]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ********************************************************************** | |
73c04bcf | 3 | * Copyright (C) 1997-2006, International Business Machines |
b75a7d8f A |
4 | * Corporation and others. All Rights Reserved. |
5 | ********************************************************************** | |
6 | * | |
7 | * File USCRIPT.C | |
8 | * | |
9 | * Modification History: | |
10 | * | |
11 | * Date Name Description | |
12 | * 07/06/2001 Ram Creation. | |
13 | ****************************************************************************** | |
14 | */ | |
15 | ||
16 | #include "unicode/uscript.h" | |
17 | #include "unicode/ures.h" | |
18 | #include "unicode/uchar.h" | |
374ca955 | 19 | #include "unicode/putil.h" |
b75a7d8f A |
20 | #include "uprops.h" |
21 | #include "cmemory.h" | |
22 | #include "cstring.h" | |
23 | ||
24 | static const char kLocaleScript[] = "LocaleScript"; | |
73c04bcf A |
25 | static const char kHyphen = '-'; |
26 | static const char kUnderscore = '_'; | |
b75a7d8f | 27 | |
73c04bcf | 28 | /* TODO: this is a bad API should be deprecated */ |
b75a7d8f A |
29 | U_CAPI int32_t U_EXPORT2 |
30 | uscript_getCode(const char* nameOrAbbrOrLocale, | |
31 | UScriptCode* fillIn, | |
32 | int32_t capacity, | |
33 | UErrorCode* err){ | |
34 | ||
35 | UScriptCode code = USCRIPT_INVALID_CODE; | |
36 | int32_t numFilled=0; | |
37 | int32_t len=0; | |
38 | /* check arguments */ | |
39 | if(err==NULL ||U_FAILURE(*err)){ | |
40 | return numFilled; | |
41 | } | |
42 | if(nameOrAbbrOrLocale==NULL || fillIn == NULL || capacity<0){ | |
43 | *err = U_ILLEGAL_ARGUMENT_ERROR; | |
44 | return numFilled; | |
45 | } | |
46 | ||
73c04bcf A |
47 | if(uprv_strchr(nameOrAbbrOrLocale, kHyphen)==NULL && uprv_strchr(nameOrAbbrOrLocale, kUnderscore)==NULL ){ |
48 | /* try long and abbreviated script names first */ | |
49 | code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, nameOrAbbrOrLocale); | |
50 | ||
51 | } | |
b75a7d8f | 52 | if(code==(UScriptCode)UCHAR_INVALID_CODE){ |
73c04bcf | 53 | /* Do not propagate error codes from just not finding a locale bundle. */ |
b75a7d8f | 54 | UErrorCode localErrorCode = U_ZERO_ERROR; |
374ca955 | 55 | UResourceBundle* resB = ures_open(NULL,nameOrAbbrOrLocale,&localErrorCode); |
b75a7d8f A |
56 | if(U_SUCCESS(localErrorCode)&& localErrorCode != U_USING_DEFAULT_WARNING){ |
57 | UResourceBundle* resD = ures_getByKey(resB,kLocaleScript,NULL,&localErrorCode); | |
58 | if(U_SUCCESS(localErrorCode) ){ | |
59 | len =0; | |
60 | while(ures_hasNext(resD)){ | |
61 | const UChar* name = ures_getNextString(resD,&len,NULL,&localErrorCode); | |
62 | if(U_SUCCESS(localErrorCode)){ | |
63 | char cName[50] = {'\0'}; | |
64 | u_UCharsToChars(name,cName,len); | |
65 | code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, cName); | |
66 | /* got the script code now fill in the buffer */ | |
67 | if(numFilled<=capacity){ | |
68 | *(fillIn)++=code; | |
69 | numFilled++; | |
70 | }else{ | |
71 | ures_close(resD); | |
72 | ures_close(resB); | |
73 | *err=U_BUFFER_OVERFLOW_ERROR; | |
74 | return len; | |
75 | } | |
76 | } | |
77 | } | |
78 | } | |
73c04bcf | 79 | ures_close(resD); |
b75a7d8f A |
80 | } |
81 | ures_close(resB); | |
73c04bcf A |
82 | code = USCRIPT_INVALID_CODE; |
83 | } | |
84 | if(code==(UScriptCode)UCHAR_INVALID_CODE){ | |
85 | /* still not found .. try long and abbreviated script names again */ | |
86 | code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, nameOrAbbrOrLocale); | |
87 | } | |
88 | if(code!=(UScriptCode)UCHAR_INVALID_CODE){ | |
b75a7d8f A |
89 | /* we found it */ |
90 | if(numFilled<=capacity){ | |
91 | *(fillIn)++=code; | |
92 | numFilled++; | |
93 | }else{ | |
94 | *err=U_BUFFER_OVERFLOW_ERROR; | |
95 | return len; | |
96 | } | |
97 | } | |
98 | return numFilled; | |
99 | } | |
100 | ||
101 | U_CAPI const char* U_EXPORT2 | |
102 | uscript_getName(UScriptCode scriptCode){ | |
103 | return u_getPropertyValueName(UCHAR_SCRIPT, scriptCode, | |
104 | U_LONG_PROPERTY_NAME); | |
105 | } | |
106 | ||
107 | U_CAPI const char* U_EXPORT2 | |
108 | uscript_getShortName(UScriptCode scriptCode){ | |
109 | return u_getPropertyValueName(UCHAR_SCRIPT, scriptCode, | |
110 | U_SHORT_PROPERTY_NAME); | |
111 | } | |
112 |