ICU-8006 Add ucnv_isFixedWidth API and test.
X-SVN-Rev: 29467
This commit is contained in:
parent
9d855beaf8
commit
4892435224
@ -1,7 +1,7 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1998-2010, International Business Machines
|
||||
* Copyright (C) 1998-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
@ -2882,6 +2882,20 @@ ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status){
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
U_DRAFT UBool U_EXPORT2
|
||||
ucnv_isFixedWidth(UConverter *cnv, UErrorCode *status){
|
||||
if (U_FAILURE(*status)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (cnv == NULL) {
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return (cnv->sharedData->staticData->minBytesPerChar == cnv->sharedData->staticData->maxBytesPerChar) ? TRUE : FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 1999-2010, International Business Machines
|
||||
* Copyright (C) 1999-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* ucnv.h:
|
||||
@ -1992,6 +1992,19 @@ ucnv_fromUCountPending(const UConverter* cnv, UErrorCode* status);
|
||||
U_STABLE int32_t U_EXPORT2
|
||||
ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status);
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether or not the converter has a fixed ratio of bytes per
|
||||
* 16-bit char/UChar (e.g. converters that are SBCS or DBCS).
|
||||
* FALSE is returned with the UErrorCode if error occurs or cnv is NULL.
|
||||
* @param cnv The converter to be tested
|
||||
* @param status ICU error code in/out paramter
|
||||
* @return TRUE if the converter is fixed-width
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
U_DRAFT UBool U_EXPORT2
|
||||
ucnv_isFixedWidth(UConverter *cnv, UErrorCode *status);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -97,6 +97,8 @@ static void TestJitterbug2411(void);
|
||||
static void TestJB5275(void);
|
||||
static void TestJB5275_1(void);
|
||||
static void TestJitterbug6175(void);
|
||||
|
||||
static void TestIsFixedWidth(void);
|
||||
#endif
|
||||
|
||||
static void TestInBufSizes(void);
|
||||
@ -323,8 +325,9 @@ void addTestNewConvert(TestNode** root)
|
||||
addTest(root, &TestJitterbug2346, "tsconv/nucnvtst/TestJitterbug2346");
|
||||
addTest(root, &TestJitterbug2411, "tsconv/nucnvtst/TestJitterbug2411");
|
||||
addTest(root, &TestJitterbug6175, "tsconv/nucnvtst/TestJitterbug6175");
|
||||
#endif
|
||||
|
||||
addTest(root, &TestIsFixedWidth, "tsconv/nucnvtst/TestIsFixedWidth");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -5538,3 +5541,47 @@ static void TestJB5275(){
|
||||
}
|
||||
ucnv_close(conv);
|
||||
}
|
||||
|
||||
static void
|
||||
TestIsFixedWidth() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UConverter *cnv = NULL;
|
||||
int32_t i;
|
||||
|
||||
const char *fixedWidth[] = {
|
||||
"US-ASCII",
|
||||
"UTF32",
|
||||
"ibm-5478_P100-1995",
|
||||
"UTF16"
|
||||
};
|
||||
int32_t fixedWidthLength = 4;
|
||||
|
||||
const char *notFixedWidth[] = {
|
||||
"GB18030",
|
||||
"UTF8",
|
||||
"windows-949-2000"
|
||||
};
|
||||
int32_t notFixedWidthLength = 3;
|
||||
|
||||
for (i = 0; i < fixedWidthLength; i++) {
|
||||
cnv = ucnv_open(fixedWidth[i], &status);
|
||||
if (cnv == NULL || U_FAILURE(status)) {
|
||||
log_err("Error open converter: %s - %s \n", fixedWidth[i], u_errorName(status));
|
||||
}
|
||||
|
||||
if (!ucnv_isFixedWidth(cnv, &status)) {
|
||||
log_err("%s is a fixedWidth converter but returned FALSE.\n", fixedWidth[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < notFixedWidthLength; i++) {
|
||||
cnv = ucnv_open(notFixedWidth[i], &status);
|
||||
if (cnv == NULL || U_FAILURE(status)) {
|
||||
log_err("Error open converter: %s - %s \n", fixedWidth[i], u_errorName(status));
|
||||
}
|
||||
|
||||
if (ucnv_isFixedWidth(cnv, &status)) {
|
||||
log_err("%s is NOT a fixedWidth converter but returned TRUE.\n", fixedWidth[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user