Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: source/i18n/digitaffix.cpp

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/i18n/digitaffix.h ('k') | source/i18n/digitaffixesandpadding.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/i18n/digitaffix.cpp
diff --git a/source/i18n/digitaffix.cpp b/source/i18n/digitaffix.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1dd3ea998b62c1754aa3c8e67be540bb4b2b095f
--- /dev/null
+++ b/source/i18n/digitaffix.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2015, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ *
+ * file name: digitaffix.cpp
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "digitaffix.h"
+#include "fphdlimp.h"
+#include "uassert.h"
+#include "unistrappender.h"
+
+U_NAMESPACE_BEGIN
+
+DigitAffix::DigitAffix() : fAffix(), fAnnotations() {
+}
+
+DigitAffix::DigitAffix(
+ const UChar *value, int32_t charCount, int32_t fieldId)
+ : fAffix(value, charCount),
+ fAnnotations(charCount, (UChar) fieldId, charCount) {
+}
+
+void
+DigitAffix::remove() {
+ fAffix.remove();
+ fAnnotations.remove();
+}
+
+void
+DigitAffix::appendUChar(UChar value, int32_t fieldId) {
+ fAffix.append(value);
+ fAnnotations.append((UChar) fieldId);
+}
+
+void
+DigitAffix::append(const UnicodeString &value, int32_t fieldId) {
+ fAffix.append(value);
+ {
+ UnicodeStringAppender appender(fAnnotations);
+ int32_t len = value.length();
+ for (int32_t i = 0; i < len; ++i) {
+ appender.append((UChar) fieldId);
+ }
+ }
+}
+
+void
+DigitAffix::setTo(const UnicodeString &value, int32_t fieldId) {
+ fAffix = value;
+ fAnnotations.remove();
+ {
+ UnicodeStringAppender appender(fAnnotations);
+ int32_t len = value.length();
+ for (int32_t i = 0; i < len; ++i) {
+ appender.append((UChar) fieldId);
+ }
+ }
+}
+
+void
+DigitAffix::append(const UChar *value, int32_t charCount, int32_t fieldId) {
+ fAffix.append(value, charCount);
+ {
+ UnicodeStringAppender appender(fAnnotations);
+ for (int32_t i = 0; i < charCount; ++i) {
+ appender.append((UChar) fieldId);
+ }
+ }
+}
+
+UnicodeString &
+DigitAffix::format(FieldPositionHandler &handler, UnicodeString &appendTo) const {
+ int32_t len = fAffix.length();
+ if (len == 0) {
+ return appendTo;
+ }
+ if (!handler.isRecording()) {
+ return appendTo.append(fAffix);
+ }
+ U_ASSERT(fAffix.length() == fAnnotations.length());
+ int32_t appendToStart = appendTo.length();
+ int32_t lastId = (int32_t) fAnnotations.charAt(0);
+ int32_t lastIdStart = 0;
+ for (int32_t i = 1; i < len; ++i) {
+ int32_t id = (int32_t) fAnnotations.charAt(i);
+ if (id != lastId) {
+ if (lastId != UNUM_FIELD_COUNT) {
+ handler.addAttribute(lastId, appendToStart + lastIdStart, appendToStart + i);
+ }
+ lastId = id;
+ lastIdStart = i;
+ }
+ }
+ if (lastId != UNUM_FIELD_COUNT) {
+ handler.addAttribute(lastId, appendToStart + lastIdStart, appendToStart + len);
+ }
+ return appendTo.append(fAffix);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
« no previous file with comments | « source/i18n/digitaffix.h ('k') | source/i18n/digitaffixesandpadding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698