casemap->action, status);
}
-int icu_utf16_casemap(struct icu_buf_utf16 * dest16,
- struct icu_buf_utf16 * src16,
- const char *locale, char action,
- UErrorCode *status)
-{
- int32_t dest16_len = 0;
- if (!src16->utf16_len)
- { /* guarding for empty source string */
- if (dest16->utf16)
- dest16->utf16[0] = (UChar) 0;
- dest16->utf16_len = 0;
- return U_ZERO_ERROR;
- }
-
+static uint32_t icu_utf16_sub(struct icu_buf_utf16 * dest16,
+ struct icu_buf_utf16 * src16,
+ const char *locale, char action,
+ UErrorCode *status)
+{
switch (action)
{
case 'l':
case 'L':
- dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
- src16->utf16, src16->utf16_len,
- locale, status);
- break;
+ return u_strToLower(dest16->utf16, dest16->utf16_cap,
+ src16->utf16, src16->utf16_len,
+ locale, status);
case 'u':
case 'U':
- dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
- src16->utf16, src16->utf16_len,
- locale, status);
+ return u_strToUpper(dest16->utf16, dest16->utf16_cap,
+ src16->utf16, src16->utf16_len,
+ locale, status);
break;
case 't':
case 'T':
- dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
- src16->utf16, src16->utf16_len,
- 0, locale, status);
+ return u_strToTitle(dest16->utf16, dest16->utf16_cap,
+ src16->utf16, src16->utf16_len,
+ 0, locale, status);
break;
case 'f':
case 'F':
- dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
- src16->utf16, src16->utf16_len,
- U_FOLD_CASE_DEFAULT, status);
+ return u_strFoldCase(dest16->utf16, dest16->utf16_cap,
+ src16->utf16, src16->utf16_len,
+ U_FOLD_CASE_DEFAULT, status);
break;
-
default:
- return U_UNSUPPORTED_ERROR;
+ *status = U_UNSUPPORTED_ERROR;
break;
}
+ return 0;
+}
+
+
+int icu_utf16_casemap(struct icu_buf_utf16 * dest16,
+ struct icu_buf_utf16 * src16,
+ const char *locale, char action,
+ UErrorCode *status)
+{
+ int32_t dest16_len = 0;
+
+ if (!src16->utf16_len)
+ { /* guarding for empty source string */
+ if (dest16->utf16)
+ dest16->utf16[0] = (UChar) 0;
+ dest16->utf16_len = 0;
+ return U_ZERO_ERROR;
+ }
+
+ dest16_len = icu_utf16_sub(dest16, src16, locale, action, status);
/* check for buffer overflow, resize and retry */
if (*status == U_BUFFER_OVERFLOW_ERROR
- && dest16 != src16 /* do not resize if in-place conversion */
- )
+ && dest16 != src16) /* do not resize if in-place conversion */
{
icu_buf_utf16_resize(dest16, dest16_len * 2);
*status = U_ZERO_ERROR;
- switch (action) {
- case 'l':
- case 'L':
- dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
- src16->utf16, src16->utf16_len,
- locale, status);
- break;
- case 'u':
- case 'U':
- dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
- src16->utf16, src16->utf16_len,
- locale, status);
- break;
- case 't':
- case 'T':
- dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
- src16->utf16, src16->utf16_len,
- 0, locale, status);
- break;
- case 'f':
- case 'F':
- dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
- src16->utf16, src16->utf16_len,
- U_FOLD_CASE_DEFAULT, status);
- break;
-
- default:
- return U_UNSUPPORTED_ERROR;
- break;
- }
+ icu_utf16_sub(dest16, src16, locale, action, status);
}
-
- if (U_SUCCESS(*status)
- && dest16_len <= dest16->utf16_cap)
+
+ if (U_SUCCESS(*status) && dest16_len <= dest16->utf16_cap)
dest16->utf16_len = dest16_len;
else
{