2 **********************************************************************
3 * Copyright (C) 1997-2006, 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";
25 static const char kHyphen
= '-';
26 static const char kUnderscore
= '_';
28 /* TODO: this is a bad API should be deprecated */
29 U_CAPI
int32_t U_EXPORT2
30 uscript_getCode(const char* nameOrAbbrOrLocale
,
35 UScriptCode code
= USCRIPT_INVALID_CODE
;
39 if(err
==NULL
||U_FAILURE(*err
)){
42 if(nameOrAbbrOrLocale
==NULL
|| fillIn
== NULL
|| capacity
<0){
43 *err
= U_ILLEGAL_ARGUMENT_ERROR
;
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
);
52 if(code
==(UScriptCode
)UCHAR_INVALID_CODE
){
53 /* Do not propagate error codes from just not finding a locale bundle. */
54 UErrorCode localErrorCode
= U_ZERO_ERROR
;
55 UResourceBundle
* resB
= ures_open(NULL
,nameOrAbbrOrLocale
,&localErrorCode
);
56 if(U_SUCCESS(localErrorCode
)&& localErrorCode
!= U_USING_DEFAULT_WARNING
){
57 UResourceBundle
* resD
= ures_getByKey(resB
,kLocaleScript
,NULL
,&localErrorCode
);
58 if(U_SUCCESS(localErrorCode
) ){
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
){
73 *err
=U_BUFFER_OVERFLOW_ERROR
;
82 code
= USCRIPT_INVALID_CODE
;
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
);
88 if(code
!=(UScriptCode
)UCHAR_INVALID_CODE
){
90 if(numFilled
<=capacity
){
94 *err
=U_BUFFER_OVERFLOW_ERROR
;
101 U_CAPI
const char* U_EXPORT2
102 uscript_getName(UScriptCode scriptCode
){
103 return u_getPropertyValueName(UCHAR_SCRIPT
, scriptCode
,
104 U_LONG_PROPERTY_NAME
);
107 U_CAPI
const char* U_EXPORT2
108 uscript_getShortName(UScriptCode scriptCode
){
109 return u_getPropertyValueName(UCHAR_SCRIPT
, scriptCode
,
110 U_SHORT_PROPERTY_NAME
);