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