mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 00:43:32 +00:00
ICU-3050 fix a bug found while porting and add a test
X-SVN-Rev: 12933
This commit is contained in:
parent
5c9a94f0ea
commit
596578756a
3 changed files with 138 additions and 47 deletions
icu4c/source
|
@ -685,25 +685,27 @@ usprep_prepare( const UStringPrepProfile* profile,
|
|||
// normalize
|
||||
if(doNFKC == TRUE){
|
||||
b2Len = usprep_normalize(b1,b1Len, b2,b2Capacity,status);
|
||||
|
||||
if(*status == U_BUFFER_OVERFLOW_ERROR){
|
||||
// redo processing of string
|
||||
/* we do not have enough room so grow the buffer*/
|
||||
b2 = (UChar*) uprv_malloc(b2Len * U_SIZEOF_UCHAR);
|
||||
if(b2==NULL){
|
||||
*status = U_MEMORY_ALLOCATION_ERROR;
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
||||
*status = U_ZERO_ERROR; // reset error
|
||||
|
||||
b2Len = usprep_normalize(b1,b1Len, b2,b2Len,status);
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
b2 = b1;
|
||||
b2Len = b1Len;
|
||||
}
|
||||
|
||||
if(*status == U_BUFFER_OVERFLOW_ERROR){
|
||||
// redo processing of string
|
||||
/* we do not have enough room so grow the buffer*/
|
||||
b2 = (UChar*) uprv_malloc(b2Len * U_SIZEOF_UCHAR);
|
||||
if(b2==NULL){
|
||||
*status = U_MEMORY_ALLOCATION_ERROR;
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
||||
*status = U_ZERO_ERROR; // reset error
|
||||
|
||||
b2Len = usprep_normalize(b2,b2Len, b2,b2Len,status);
|
||||
|
||||
}
|
||||
|
||||
if(U_FAILURE(*status)){
|
||||
goto CLEANUP;
|
||||
|
|
|
@ -168,43 +168,43 @@ syntaxError( const UChar* rules,
|
|||
}
|
||||
|
||||
|
||||
/* sorted array for binary search*/
|
||||
static const char* special_prefixes[]={
|
||||
"ANONYMOUS",
|
||||
"AUTHENTICATED"
|
||||
"BATCH",
|
||||
"DIALUP",
|
||||
"EVERYONE",
|
||||
"GROUP",
|
||||
"INTERACTIVE",
|
||||
"NETWORK",
|
||||
"OWNER",
|
||||
};
|
||||
/* sorted array for binary search*/
|
||||
static const char* special_prefixes[]={
|
||||
"ANONYMOUS",
|
||||
"AUTHENTICATED",
|
||||
"BATCH",
|
||||
"DIALUP",
|
||||
"EVERYONE",
|
||||
"GROUP",
|
||||
"INTERACTIVE",
|
||||
"NETWORK",
|
||||
"OWNER",
|
||||
};
|
||||
|
||||
|
||||
/* binary search the sorted array */
|
||||
static int
|
||||
findStringIndex(const char* const *sortedArr, int32_t sortedArrLen, const char* target, int32_t targetLen){
|
||||
/* binary search the sorted array */
|
||||
static int
|
||||
findStringIndex(const char* const *sortedArr, int32_t sortedArrLen, const char* target, int32_t targetLen){
|
||||
|
||||
int left, middle, right,rc;
|
||||
int left, middle, right,rc;
|
||||
|
||||
left =0;
|
||||
right= sortedArrLen-1;
|
||||
left =0;
|
||||
right= sortedArrLen-1;
|
||||
|
||||
while(left <= right){
|
||||
middle = (left+right)/2;
|
||||
rc=strncmp(sortedArr[middle],target, targetLen);
|
||||
while(left <= right){
|
||||
middle = (left+right)/2;
|
||||
rc=strncmp(sortedArr[middle],target, targetLen);
|
||||
|
||||
if(rc<0){
|
||||
left = middle+1;
|
||||
}else if(rc >0){
|
||||
right = middle -1;
|
||||
}else{
|
||||
return middle;
|
||||
if(rc<0){
|
||||
left = middle+1;
|
||||
}else if(rc >0){
|
||||
right = middle -1;
|
||||
}else{
|
||||
return middle;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
getPrefixSuffix(const char *src, int32_t srcLength,
|
||||
|
@ -237,7 +237,7 @@ getPrefixSuffix(const char *src, int32_t srcLength,
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
#define AT_SIGN 0x0040
|
||||
int32_t
|
||||
nfs4_mixed_prepare( const char* src, int32_t srcLength,
|
||||
char* dest, int32_t destCapacity,
|
||||
|
@ -291,10 +291,14 @@ nfs4_mixed_prepare( const char* src, int32_t srcLength,
|
|||
sLen = nfs4_prepare(suffix, suffixLen, s, sLen, NFS4_MIXED_PREP_SUFFIX, parseError, status);
|
||||
}
|
||||
}
|
||||
reqLen = pLen+sLen;
|
||||
reqLen = pLen+sLen+1 /* for the delimiter */;
|
||||
if(dest != NULL && reqLen <= destCapacity){
|
||||
memmove(dest, p, pLen);
|
||||
memmove(dest+pLen, s, sLen);
|
||||
/* add the suffix */
|
||||
if(suffix!=NULL){
|
||||
dest[pLen++] = AT_SIGN;
|
||||
memmove(dest+pLen, s, sLen);
|
||||
}
|
||||
}
|
||||
|
||||
CLEANUP:
|
||||
|
|
|
@ -43,7 +43,7 @@ addUStringPrepTest(TestNode** root)
|
|||
addTest(root, &Test_nfs4_cs_prep_data, "spreptst/Test_nfs4_cs_prep_data");
|
||||
addTest(root, &Test_nfs4_cis_prep_data, "spreptst/Test_nfs4_cis_prep_data");
|
||||
addTest(root, &Test_nfs4_mixed_prep_data, "spreptst/Test_nfs4_mixed_prep_data");
|
||||
/*addTest(root, &Test_nfs4_cs_prep, "spreptst/Test_nfs4_cs_prep");*/
|
||||
addTest(root, &Test_nfs4_cs_prep, "spreptst/Test_nfs4_cs_prep");
|
||||
addTest(root, &Test_nfs4_cis_prep, "spreptst/Test_nfs4_cis_prep");
|
||||
addTest(root, &Test_nfs4_mixed_prep, "spreptst/Test_nfs4_mixed_prep");
|
||||
}
|
||||
|
@ -439,6 +439,91 @@ Test_nfs4_mixed_prep(void){
|
|||
|
||||
}
|
||||
|
||||
static void
|
||||
Test_nfs4_cs_prep(void){
|
||||
{
|
||||
/* BiDi checking is turned off */
|
||||
const char *source = "\\uC138\\uACC4\\uC758\\uBAA8\\uB4E0\\uC0AC\\uB78C\\uB4E4\\uC774\\u0644\\u064A\\u0647\\uD55C\\uAD6D\\uC5B4\\uB97C\\uC774\\uD574\\uD55C\\uB2E4\\uBA74";
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
char src[MAX_BUFFER_SIZE]={'\0'};
|
||||
UParseError parseError;
|
||||
int32_t srcLen = unescapeData(source, strlen(source), src, MAX_BUFFER_SIZE, &status);
|
||||
if(U_SUCCESS(status)){
|
||||
char dest[MAX_BUFFER_SIZE] = {'\0'};
|
||||
int32_t destLen = nfs4_cs_prepare(src, srcLen, dest, MAX_BUFFER_SIZE, FALSE, &parseError, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("StringPrep failed with error: %s\n", u_errorName(status));
|
||||
}
|
||||
if(strcmp(dest,src)!=0){
|
||||
log_err("Did not get the expected output!");
|
||||
}
|
||||
}else{
|
||||
log_err("Conversion failed with error: %s\n", u_errorName(status));
|
||||
}
|
||||
}
|
||||
{
|
||||
/* Normalization turned off */
|
||||
const char *source = "www.\\u00E0\\u00B3\\u00AF.com";
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
char src[MAX_BUFFER_SIZE]={'\0'};
|
||||
UParseError parseError;
|
||||
int32_t srcLen = unescapeData(source, strlen(source), src, MAX_BUFFER_SIZE, &status);
|
||||
if(U_SUCCESS(status)){
|
||||
char dest[MAX_BUFFER_SIZE] = {'\0'};
|
||||
int32_t destLen = nfs4_cs_prepare(src, srcLen, dest, MAX_BUFFER_SIZE, FALSE, &parseError, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("StringPrep failed with error: %s\n", u_errorName(status));
|
||||
}
|
||||
if(strcmp(dest,src)!=0){
|
||||
log_err("Did not get the expected output!");
|
||||
}
|
||||
}else{
|
||||
log_err("Conversion failed with error: %s\n", u_errorName(status));
|
||||
}
|
||||
}
|
||||
{
|
||||
/* case mapping turned off */
|
||||
const char *source = "THISISATEST";
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
char src[MAX_BUFFER_SIZE]={'\0'};
|
||||
UParseError parseError;
|
||||
int32_t srcLen = unescapeData(source, strlen(source), src, MAX_BUFFER_SIZE, &status);
|
||||
if(U_SUCCESS(status)){
|
||||
char dest[MAX_BUFFER_SIZE] = {'\0'};
|
||||
int32_t destLen = nfs4_cs_prepare(src, srcLen, dest, MAX_BUFFER_SIZE, TRUE, &parseError, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("StringPrep failed with error: %s\n", u_errorName(status));
|
||||
}
|
||||
if(strcmp(dest,src)!=0){
|
||||
log_err("Did not get the expected output!");
|
||||
}
|
||||
}else{
|
||||
log_err("Conversion failed with error: %s\n", u_errorName(status));
|
||||
}
|
||||
}
|
||||
{
|
||||
/* case mapping turned on */
|
||||
const char *source = "THISISATEST";
|
||||
const char *expected = "thisisatest";
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
char src[MAX_BUFFER_SIZE]={'\0'};
|
||||
UParseError parseError;
|
||||
int32_t srcLen = unescapeData(source, strlen(source), src, MAX_BUFFER_SIZE, &status);
|
||||
if(U_SUCCESS(status)){
|
||||
char dest[MAX_BUFFER_SIZE] = {'\0'};
|
||||
int32_t destLen = nfs4_cs_prepare(src, srcLen, dest, MAX_BUFFER_SIZE, FALSE, &parseError, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("StringPrep failed with error: %s\n", u_errorName(status));
|
||||
}
|
||||
if(strcmp(expected, dest)!=0){
|
||||
log_err("Did not get the expected output!");
|
||||
}
|
||||
}else{
|
||||
log_err("Conversion failed with error: %s\n", u_errorName(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue