]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/digitaffix.cpp
2 * Copyright (C) 2015, International Business Machines
3 * Corporation and others. All Rights Reserved.
5 * file name: digitaffix.cpp
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_FORMATTING
12 #include "digitaffix.h"
15 #include "unistrappender.h"
19 DigitAffix::DigitAffix() : fAffix(), fAnnotations() {
22 DigitAffix::DigitAffix(
23 const UChar
*value
, int32_t charCount
, int32_t fieldId
)
24 : fAffix(value
, charCount
),
25 fAnnotations(charCount
, (UChar
) fieldId
, charCount
) {
29 DigitAffix::remove() {
31 fAnnotations
.remove();
35 DigitAffix::appendUChar(UChar value
, int32_t fieldId
) {
37 fAnnotations
.append((UChar
) fieldId
);
41 DigitAffix::append(const UnicodeString
&value
, int32_t fieldId
) {
44 UnicodeStringAppender
appender(fAnnotations
);
45 int32_t len
= value
.length();
46 for (int32_t i
= 0; i
< len
; ++i
) {
47 appender
.append((UChar
) fieldId
);
53 DigitAffix::setTo(const UnicodeString
&value
, int32_t fieldId
) {
55 fAnnotations
.remove();
57 UnicodeStringAppender
appender(fAnnotations
);
58 int32_t len
= value
.length();
59 for (int32_t i
= 0; i
< len
; ++i
) {
60 appender
.append((UChar
) fieldId
);
66 DigitAffix::append(const UChar
*value
, int32_t charCount
, int32_t fieldId
) {
67 fAffix
.append(value
, charCount
);
69 UnicodeStringAppender
appender(fAnnotations
);
70 for (int32_t i
= 0; i
< charCount
; ++i
) {
71 appender
.append((UChar
) fieldId
);
77 DigitAffix::format(FieldPositionHandler
&handler
, UnicodeString
&appendTo
) const {
78 int32_t len
= fAffix
.length();
82 if (!handler
.isRecording()) {
83 return appendTo
.append(fAffix
);
85 U_ASSERT(fAffix
.length() == fAnnotations
.length());
86 int32_t appendToStart
= appendTo
.length();
87 int32_t lastId
= (int32_t) fAnnotations
.charAt(0);
88 int32_t lastIdStart
= 0;
89 for (int32_t i
= 1; i
< len
; ++i
) {
90 int32_t id
= (int32_t) fAnnotations
.charAt(i
);
92 if (lastId
!= UNUM_FIELD_COUNT
) {
93 handler
.addAttribute(lastId
, appendToStart
+ lastIdStart
, appendToStart
+ i
);
99 if (lastId
!= UNUM_FIELD_COUNT
) {
100 handler
.addAttribute(lastId
, appendToStart
+ lastIdStart
, appendToStart
+ len
);
102 return appendTo
.append(fAffix
);
107 #endif /* #if !UCONFIG_NO_FORMATTING */