+
+// UnicodeStringAppendable ------------------------------------------------- ***
+
+UnicodeStringAppendable::~UnicodeStringAppendable() {}
+
+UBool
+UnicodeStringAppendable::appendCodeUnit(UChar c) {
+ return str.doReplace(str.length(), 0, &c, 0, 1).isWritable();
+}
+
+UBool
+UnicodeStringAppendable::appendCodePoint(UChar32 c) {
+ UChar buffer[U16_MAX_LENGTH];
+ int32_t cLength = 0;
+ UBool isError = FALSE;
+ U16_APPEND(buffer, cLength, U16_MAX_LENGTH, c, isError);
+ return !isError && str.doReplace(str.length(), 0, buffer, 0, cLength).isWritable();
+}
+
+UBool
+UnicodeStringAppendable::appendString(const UChar *s, int32_t length) {
+ return str.doReplace(str.length(), 0, s, 0, length).isWritable();
+}
+
+UBool
+UnicodeStringAppendable::reserveAppendCapacity(int32_t appendCapacity) {
+ return str.cloneArrayIfNeeded(str.length() + appendCapacity);
+}
+
+UChar *
+UnicodeStringAppendable::getAppendBuffer(int32_t minCapacity,
+ int32_t desiredCapacityHint,
+ UChar *scratch, int32_t scratchCapacity,
+ int32_t *resultCapacity) {
+ if(minCapacity < 1 || scratchCapacity < minCapacity) {
+ *resultCapacity = 0;
+ return NULL;
+ }
+ int32_t oldLength = str.length();
+ if(str.cloneArrayIfNeeded(oldLength + minCapacity, oldLength + desiredCapacityHint)) {
+ *resultCapacity = str.getCapacity() - oldLength;
+ return str.getArrayStart() + oldLength;
+ }
+ *resultCapacity = scratchCapacity;
+ return scratch;
+}
+