2 **********************************************************************
3 * Copyright (C) 1997-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
9 * Modification History:
11 * Date Name Description
12 * 07/06/2001 Ram Creation.
13 ******************************************************************************
16 #include "unicode/uscript.h"
17 #include "unicode/ures.h"
18 #include "unicode/uchar.h"
19 #include "unicode/putil.h"
24 static const char kLocaleScript
[] = "LocaleScript";
26 /* TODO: this is a bad API should be deprecated */
27 U_CAPI
int32_t U_EXPORT2
28 uscript_getCode(const char* nameOrAbbrOrLocale
,
33 UScriptCode code
= USCRIPT_INVALID_CODE
;
37 if(err
==NULL
||U_FAILURE(*err
)){
40 if(nameOrAbbrOrLocale
==NULL
|| fillIn
== NULL
|| capacity
<0){
41 *err
= U_ILLEGAL_ARGUMENT_ERROR
;
45 if(uprv_strchr(nameOrAbbrOrLocale
, '-')==NULL
&& uprv_strchr(nameOrAbbrOrLocale
, '_')==NULL
){
46 /* try long and abbreviated script names first */
47 code
= (UScriptCode
) u_getPropertyValueEnum(UCHAR_SCRIPT
, nameOrAbbrOrLocale
);
50 if(code
==(UScriptCode
)UCHAR_INVALID_CODE
){
51 /* Do not propagate error codes from just not finding a locale bundle. */
52 UErrorCode localErrorCode
= U_ZERO_ERROR
;
53 UResourceBundle
* resB
= ures_open(NULL
,nameOrAbbrOrLocale
,&localErrorCode
);
54 if(U_SUCCESS(localErrorCode
)&& localErrorCode
!= U_USING_DEFAULT_WARNING
){
55 UResourceBundle
* resD
= ures_getByKey(resB
,kLocaleScript
,NULL
,&localErrorCode
);
56 if(U_SUCCESS(localErrorCode
) ){
58 while(ures_hasNext(resD
)){
59 const UChar
* name
= ures_getNextString(resD
,&len
,NULL
,&localErrorCode
);
60 if(U_SUCCESS(localErrorCode
)){
61 char cName
[50] = {'\0'};
62 u_UCharsToChars(name
,cName
,len
);
63 code
= (UScriptCode
) u_getPropertyValueEnum(UCHAR_SCRIPT
, cName
);
64 /* got the script code now fill in the buffer */
65 if(numFilled
<capacity
){
71 *err
=U_BUFFER_OVERFLOW_ERROR
;
80 code
= USCRIPT_INVALID_CODE
;
82 if(code
==(UScriptCode
)UCHAR_INVALID_CODE
){
83 /* still not found .. try long and abbreviated script names again */
84 code
= (UScriptCode
) u_getPropertyValueEnum(UCHAR_SCRIPT
, nameOrAbbrOrLocale
);
86 if(code
!=(UScriptCode
)UCHAR_INVALID_CODE
){
88 if(numFilled
<capacity
){
92 *err
=U_BUFFER_OVERFLOW_ERROR
;