00001
00002
00003
00004
00005
00006
00007 #ifndef __EDITS_H__
00008 #define __EDITS_H__
00009
00010 #include "unicode/utypes.h"
00011 #include "unicode/uobject.h"
00012
00018 U_NAMESPACE_BEGIN
00019
00020 #ifndef U_HIDE_DRAFT_API
00021
00032 class U_COMMON_API Edits U_FINAL : public UMemory {
00033 public:
00038 Edits() :
00039 array(stackArray), capacity(STACK_CAPACITY), length(0), delta(0), numChanges(0),
00040 errorCode_(U_ZERO_ERROR) {}
00046 Edits(const Edits &other) :
00047 array(stackArray), capacity(STACK_CAPACITY), length(other.length),
00048 delta(other.delta), numChanges(other.numChanges),
00049 errorCode_(other.errorCode_) {
00050 copyArray(other);
00051 }
00058 Edits(Edits &&src) U_NOEXCEPT :
00059 array(stackArray), capacity(STACK_CAPACITY), length(src.length),
00060 delta(src.delta), numChanges(src.numChanges),
00061 errorCode_(src.errorCode_) {
00062 moveArray(src);
00063 }
00064
00069 ~Edits();
00070
00077 Edits &operator=(const Edits &other);
00078
00087 Edits &operator=(Edits &&src) U_NOEXCEPT;
00088
00093 void reset() U_NOEXCEPT;
00094
00100 void addUnchanged(int32_t unchangedLength);
00106 void addReplace(int32_t oldLength, int32_t newLength);
00117 UBool copyErrorTo(UErrorCode &outErrorCode);
00118
00124 int32_t lengthDelta() const { return delta; }
00129 UBool hasChanges() const { return numChanges != 0; }
00130
00135 int32_t numberOfChanges() const { return numChanges; }
00136
00143 struct U_COMMON_API Iterator U_FINAL : public UMemory {
00148 Iterator() :
00149 array(nullptr), index(0), length(0),
00150 remaining(0), onlyChanges_(FALSE), coarse(FALSE),
00151 dir(0), changed(FALSE), oldLength_(0), newLength_(0),
00152 srcIndex(0), replIndex(0), destIndex(0) {}
00157 Iterator(const Iterator &other) = default;
00162 Iterator &operator=(const Iterator &other) = default;
00163
00172 UBool next(UErrorCode &errorCode) { return next(onlyChanges_, errorCode); }
00173
00193 UBool findSourceIndex(int32_t i, UErrorCode &errorCode) {
00194 return findIndex(i, TRUE, errorCode) == 0;
00195 }
00196
00216 UBool findDestinationIndex(int32_t i, UErrorCode &errorCode) {
00217 return findIndex(i, FALSE, errorCode) == 0;
00218 }
00219
00242 int32_t destinationIndexFromSourceIndex(int32_t i, UErrorCode &errorCode);
00243
00266 int32_t sourceIndexFromDestinationIndex(int32_t i, UErrorCode &errorCode);
00267
00273 UBool hasChange() const { return changed; }
00278 int32_t oldLength() const { return oldLength_; }
00284 int32_t newLength() const { return newLength_; }
00285
00290 int32_t sourceIndex() const { return srcIndex; }
00296 int32_t replacementIndex() const { return replIndex; }
00301 int32_t destinationIndex() const { return destIndex; }
00302
00303 private:
00304 friend class Edits;
00305
00306 Iterator(const uint16_t *a, int32_t len, UBool oc, UBool crs);
00307
00308 int32_t readLength(int32_t head);
00309 void updateNextIndexes();
00310 void updatePreviousIndexes();
00311 UBool noNext();
00312 UBool next(UBool onlyChanges, UErrorCode &errorCode);
00313 UBool previous(UErrorCode &errorCode);
00315 int32_t findIndex(int32_t i, UBool findSource, UErrorCode &errorCode);
00316
00317 const uint16_t *array;
00318 int32_t index, length;
00319
00320
00321 int32_t remaining;
00322 UBool onlyChanges_, coarse;
00323
00324 int8_t dir;
00325 UBool changed;
00326 int32_t oldLength_, newLength_;
00327 int32_t srcIndex, replIndex, destIndex;
00328 };
00329
00336 Iterator getCoarseChangesIterator() const {
00337 return Iterator(array, length, TRUE, TRUE);
00338 }
00339
00345 Iterator getCoarseIterator() const {
00346 return Iterator(array, length, FALSE, TRUE);
00347 }
00348
00355 Iterator getFineChangesIterator() const {
00356 return Iterator(array, length, TRUE, FALSE);
00357 }
00358
00364 Iterator getFineIterator() const {
00365 return Iterator(array, length, FALSE, FALSE);
00366 }
00367
00395 Edits &mergeAndAppend(const Edits &ab, const Edits &bc, UErrorCode &errorCode);
00396
00397 private:
00398 void releaseArray() U_NOEXCEPT;
00399 Edits ©Array(const Edits &other);
00400 Edits &moveArray(Edits &src) U_NOEXCEPT;
00401
00402 void setLastUnit(int32_t last) { array[length - 1] = (uint16_t)last; }
00403 int32_t lastUnit() const { return length > 0 ? array[length - 1] : 0xffff; }
00404
00405 void append(int32_t r);
00406 UBool growArray();
00407
00408 static const int32_t STACK_CAPACITY = 100;
00409 uint16_t *array;
00410 int32_t capacity;
00411 int32_t length;
00412 int32_t delta;
00413 int32_t numChanges;
00414 UErrorCode errorCode_;
00415 uint16_t stackArray[STACK_CAPACITY];
00416 };
00417
00418 #endif // U_HIDE_DRAFT_API
00419
00420 U_NAMESPACE_END
00421
00422 #endif // __EDITS_H__