mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-1269 make u_charFromName() work with mixed-case input names
X-SVN-Rev: 6648
This commit is contained in:
parent
03b8c5bcdd
commit
67ac4d3964
2 changed files with 22 additions and 0 deletions
|
@ -187,11 +187,13 @@ U_CAPI UChar32 U_EXPORT2
|
|||
u_charFromName(UCharNameChoice nameChoice,
|
||||
const char *name,
|
||||
UErrorCode *pErrorCode) {
|
||||
char upper[120];
|
||||
FindName findName;
|
||||
AlgorithmicRange *algRange;
|
||||
uint32_t *p;
|
||||
uint32_t i;
|
||||
UChar32 c;
|
||||
char c0;
|
||||
|
||||
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
||||
return 0xffff;
|
||||
|
@ -206,6 +208,21 @@ u_charFromName(UCharNameChoice nameChoice,
|
|||
return 0xffff;
|
||||
}
|
||||
|
||||
/* uppercase the name first */
|
||||
for(i=0; i<sizeof(upper); ++i) {
|
||||
if((c0=*name++)!=0) {
|
||||
upper[i]=uprv_toupper(c0);
|
||||
} else {
|
||||
upper[i]=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i==sizeof(upper)) {
|
||||
/* name too long, there is no such character */
|
||||
return 0xffff;
|
||||
}
|
||||
name=upper;
|
||||
|
||||
/* try algorithmic names first */
|
||||
p=(uint32_t *)((uint8_t *)uCharNames+uCharNames->algNamesOffset);
|
||||
i=*p;
|
||||
|
|
|
@ -1432,6 +1432,11 @@ TestCharNames() {
|
|||
log_err("u_enumCharNames(0..0x1100000) error %s names count=%ld\n", u_errorName(errorCode), length);
|
||||
}
|
||||
|
||||
/* test that u_charFromName() uppercases the input name, i.e., works with mixed-case names (new in 2.0) */
|
||||
if(0x61!=u_charFromName(U_UNICODE_CHAR_NAME, "LATin smALl letTER A", &errorCode)) {
|
||||
log_err("u_charFromName(U_UNICODE_CHAR_NAME, \"LATin smALl letTER A\") did not find U+0061 (%s)\n", u_errorName(errorCode));
|
||||
}
|
||||
|
||||
/* ### TODO: test error cases and other interesting things */
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue