2001-07-10 18:33:40 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
|
|
|
* Copyright (C) 1997-2001, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
*
|
|
|
|
* File USCRIPT.C
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 07/06/2001 Ram Creation.
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/uscript.h"
|
2001-09-11 05:00:34 +00:00
|
|
|
#include "unicode/ures.h"
|
2002-10-30 18:25:27 +00:00
|
|
|
#include "unicode/uchar.h"
|
2002-06-01 00:43:07 +00:00
|
|
|
#include "uprops.h"
|
2002-05-13 21:50:59 +00:00
|
|
|
#include "cmemory.h"
|
2001-09-11 05:00:34 +00:00
|
|
|
#include "cstring.h"
|
2001-07-10 18:33:40 +00:00
|
|
|
|
2001-09-07 00:54:02 +00:00
|
|
|
static const char kLocaleScript[] = "LocaleScript";
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-10-23 02:00:50 +00:00
|
|
|
uscript_getCode(const char* nameOrAbbrOrLocale,
|
|
|
|
UScriptCode* fillIn,
|
|
|
|
int32_t capacity,
|
|
|
|
UErrorCode* err){
|
|
|
|
|
2001-09-11 05:00:34 +00:00
|
|
|
UScriptCode code = USCRIPT_INVALID_CODE;
|
2001-10-23 02:00:50 +00:00
|
|
|
int32_t numFilled=0;
|
|
|
|
int32_t len=0;
|
2001-07-10 18:33:40 +00:00
|
|
|
/* check arguments */
|
2002-04-05 02:49:56 +00:00
|
|
|
if(err==NULL ||U_FAILURE(*err)){
|
|
|
|
return numFilled;
|
|
|
|
}
|
|
|
|
if(nameOrAbbrOrLocale==NULL || fillIn == NULL || capacity<0){
|
|
|
|
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
2001-10-23 02:00:50 +00:00
|
|
|
return numFilled;
|
2001-07-10 18:33:40 +00:00
|
|
|
}
|
2002-10-30 18:25:27 +00:00
|
|
|
|
|
|
|
/* try long and abbreviated script names first */
|
|
|
|
code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, nameOrAbbrOrLocale);
|
2001-10-23 02:00:50 +00:00
|
|
|
|
2001-07-10 18:33:40 +00:00
|
|
|
/* we still haven't found it try locale */
|
2002-10-30 18:25:27 +00:00
|
|
|
if(code==(UScriptCode)UCHAR_INVALID_CODE){
|
2002-08-09 21:14:38 +00:00
|
|
|
/* Do not propagate error codes from just not finding a locale bundle. */
|
|
|
|
UErrorCode localErrorCode = U_ZERO_ERROR;
|
|
|
|
UResourceBundle* resB = ures_open(u_getDataDirectory(),nameOrAbbrOrLocale,&localErrorCode);
|
2002-08-21 19:12:24 +00:00
|
|
|
if(U_SUCCESS(localErrorCode)&& localErrorCode != U_USING_DEFAULT_WARNING){
|
2002-08-09 21:14:38 +00:00
|
|
|
UResourceBundle* resD = ures_getByKey(resB,kLocaleScript,NULL,&localErrorCode);
|
|
|
|
if(U_SUCCESS(localErrorCode) ){
|
2001-10-23 02:00:50 +00:00
|
|
|
len =0;
|
|
|
|
while(ures_hasNext(resD)){
|
2002-08-09 21:14:38 +00:00
|
|
|
const UChar* name = ures_getNextString(resD,&len,NULL,&localErrorCode);
|
|
|
|
if(U_SUCCESS(localErrorCode)){
|
2001-10-23 02:00:50 +00:00
|
|
|
char cName[50] = {'\0'};
|
|
|
|
u_UCharsToChars(name,cName,len);
|
2002-10-30 18:25:27 +00:00
|
|
|
code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, cName);
|
2001-10-23 02:00:50 +00:00
|
|
|
/* got the script code now fill in the buffer */
|
|
|
|
if(numFilled<=capacity){
|
|
|
|
*(fillIn)++=code;
|
|
|
|
numFilled++;
|
|
|
|
}else{
|
2001-10-27 00:15:39 +00:00
|
|
|
ures_close(resD);
|
|
|
|
ures_close(resB);
|
2001-10-23 02:00:50 +00:00
|
|
|
*err=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-07-10 18:33:40 +00:00
|
|
|
}
|
|
|
|
ures_close(resD);
|
|
|
|
|
|
|
|
}
|
|
|
|
ures_close(resB);
|
2001-10-23 02:00:50 +00:00
|
|
|
}else{
|
|
|
|
/* we found it */
|
|
|
|
if(numFilled<=capacity){
|
|
|
|
*(fillIn)++=code;
|
|
|
|
numFilled++;
|
|
|
|
}else{
|
|
|
|
*err=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
return len;
|
|
|
|
}
|
2001-07-10 18:33:40 +00:00
|
|
|
}
|
2001-10-23 02:00:50 +00:00
|
|
|
return numFilled;
|
2001-07-10 18:33:40 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
2001-09-11 05:00:34 +00:00
|
|
|
uscript_getName(UScriptCode scriptCode){
|
2002-10-30 18:25:27 +00:00
|
|
|
return u_getPropertyValueName(UCHAR_SCRIPT, scriptCode,
|
|
|
|
U_LONG_PROPERTY_NAME);
|
2001-07-10 18:33:40 +00:00
|
|
|
}
|
2002-10-30 18:25:27 +00:00
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
2001-09-11 05:00:34 +00:00
|
|
|
uscript_getShortName(UScriptCode scriptCode){
|
2002-10-30 18:25:27 +00:00
|
|
|
return u_getPropertyValueName(UCHAR_SCRIPT, scriptCode,
|
|
|
|
U_SHORT_PROPERTY_NAME);
|
2001-07-10 18:33:40 +00:00
|
|
|
}
|
2002-05-13 21:50:59 +00:00
|
|
|
|