OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 1997-2012, International Business Machines Corporation and * | 3 * Copyright (C) 1997-2014, International Business Machines Corporation and * |
4 * others. All Rights Reserved. * | 4 * others. All Rights Reserved. * |
5 ******************************************************************************* | 5 ******************************************************************************* |
6 * | 6 * |
7 * File COMPACTDECIMALFORMAT.CPP | 7 * File COMPACTDECIMALFORMAT.CPP |
8 * | 8 * |
9 ******************************************************************************** | 9 ******************************************************************************** |
10 */ | 10 */ |
11 #include "unicode/utypes.h" | 11 #include "unicode/utypes.h" |
12 | 12 |
13 #if !UCONFIG_NO_FORMATTING | 13 #if !UCONFIG_NO_FORMATTING |
14 | 14 |
15 #include "charstr.h" | 15 #include "charstr.h" |
16 #include "cstring.h" | 16 #include "cstring.h" |
17 #include "digitlst.h" | 17 #include "digitlst.h" |
18 #include "mutex.h" | 18 #include "mutex.h" |
19 #include "unicode/compactdecimalformat.h" | 19 #include "unicode/compactdecimalformat.h" |
20 #include "unicode/numsys.h" | 20 #include "unicode/numsys.h" |
21 #include "unicode/plurrule.h" | 21 #include "unicode/plurrule.h" |
22 #include "unicode/ures.h" | 22 #include "unicode/ures.h" |
23 #include "ucln_in.h" | 23 #include "ucln_in.h" |
24 #include "uhash.h" | 24 #include "uhash.h" |
25 #include "umutex.h" | 25 #include "umutex.h" |
26 #include "unicode/ures.h" | 26 #include "unicode/ures.h" |
27 #include "uresimp.h" | 27 #include "uresimp.h" |
28 | 28 |
29 #define LENGTHOF(array) (int32_t)(sizeof(array) / sizeof((array)[0])) | |
30 | |
31 // Maps locale name to CDFLocaleData struct. | 29 // Maps locale name to CDFLocaleData struct. |
32 static UHashtable* gCompactDecimalData = NULL; | 30 static UHashtable* gCompactDecimalData = NULL; |
33 static UMutex gCompactDecimalMetaLock = U_MUTEX_INITIALIZER; | 31 static UMutex gCompactDecimalMetaLock = U_MUTEX_INITIALIZER; |
34 | 32 |
35 U_NAMESPACE_BEGIN | 33 U_NAMESPACE_BEGIN |
36 | 34 |
37 static const int32_t MAX_DIGITS = 15; | 35 static const int32_t MAX_DIGITS = 15; |
38 static const char gOther[] = "other"; | 36 static const char gOther[] = "other"; |
39 static const char gLatnTag[] = "latn"; | 37 static const char gLatnTag[] = "latn"; |
40 static const char gNumberElementsTag[] = "NumberElements"; | 38 static const char gNumberElementsTag[] = "NumberElements"; |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 // extracted. It is usually of form 'Pefix 000 suffix'. | 759 // extracted. It is usually of form 'Pefix 000 suffix'. |
762 // populatePrefixSuffix returns the number of 0's found in formatStr | 760 // populatePrefixSuffix returns the number of 0's found in formatStr |
763 // before the decimal point. | 761 // before the decimal point. |
764 // In the special case that formatStr contains only spaces for prefix | 762 // In the special case that formatStr contains only spaces for prefix |
765 // and suffix, populatePrefixSuffix returns log10Value + 1. | 763 // and suffix, populatePrefixSuffix returns log10Value + 1. |
766 static int32_t populatePrefixSuffix( | 764 static int32_t populatePrefixSuffix( |
767 const char* variant, int32_t log10Value, const UnicodeString& formatStr, UHa
shtable* result, UErrorCode& status) { | 765 const char* variant, int32_t log10Value, const UnicodeString& formatStr, UHa
shtable* result, UErrorCode& status) { |
768 if (U_FAILURE(status)) { | 766 if (U_FAILURE(status)) { |
769 return 0; | 767 return 0; |
770 } | 768 } |
771 int32_t firstIdx = formatStr.indexOf(kZero, LENGTHOF(kZero), 0); | 769 int32_t firstIdx = formatStr.indexOf(kZero, UPRV_LENGTHOF(kZero), 0); |
772 // We must have 0's in format string. | 770 // We must have 0's in format string. |
773 if (firstIdx == -1) { | 771 if (firstIdx == -1) { |
774 status = U_INTERNAL_PROGRAM_ERROR; | 772 status = U_INTERNAL_PROGRAM_ERROR; |
775 return 0; | 773 return 0; |
776 } | 774 } |
777 int32_t lastIdx = formatStr.lastIndexOf(kZero, LENGTHOF(kZero), firstIdx); | 775 int32_t lastIdx = formatStr.lastIndexOf(kZero, UPRV_LENGTHOF(kZero), firstIdx)
; |
778 CDFUnit* unit = createCDFUnit(variant, log10Value, result, status); | 776 CDFUnit* unit = createCDFUnit(variant, log10Value, result, status); |
779 if (U_FAILURE(status)) { | 777 if (U_FAILURE(status)) { |
780 return 0; | 778 return 0; |
781 } | 779 } |
782 // Everything up to first 0 is the prefix | 780 // Everything up to first 0 is the prefix |
783 unit->prefix = formatStr.tempSubString(0, firstIdx); | 781 unit->prefix = formatStr.tempSubString(0, firstIdx); |
784 fixQuotes(unit->prefix); | 782 fixQuotes(unit->prefix); |
785 // Everything beyond the last 0 is the suffix | 783 // Everything beyond the last 0 is the suffix |
786 unit->suffix = formatStr.tempSubString(lastIdx + 1); | 784 unit->suffix = formatStr.tempSubString(lastIdx + 1); |
787 fixQuotes(unit->suffix); | 785 fixQuotes(unit->suffix); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 cdfUnit = (const CDFUnit*) uhash_get(table, cvariant.data()); | 942 cdfUnit = (const CDFUnit*) uhash_get(table, cvariant.data()); |
945 } | 943 } |
946 if (cdfUnit == NULL) { | 944 if (cdfUnit == NULL) { |
947 cdfUnit = (const CDFUnit*) uhash_get(table, gOther); | 945 cdfUnit = (const CDFUnit*) uhash_get(table, gOther); |
948 } | 946 } |
949 return &cdfUnit[log10Value]; | 947 return &cdfUnit[log10Value]; |
950 } | 948 } |
951 | 949 |
952 U_NAMESPACE_END | 950 U_NAMESPACE_END |
953 #endif | 951 #endif |
OLD | NEW |