ICU 59.1  59.1
edits.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 
4 // edits.h
5 // created: 2016dec30 Markus W. Scherer
6 
7 #ifndef __EDITS_H__
8 #define __EDITS_H__
9 
10 #include "unicode/utypes.h"
11 #include "unicode/uobject.h"
12 
19 
20 #ifndef U_HIDE_DRAFT_API
21 
32 class U_COMMON_API Edits U_FINAL : public UMemory {
33 public:
38  Edits() :
39  array(stackArray), capacity(STACK_CAPACITY), length(0), delta(0),
40  errorCode(U_ZERO_ERROR) {}
45  ~Edits();
46 
51  void reset();
52 
58  void addUnchanged(int32_t unchangedLength);
64  void addReplace(int32_t oldLength, int32_t newLength);
72  UBool copyErrorTo(UErrorCode &outErrorCode);
73 
79  int32_t lengthDelta() const { return delta; }
84  UBool hasChanges() const;
85 
92  struct U_COMMON_API Iterator U_FINAL : public UMemory {
97  Iterator(const Iterator &other) = default;
102  Iterator &operator=(const Iterator &other) = default;
103 
109  UBool next(UErrorCode &errorCode) { return next(onlyChanges_, errorCode); }
110 
127  UBool findSourceIndex(int32_t i, UErrorCode &errorCode);
128 
134  UBool hasChange() const { return changed; }
139  int32_t oldLength() const { return oldLength_; }
145  int32_t newLength() const { return newLength_; }
146 
151  int32_t sourceIndex() const { return srcIndex; }
157  int32_t replacementIndex() const { return replIndex; }
162  int32_t destinationIndex() const { return destIndex; }
163 
164  private:
165  friend class Edits;
166 
167  Iterator(const uint16_t *a, int32_t len, UBool oc, UBool crs);
168 
169  int32_t readLength(int32_t head);
170  void updateIndexes();
171  UBool noNext();
172  UBool next(UBool onlyChanges, UErrorCode &errorCode);
173 
174  const uint16_t *array;
175  int32_t index, length;
176  int32_t remaining;
177  UBool onlyChanges_, coarse;
178 
179  UBool changed;
180  int32_t oldLength_, newLength_;
181  int32_t srcIndex, replIndex, destIndex;
182  };
183 
191  return Iterator(array, length, TRUE, TRUE);
192  }
193 
200  return Iterator(array, length, FALSE, TRUE);
201  }
202 
210  return Iterator(array, length, TRUE, FALSE);
211  }
212 
219  return Iterator(array, length, FALSE, FALSE);
220  }
221 
222 private:
223  Edits(const Edits &) = delete;
224  Edits &operator=(const Edits &) = delete;
225 
226  void setLastUnit(int32_t last) { array[length - 1] = (uint16_t)last; }
227  int32_t lastUnit() const { return length > 0 ? array[length - 1] : 0xffff; }
228 
229  void append(int32_t r);
230  UBool growArray();
231 
232  static const int32_t STACK_CAPACITY = 100;
233  uint16_t *array;
234  int32_t capacity;
235  int32_t length;
236  int32_t delta;
237  UErrorCode errorCode;
238  uint16_t stackArray[STACK_CAPACITY];
239 };
240 
241 #endif // U_HIDE_DRAFT_API
242 
244 
245 #endif // __EDITS_H__
int32_t oldLength() const
Definition: edits.h:139
Iterator getFineChangesIterator() const
Returns an Iterator for fine-grained changes for modifying styled text.
Definition: edits.h:209
Access to the list of edits.
Definition: edits.h:92
No error, no warning.
Definition: utypes.h:430
Iterator getCoarseIterator() const
Returns an Iterator for coarse-grained changes and non-changes for simple string updates.
Definition: edits.h:199
Iterator getCoarseChangesIterator() const
Returns an Iterator for coarse-grained changes for simple string updates.
Definition: edits.h:190
int32_t newLength() const
Definition: edits.h:145
Records lengths of string edits but not replacement text.
Definition: edits.h:32
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
int32_t sourceIndex() const
Definition: edits.h:151
int32_t lengthDelta() const
How much longer is the new text compared with the old text?
Definition: edits.h:79
int32_t replacementIndex() const
Definition: edits.h:157
int32_t destinationIndex() const
Definition: edits.h:162
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:240
C++ API: Common ICU base class UObject.
Iterator getFineIterator() const
Returns an Iterator for fine-grained changes and non-changes for modifying styled text...
Definition: edits.h:218
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UBool hasChange() const
Definition: edits.h:134
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
Basic definitions for ICU, for both C and C++ APIs.
Edits()
Constructs an empty object.
Definition: edits.h:38
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:244
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:359
UBool next(UErrorCode &errorCode)
Advances to the next edit.
Definition: edits.h:109
UMemory is the common ICU base class.
Definition: uobject.h:112
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236