/*
**********************************************************************
-* Copyright (c) 2002, International Business Machines Corporation
+* Copyright (c) 2002-2012, International Business Machines Corporation
* and others. All Rights Reserved.
**********************************************************************
* Date Name Description
#if !UCONFIG_NO_TRANSLITERATION
+#include "unicode/uniset.h"
+#include "unicode/utf16.h"
#include "strrepl.h"
#include "rbt_data.h"
#include "util.h"
-#include "unicode/uniset.h"
U_NAMESPACE_BEGIN
-const UChar EMPTY[] = { 0 }; // empty string: ""
-
-const char StringReplacer::fgClassID=0;
+UnicodeReplacer::~UnicodeReplacer() {}
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringReplacer)
/**
* Construct a StringReplacer that sets the emits the given output
/**
* Copy constructor.
*/
-StringReplacer::StringReplacer(const StringReplacer& other) {
+StringReplacer::StringReplacer(const StringReplacer& other) :
+ UnicodeFunctor(other),
+ UnicodeReplacer(other)
+{
output = other.output;
cursorPos = other.cursorPos;
hasCursor = other.hasCursor;
* Implement UnicodeFunctor
*/
UnicodeReplacer* StringReplacer::toReplacer() const {
- return (UnicodeReplacer*) this;
+ return const_cast<StringReplacer *>(this);
}
/**
int32_t tempStart = text.length(); // start of temp buffer
int32_t destStart = tempStart; // copy new text to here
if (start > 0) {
- int32_t len = UTF_CHAR_LENGTH(text.char32At(start-1));
+ int32_t len = U16_LENGTH(text.char32At(start-1));
text.copy(start-len, start, tempStart);
destStart += len;
} else {
int32_t len = r->replace(text, destLimit, destLimit, cursor);
destLimit += len;
}
- oOutput += UTF_CHAR_LENGTH(c);
+ oOutput += U16_LENGTH(c);
}
// Insert any accumulated straight text.
if (buf.length() > 0) {
// Copy new text to start, and delete it
text.copy(destStart, destLimit, start);
- text.handleReplaceBetween(tempStart + outLen, destLimit + outLen, EMPTY);
+ text.handleReplaceBetween(tempStart + outLen, destLimit + outLen, UnicodeString());
// Delete the old text (the key)
- text.handleReplaceBetween(start + outLen, limit + outLen, EMPTY);
+ text.handleReplaceBetween(start + outLen, limit + outLen, UnicodeString());
}
if (hasCursor) {
int32_t n = cursorPos;
// Outside the output string, cursorPos counts code points
while (n < 0 && newStart > 0) {
- newStart -= UTF_CHAR_LENGTH(text.char32At(newStart-1));
+ newStart -= U16_LENGTH(text.char32At(newStart-1));
++n;
}
newStart += n;
int32_t n = cursorPos - output.length();
// Outside the output string, cursorPos counts code points
while (n > 0 && newStart < text.length()) {
- newStart += UTF_CHAR_LENGTH(text.char32At(newStart));
+ newStart += U16_LENGTH(text.char32At(newStart));
--n;
}
newStart += n;
*/
void StringReplacer::addReplacementSetTo(UnicodeSet& toUnionTo) const {
UChar32 ch;
- for (int32_t i=0; i<output.length(); i+=UTF_CHAR_LENGTH(ch)) {
- ch = output.char32At(i);
- UnicodeReplacer* r = data->lookupReplacer(ch);
- if (r == NULL) {
- toUnionTo.add(ch);
- } else {
- r->addReplacementSetTo(toUnionTo);
- }
+ for (int32_t i=0; i<output.length(); i+=U16_LENGTH(ch)) {
+ ch = output.char32At(i);
+ UnicodeReplacer* r = data->lookupReplacer(ch);
+ if (r == NULL) {
+ toUnionTo.add(ch);
+ } else {
+ r->addReplacementSetTo(toUnionTo);
+ }
}
}
if (f != NULL) {
f->setData(data);
}
- i += UTF_CHAR_LENGTH(c);
+ i += U16_LENGTH(c);
}
}