michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 1997-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * michael@0: * File USCRIPT.C michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 07/06/2001 Ram Creation. michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #include "unicode/uscript.h" michael@0: #include "unicode/ures.h" michael@0: #include "unicode/uchar.h" michael@0: #include "unicode/putil.h" michael@0: #include "uprops.h" michael@0: #include "cmemory.h" michael@0: #include "cstring.h" michael@0: michael@0: static const char kLocaleScript[] = "LocaleScript"; michael@0: michael@0: /* TODO: this is a bad API should be deprecated */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uscript_getCode(const char* nameOrAbbrOrLocale, michael@0: UScriptCode* fillIn, michael@0: int32_t capacity, michael@0: UErrorCode* err){ michael@0: michael@0: UScriptCode code = USCRIPT_INVALID_CODE; michael@0: int32_t numFilled=0; michael@0: int32_t len=0; michael@0: /* check arguments */ michael@0: if(err==NULL ||U_FAILURE(*err)){ michael@0: return numFilled; michael@0: } michael@0: if(nameOrAbbrOrLocale==NULL || fillIn == NULL || capacity<0){ michael@0: *err = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return numFilled; michael@0: } michael@0: michael@0: if(uprv_strchr(nameOrAbbrOrLocale, '-')==NULL && uprv_strchr(nameOrAbbrOrLocale, '_')==NULL ){ michael@0: /* try long and abbreviated script names first */ michael@0: code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, nameOrAbbrOrLocale); michael@0: michael@0: } michael@0: if(code==(UScriptCode)UCHAR_INVALID_CODE){ michael@0: /* Do not propagate error codes from just not finding a locale bundle. */ michael@0: UErrorCode localErrorCode = U_ZERO_ERROR; michael@0: UResourceBundle* resB = ures_open(NULL,nameOrAbbrOrLocale,&localErrorCode); michael@0: if(U_SUCCESS(localErrorCode)&& localErrorCode != U_USING_DEFAULT_WARNING){ michael@0: UResourceBundle* resD = ures_getByKey(resB,kLocaleScript,NULL,&localErrorCode); michael@0: if(U_SUCCESS(localErrorCode) ){ michael@0: len =0; michael@0: while(ures_hasNext(resD)){ michael@0: const UChar* name = ures_getNextString(resD,&len,NULL,&localErrorCode); michael@0: if(U_SUCCESS(localErrorCode)){ michael@0: char cName[50] = {'\0'}; michael@0: u_UCharsToChars(name,cName,len); michael@0: code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, cName); michael@0: /* got the script code now fill in the buffer */ michael@0: if(numFilled