Logo Search packages:      
Sourcecode: icu version File versions  Download package

U_STABLE int32_t U_EXPORT2 uscript_getCode ( const char *  nameOrAbbrOrLocale,
UScriptCode fillIn,
int32_t  capacity,
UErrorCode err 
)

Gets script codes associated with the given locale or ISO 15924 abbreviation or name. Fills in USCRIPT_MALAYALAM given "Malayam" OR "Mlym". Fills in USCRIPT_LATIN given "en" OR "en_US" If required capacity is greater than capacity of the destination buffer then the error code is set to U_BUFFER_OVERFLOW_ERROR and the required capacity is returned

Note: To search by short or long script alias only, use u_getPropertyValueEnum(UCHAR_SCRIPT, alias) instead. This does a fast lookup with no access of the locale data.

Parameters:
nameOrAbbrOrLocalename of the script, as given in PropertyValueAliases.txt, or ISO 15924 code or locale
fillInthe UScriptCode buffer to fill in the script code
capacitythe capacity (size) fo UScriptCode buffer passed in.
errthe error status code.
Returns:
The number of script codes filled in the buffer passed in ICU 2.4

Definition at line 28 of file uscript.c.

References NULL, U_BUFFER_OVERFLOW_ERROR, U_FAILURE, U_ILLEGAL_ARGUMENT_ERROR, U_SUCCESS, U_USING_DEFAULT_WARNING, U_ZERO_ERROR, UCHAR_INVALID_CODE, and UCHAR_SCRIPT.

                                {

    UScriptCode code = USCRIPT_INVALID_CODE;
    int32_t numFilled=0;
    int32_t len=0;
    /* check arguments */
    if(err==NULL ||U_FAILURE(*err)){
        return numFilled;
    }
    if(nameOrAbbrOrLocale==NULL || fillIn == NULL || capacity<0){
        *err = U_ILLEGAL_ARGUMENT_ERROR;
        return numFilled;
    }

    if(uprv_strchr(nameOrAbbrOrLocale, '-')==NULL && uprv_strchr(nameOrAbbrOrLocale, '_')==NULL ){
        /* try long and abbreviated script names first */
        code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, nameOrAbbrOrLocale);
        
    }
    if(code==(UScriptCode)UCHAR_INVALID_CODE){
       /* Do not propagate error codes from just not finding a locale bundle. */
        UErrorCode localErrorCode = U_ZERO_ERROR;
        UResourceBundle* resB = ures_open(NULL,nameOrAbbrOrLocale,&localErrorCode);
        if(U_SUCCESS(localErrorCode)&& localErrorCode != U_USING_DEFAULT_WARNING){
            UResourceBundle* resD = ures_getByKey(resB,kLocaleScript,NULL,&localErrorCode);
            if(U_SUCCESS(localErrorCode) ){
                len =0;
                while(ures_hasNext(resD)){
                    const UChar* name = ures_getNextString(resD,&len,NULL,&localErrorCode);
                    if(U_SUCCESS(localErrorCode)){
                        char cName[50] = {'\0'};
                        u_UCharsToChars(name,cName,len);
                        code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, cName);
                        /* got the script code now fill in the buffer */
                        if(numFilled<=capacity){ 
                            *(fillIn)++=code;
                            numFilled++;
                        }else{
                            ures_close(resD);
                            ures_close(resB);
                            *err=U_BUFFER_OVERFLOW_ERROR;
                            return len;
                        }
                    }
                }
            }
            ures_close(resD); 
        }
        ures_close(resB);
        code = USCRIPT_INVALID_CODE;
    }
    if(code==(UScriptCode)UCHAR_INVALID_CODE){
       /* still not found .. try long and abbreviated script names again */
        code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, nameOrAbbrOrLocale);
    }
    if(code!=(UScriptCode)UCHAR_INVALID_CODE){
        /* we found it */
        if(numFilled<=capacity){ 
            *(fillIn)++=code;
            numFilled++;
        }else{
            *err=U_BUFFER_OVERFLOW_ERROR;
            return len;
        }
    }
    return numFilled;
}

Generated by  Doxygen 1.6.0   Back to index