2001-07-10 18:33:40 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2010-10-29 15:41:56 +00:00
|
|
|
* Copyright (C) 1997-2010, International Business Machines
|
2001-07-10 18:33:40 +00:00
|
|
|
* 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"
|
2004-10-18 03:03:13 +00:00
|
|
|
#include "unicode/putil.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";
|
|
|
|
|
2006-02-16 22:49:34 +00:00
|
|
|
/* TODO: this is a bad API should be deprecated */
|
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
|
|
|
|
2008-03-14 06:41:45 +00:00
|
|
|
if(uprv_strchr(nameOrAbbrOrLocale, '-')==NULL && uprv_strchr(nameOrAbbrOrLocale, '_')==NULL ){
|
2006-02-16 22:49:34 +00:00
|
|
|
/* try long and abbreviated script names first */
|
|
|
|
code = (UScriptCode) u_getPropertyValueEnum(UCHAR_SCRIPT, nameOrAbbrOrLocale);
|
|
|
|
|
|
|
|
}
|
2002-10-30 18:25:27 +00:00
|
|
|
if(code==(UScriptCode)UCHAR_INVALID_CODE){
|
2006-02-16 22:49:34 +00:00
|
|
|
/* Do not propagate error codes from just not finding a locale bundle. */
|
2002-08-09 21:14:38 +00:00
|
|
|
UErrorCode localErrorCode = U_ZERO_ERROR;
|
2004-09-01 01:17:47 +00:00
|
|
|
UResourceBundle* resB = ures_open(NULL,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 */
|
2010-10-29 15:41:56 +00:00
|
|
|
if(numFilled<capacity){
|
2001-10-23 02:00:50 +00:00
|
|
|
*(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
|
|
|
}
|
2006-02-16 22:49:34 +00:00
|
|
|
ures_close(resD);
|
2001-07-10 18:33:40 +00:00
|
|
|
}
|
|
|
|
ures_close(resB);
|
2006-02-16 22:49:34 +00:00
|
|
|
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){
|
2001-10-23 02:00:50 +00:00
|
|
|
/* we found it */
|
2010-10-29 15:41:56 +00:00
|
|
|
if(numFilled<capacity){
|
2001-10-23 02:00:50 +00:00
|
|
|
*(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
|
|
|
|