Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | ***************************************************************************************** |
michael@0 | 3 | * Copyright (C) 2013, International Business Machines Corporation and others. |
michael@0 | 4 | * All Rights Reserved. |
michael@0 | 5 | ***************************************************************************************** |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "unicode/utypes.h" |
michael@0 | 9 | |
michael@0 | 10 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 11 | |
michael@0 | 12 | #include "unicode/unumsys.h" |
michael@0 | 13 | #include "unicode/numsys.h" |
michael@0 | 14 | #include "unicode/uenum.h" |
michael@0 | 15 | |
michael@0 | 16 | U_NAMESPACE_USE |
michael@0 | 17 | |
michael@0 | 18 | |
michael@0 | 19 | U_CAPI UNumberingSystem* U_EXPORT2 |
michael@0 | 20 | unumsys_open(const char *locale, UErrorCode *status) |
michael@0 | 21 | { |
michael@0 | 22 | // createInstance returns immediately if status indicates error |
michael@0 | 23 | return (UNumberingSystem*)NumberingSystem::createInstance(Locale(locale), *status); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | |
michael@0 | 27 | U_CAPI UNumberingSystem* U_EXPORT2 |
michael@0 | 28 | unumsys_openByName(const char *name, UErrorCode *status) |
michael@0 | 29 | { |
michael@0 | 30 | // createInstanceByName does NOT return immediately if status indicates error |
michael@0 | 31 | if (U_FAILURE(*status)) { |
michael@0 | 32 | return NULL; |
michael@0 | 33 | } |
michael@0 | 34 | return (UNumberingSystem*)NumberingSystem::createInstanceByName(name, *status); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | |
michael@0 | 38 | U_CAPI void U_EXPORT2 |
michael@0 | 39 | unumsys_close(UNumberingSystem *unumsys) |
michael@0 | 40 | { |
michael@0 | 41 | delete ((NumberingSystem*)unumsys); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | |
michael@0 | 45 | U_CAPI UEnumeration* U_EXPORT2 |
michael@0 | 46 | unumsys_openAvailableNames(UErrorCode *status) |
michael@0 | 47 | { |
michael@0 | 48 | // getAvailableNames returns immediately if status indicates error |
michael@0 | 49 | return uenum_openFromStringEnumeration(NumberingSystem::getAvailableNames(*status), status); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | |
michael@0 | 53 | U_CAPI const char * U_EXPORT2 |
michael@0 | 54 | unumsys_getName(const UNumberingSystem *unumsys) |
michael@0 | 55 | { |
michael@0 | 56 | return ((NumberingSystem*)unumsys)->getName(); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | |
michael@0 | 60 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 61 | unumsys_getRadix(const UNumberingSystem *unumsys) |
michael@0 | 62 | { |
michael@0 | 63 | return ((NumberingSystem*)unumsys)->getRadix(); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | U_CAPI UBool U_EXPORT2 |
michael@0 | 68 | unumsys_isAlgorithmic(const UNumberingSystem *unumsys) |
michael@0 | 69 | { |
michael@0 | 70 | return ((NumberingSystem*)unumsys)->isAlgorithmic(); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 74 | unumsys_getDescription(const UNumberingSystem *unumsys, UChar *result, |
michael@0 | 75 | int32_t resultLength, UErrorCode *status) |
michael@0 | 76 | { |
michael@0 | 77 | if (U_FAILURE(*status)) { |
michael@0 | 78 | return -1; |
michael@0 | 79 | } |
michael@0 | 80 | // implement |
michael@0 | 81 | UnicodeString descrip = ((NumberingSystem*)unumsys)->getDescription(); |
michael@0 | 82 | return descrip.extract(result, resultLength, *status); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | |
michael@0 | 86 | #endif /* #if !UCONFIG_NO_FORMATTING */ |