There are two types of edits: change edits and no-change edits. Add edits to
instances of this class using addReplace(int, int) (for change edits) and
addUnchanged(int) (for no-change edits). Change edits are retained with full granularity,
whereas adjacent no-change edits are always merged together. In no-change edits, there is a one-to-one
mapping between code points in the source and destination strings.
After all edits have been added, instances of this class should be considered immutable, and an
Edits. can be used for queries.
There are four flavors of Edits.Iterator:
getFineIterator() retains full granularity of change edits.
getFineChangesIterator() retains full granularity of change edits, and when calling
next() on the iterator, skips over no-change edits (unchanged regions).
getCoarseIterator() treats adjacent change edits as a single edit. (Adjacent no-change
edits are automatically merged during the construction phase.)
getCoarseChangesIterator() treats adjacent change edits as a single edit, and when
calling next() on the iterator, skips over no-change edits (unchanged regions).
For example, consider the string "abcßDeF", which case-folds to "abcssdef". This string has the following fine edits:
The "fine changes" and "coarse changes" iterators will step through only the change edits when their
Edits. methods are called. They are identical to the non-change iterators when
their Edits. or Edits.
methods are used to walk through the string.
For examples of how to use this class, see the test TestCaseMapEditsIteratorDocs in
UCharacterCaseTest.java.
| Modifier and Type | Class and Description |
|---|---|
| public static class | Edits.Iterator
Access to the list of edits. |
| Modifier and Type | Field and Description |
|---|---|
| private char[] | |
| private int | |
| private int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private int | |
| private static final int | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addReplace(int oldLength, int newLength)
Adds a change edit: a record for a text replacement/insertion/deletion. |
| public void | |
| private void | |
| public Edits. | Returns: an Iterator that merges adjacent changes.Returns an Iterator for coarse-grained change edits (adjacent change edits are treated as one). |
| public Edits. | Returns: an Iterator that merges adjacent changes.Returns an Iterator for coarse-grained change and no-change edits (adjacent change edits are treated as one). |
| public Edits. | Returns: an Iterator that separates adjacent changes.Returns an Iterator for fine-grained change edits (full granularity of change edits is retained). |
| public Edits. | Returns: an Iterator that separates adjacent changes.Returns an Iterator for fine-grained change and no-change edits (full granularity of change edits is retained). |
| private boolean | |
| public boolean | |
| private int | |
| public int | Returns: new length minus old lengthHow much longer is the new text compared with the old text? |
| public Edits | Returns: this, with the merged edits appendedreflects how substrings of input string a
map to substrings of intermediate string b. ab, Edits reflects how substrings of intermediate string b
map to substrings of output string c. bc)Merges the two input Edits and appends the result to this object. |
| public int | |
| public void | |
| private void |
| array | back to summary |
|---|---|
| private char[] array | |
| delta | back to summary |
|---|---|
| private int delta | |
| length | back to summary |
|---|---|
| private int length | |
| LENGTH_IN_1TRAIL | back to summary |
|---|---|
| private static final int LENGTH_IN_1TRAIL | |
| LENGTH_IN_2TRAIL | back to summary |
|---|---|
| private static final int LENGTH_IN_2TRAIL | |
| MAX_SHORT_CHANGE | back to summary |
|---|---|
| private static final int MAX_SHORT_CHANGE | |
| MAX_SHORT_CHANGE_NEW_LENGTH | back to summary |
|---|---|
| private static final int MAX_SHORT_CHANGE_NEW_LENGTH | |
| MAX_SHORT_CHANGE_OLD_LENGTH | back to summary |
|---|---|
| private static final int MAX_SHORT_CHANGE_OLD_LENGTH | |
| MAX_UNCHANGED | back to summary |
|---|---|
| private static final int MAX_UNCHANGED | |
| MAX_UNCHANGED_LENGTH | back to summary |
|---|---|
| private static final int MAX_UNCHANGED_LENGTH | |
| numChanges | back to summary |
|---|---|
| private int numChanges | |
| SHORT_CHANGE_NUM_MASK | back to summary |
|---|---|
| private static final int SHORT_CHANGE_NUM_MASK | |
| STACK_CAPACITY | back to summary |
|---|---|
| private static final int STACK_CAPACITY | |
| Edits | back to summary |
|---|---|
| public Edits() Constructs an empty object.
| |
| addReplace | back to summary |
|---|---|
| public void addReplace(int oldLength, int newLength) Adds a change edit: a record for a text replacement/insertion/deletion. Normally called from inside ICU string transformation functions, not user code.
| |
| addUnchanged | back to summary |
|---|---|
| public void addUnchanged(int unchangedLength) Adds a no-change edit: a record for an unchanged segment of text. Normally called from inside ICU string transformation functions, not user code.
| |
| append | back to summary |
|---|---|
| private void append(int r) | |
| getCoarseChangesIterator | back to summary |
|---|---|
| public Edits. Returns an Iterator for coarse-grained change edits (adjacent change edits are treated as one). Can be used to perform simple string updates. Skips no-change edits. | |
| getCoarseIterator | back to summary |
|---|---|
| public Edits. Returns an Iterator for coarse-grained change and no-change edits (adjacent change edits are treated as one). Can be used to perform simple string updates. Adjacent change edits are treated as one edit. | |
| getFineChangesIterator | back to summary |
|---|---|
| public Edits. Returns an Iterator for fine-grained change edits (full granularity of change edits is retained). Can be used for modifying styled text. Skips no-change edits. | |
| getFineIterator | back to summary |
|---|---|
| public Edits. Returns an Iterator for fine-grained change and no-change edits (full granularity of change edits is retained). Can be used for modifying styled text. | |
| growArray | back to summary |
|---|---|
| private boolean growArray() | |
| hasChanges | back to summary |
|---|---|
public boolean hasChanges()
| |
| lastUnit | back to summary |
|---|---|
| private int lastUnit() | |
| lengthDelta | back to summary |
|---|---|
| public int lengthDelta() How much longer is the new text compared with the old text?
| |
| mergeAndAppend | back to summary |
|---|---|
| public Edits mergeAndAppend(Edits ab, Edits bc) Merges the two input Edits and appends the result to this object. Consider two string transformations (for example, normalization and case mapping)
where each records Edits in addition to writing an output string. If unrelated Edits are passed in where the output string of the first has a different length than the input string of the second, then an IllegalArgumentException is thrown. | |
| numberOfChanges | back to summary |
|---|---|
public int numberOfChanges()
| |
| reset | back to summary |
|---|---|
| public void reset() Resets the data but may not release memory.
| |
| setLastUnit | back to summary |
|---|---|
| private void setLastUnit(int last) | |
At any moment in time, an instance of this class points to a single edit: a "window" into a span
of the source string and the corresponding span of the destination string. The source string span
starts at sourceIndex() and runs for oldLength() chars; the destination string
span starts at destinationIndex() and runs for newLength() chars.
The iterator can be moved between edits using the next(), findSourceIndex(int),
and findDestinationIndex(int) methods. Calling any of these methods mutates the iterator
to make it point to the corresponding edit.
For more information, see the documentation for Edits.
Note
Although this class is called "Iterator", it does not implement java..
getCoarseIterator, getFineIterator
| Modifier and Type | Field and Description |
|---|---|
| private final char[] | |
| private boolean | |
| private final boolean | |
| private int | |
| private int | |
| private int | |
| private final int | |
| private int | |
| private int | |
| private final boolean | |
| private int | remaining
0 if we are not within compressed equal-length changes. |
| private int | |
| private int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: the current index into the full destination stringThe start index of the current span in the destination string; the span has length
|
| public int | Returns: destination index; undefined if i is not 0..string lengthsource index i)Computes the destination index corresponding to the given source index. |
| public boolean | Returns: true if the edit for the destination index was founddestination index i)Moves the iterator to the edit that contains the destination index. |
| private int | |
| public boolean | Returns: true if the edit for the source index was foundsource index i)Moves the iterator to the edit that contains the source index. |
| public boolean | Returns: true if this edit replaces oldLength() units with newLength() different ones. false if oldLength units remain unchanged.Returns whether the edit currently represented by the iterator is a change edit. |
| public int | Returns: the number of units in the destination string, if hasChange() is true. Same as oldLength if hasChange() is false.The length of the current span in the destination string, which starts at
|
| public boolean | |
| private boolean | |
| private boolean | |
| public int | Returns: the number of units in the source string which are replaced or remain unchanged.The length of the current span in the source string, which starts at |
| private boolean | |
| private int | |
| public int | Returns: the current index into the replacement-characters-only string, not counting unchanged spansThe start index of the current span in the replacement string; the span has length
|
| public int | Returns: the current index into the source stringThe start index of the current span in the source string; the span has length
|
| public int | Returns: source index; undefined if i is not 0..string lengthdestination index i)Computes the source index corresponding to the given destination index. |
| public String | Returns: a string representation of the object.Overrides java. |
| private void | |
| private void |
| array | back to summary |
|---|---|
| private final char[] array | |
| changed | back to summary |
|---|---|
| private boolean changed | |
| coarse | back to summary |
|---|---|
| private final boolean coarse | |
| destIndex | back to summary |
|---|---|
| private int destIndex | |
| dir | back to summary |
|---|---|
| private int dir | |
| index | back to summary |
|---|---|
| private int index | |
| length | back to summary |
|---|---|
| private final int length | |
| newLength_ | back to summary |
|---|---|
| private int newLength_ | |
| oldLength_ | back to summary |
|---|---|
| private int oldLength_ | |
| onlyChanges_ | back to summary |
|---|---|
| private final boolean onlyChanges_ | |
| remaining | back to summary |
|---|---|
| private int remaining 0 if we are not within compressed equal-length changes. Otherwise the number of remaining changes, including the current one. | |
| replIndex | back to summary |
|---|---|
| private int replIndex | |
| srcIndex | back to summary |
|---|---|
| private int srcIndex | |
| Iterator | back to summary |
|---|---|
| private Iterator(char[] a, int len, boolean oc, boolean crs) | |
| destinationIndex | back to summary |
|---|---|
| public int destinationIndex() The start index of the current span in the destination string; the span has length
| |
| destinationIndexFromSourceIndex | back to summary |
|---|---|
| public int destinationIndexFromSourceIndex(int i) Computes the destination index corresponding to the given source index. If the source index is inside a change edit (not at its start), then the destination index at the end of that edit is returned, since there is no information about index mapping inside a change edit. (This means that indexes to the start and middle of an edit, for example around a grapheme cluster, are mapped to indexes encompassing the entire edit. The alternative, mapping an interior index to the start, would map such an interval to an empty one.) This operation will usually but not always modify this object. The iterator state after this search is undefined.
| |
| findDestinationIndex | back to summary |
|---|---|
| public boolean findDestinationIndex(int i) Moves the iterator to the edit that contains the destination index. The destination index may be found in a no-change edit even if normal iteration would skip no-change edits. Normal iteration can continue from a found edit. The iterator state before this search logically does not matter. (It may affect the performance of the search.) The iterator state after this search is undefined if the source index is out of bounds for the source string.
| |
| findIndex | back to summary |
|---|---|
private int findIndex(int i, boolean findSource)
| |
| findSourceIndex | back to summary |
|---|---|
| public boolean findSourceIndex(int i) Moves the iterator to the edit that contains the source index. The source index may be found in a no-change edit even if normal iteration would skip no-change edits. Normal iteration can continue from a found edit. The iterator state before this search logically does not matter. (It may affect the performance of the search.) The iterator state after this search is undefined if the source index is out of bounds for the source string.
| |
| hasChange | back to summary |
|---|---|
| public boolean hasChange() Returns whether the edit currently represented by the iterator is a change edit.
| |
| newLength | back to summary |
|---|---|
| public int newLength() The length of the current span in the destination string, which starts at
| |
| next | back to summary |
|---|---|
| public boolean next() Advances the iterator to the next edit.
| |
| next | back to summary |
|---|---|
| private boolean next(boolean onlyChanges) | |
| noNext | back to summary |
|---|---|
| private boolean noNext() | |
| oldLength | back to summary |
|---|---|
| public int oldLength() The length of the current span in the source string, which starts at
| |
| previous | back to summary |
|---|---|
| private boolean previous() | |
| readLength | back to summary |
|---|---|
| private int readLength(int head) | |
| replacementIndex | back to summary |
|---|---|
| public int replacementIndex() The start index of the current span in the replacement string; the span has length
The replacement string is the concatenation of all substrings of the destination string corresponding to change edits.
This method is intended to be used together with operations that write only replacement
characters (e.g.,
| |
| sourceIndex | back to summary |
|---|---|
| public int sourceIndex() The start index of the current span in the source string; the span has length
| |
| sourceIndexFromDestinationIndex | back to summary |
|---|---|
| public int sourceIndexFromDestinationIndex(int i) Computes the source index corresponding to the given destination index. If the destination index is inside a change edit (not at its start), then the source index at the end of that edit is returned, since there is no information about index mapping inside a change edit. (This means that indexes to the start and middle of an edit, for example around a grapheme cluster, are mapped to indexes encompassing the entire edit. The alternative, mapping an interior index to the start, would map such an interval to an empty one.) This operation will usually but not always modify this object. The iterator state after this search is undefined.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. A string representation of the current edit represented by the iterator for debugging. You should not depend on the contents of the return string; it may change over time. | |
| updateNextIndexes | back to summary |
|---|---|
| private void updateNextIndexes() | |
| updatePreviousIndexes | back to summary |
|---|---|
| private void updatePreviousIndexes() | |