2 **********************************************************************
3 * Copyright (C) 1997-2004, 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 U_CAPI
int32_t U_EXPORT2
27 uscript_getCode(const char* nameOrAbbrOrLocale
,
32 UScriptCode code
= USCRIPT_INVALID_CODE
;
36 if(err
==NULL
||U_FAILURE(*err
)){
39 if(nameOrAbbrOrLocale
==NULL
|| fillIn
== NULL
|| capacity
<0){
40 *err
= U_ILLEGAL_ARGUMENT_ERROR
;
44 /* try long and abbreviated script names first */
45 code
= (UScriptCode
) u_getPropertyValueEnum(UCHAR_SCRIPT
, nameOrAbbrOrLocale
);
47 /* we still haven't found it try locale */
48 if(code
==(UScriptCode
)UCHAR_INVALID_CODE
){
49 /* Do not propagate error codes from just not finding a locale bundle. */
50 UErrorCode localErrorCode
= U_ZERO_ERROR
;
51 UResourceBundle
* resB
= ures_open(NULL
,nameOrAbbrOrLocale
,&localErrorCode
);
52 if(U_SUCCESS(localErrorCode
)&& localErrorCode
!= U_USING_DEFAULT_WARNING
){
53 UResourceBundle
* resD
= ures_getByKey(resB
,kLocaleScript
,NULL
,&localErrorCode
);
54 if(U_SUCCESS(localErrorCode
) ){
56 while(ures_hasNext(resD
)){
57 const UChar
* name
= ures_getNextString(resD
,&len
,NULL
,&localErrorCode
);
58 if(U_SUCCESS(localErrorCode
)){
59 char cName
[50] = {'\0'};
60 u_UCharsToChars(name
,cName
,len
);
61 code
= (UScriptCode
) u_getPropertyValueEnum(UCHAR_SCRIPT
, cName
);
62 /* got the script code now fill in the buffer */
63 if(numFilled
<=capacity
){
69 *err
=U_BUFFER_OVERFLOW_ERROR
;
81 if(numFilled
<=capacity
){
85 *err
=U_BUFFER_OVERFLOW_ERROR
;
92 U_CAPI
const char* U_EXPORT2
93 uscript_getName(UScriptCode scriptCode
){
94 return u_getPropertyValueName(UCHAR_SCRIPT
, scriptCode
,
95 U_LONG_PROPERTY_NAME
);
98 U_CAPI
const char* U_EXPORT2
99 uscript_getShortName(UScriptCode scriptCode
){
100 return u_getPropertyValueName(UCHAR_SCRIPT
, scriptCode
,
101 U_SHORT_PROPERTY_NAME
);