1 /* 2 ******************************************************************************* 3 * Copyright (C) 2015, International Business Machines 4 * Corporation and others. All Rights Reserved. 5 ******************************************************************************* 6 * digitaffix.h 7 * 8 * created on: 2015jan06 9 * created by: Travis Keep 10 */ 11 12 #ifndef __DIGITAFFIX_H__ 13 #define __DIGITAFFIX_H__ 14 15 #include "unicode/uobject.h" 16 17 #if !UCONFIG_NO_FORMATTING 18 19 #include "unicode/unistr.h" 20 #include "unicode/unum.h" 21 #include "unicode/utypes.h" 22 23 U_NAMESPACE_BEGIN 24 25 class FieldPositionHandler; 26 27 /** 28 * A prefix or suffix of a formatted number. 29 */ 30 class U_I18N_API DigitAffix : public UMemory { 31 public: 32 33 /** 34 * Creates an empty DigitAffix. 35 */ 36 DigitAffix(); 37 38 /** 39 * Creates a DigitAffix containing given UChars where all of it has 40 * a field type of fieldId. 41 */ 42 DigitAffix( 43 const UChar *value, 44 int32_t charCount, 45 int32_t fieldId=UNUM_FIELD_COUNT); 46 47 /** 48 * Makes this affix be the empty string. 49 */ 50 void remove(); 51 52 /** 53 * Append value to this affix. If fieldId is present, the appended 54 * string is considered to be the type fieldId. 55 */ 56 void appendUChar(UChar value, int32_t fieldId=UNUM_FIELD_COUNT); 57 58 /** 59 * Append value to this affix. If fieldId is present, the appended 60 * string is considered to be the type fieldId. 61 */ 62 void append(const UnicodeString &value, int32_t fieldId=UNUM_FIELD_COUNT); 63 64 /** 65 * Sets this affix to given string. The entire string 66 * is considered to be the type fieldId. 67 */ 68 void setTo(const UnicodeString &value, int32_t fieldId=UNUM_FIELD_COUNT); 69 70 /** 71 * Append value to this affix. If fieldId is present, the appended 72 * string is considered to be the type fieldId. 73 */ 74 void append(const UChar *value, int32_t charCount, int32_t fieldId=UNUM_FIELD_COUNT); 75 76 /** 77 * Formats this affix. 78 */ 79 UnicodeString &format( 80 FieldPositionHandler &handler, UnicodeString &appendTo) const; countChar32()81 int32_t countChar32() const { return fAffix.countChar32(); } 82 83 /** 84 * Returns this affix as a unicode string. 85 */ toString()86 const UnicodeString & toString() const { return fAffix; } 87 88 /** 89 * Returns TRUE if this object equals rhs. 90 */ equals(const DigitAffix & rhs)91 UBool equals(const DigitAffix &rhs) const { 92 return ((fAffix == rhs.fAffix) && (fAnnotations == rhs.fAnnotations)); 93 } 94 private: 95 UnicodeString fAffix; 96 UnicodeString fAnnotations; 97 }; 98 99 100 U_NAMESPACE_END 101 #endif // #if !UCONFIG_NO_FORMATTING 102 #endif // __DIGITAFFIX_H__ 103