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