X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ficu_casemap.c;h=1aa941b3ccefaec023b64da15d7285e005849282;hb=5bc2ee09e4dff0f872ce738a5327bced915e3474;hp=26aa73744ef641fe1f6c59fd5e93e9a22d80f37b;hpb=527a008f2f3b1a19a968a7a1275132a04aa4d945;p=yaz-moved-to-github.git diff --git a/src/icu_casemap.c b/src/icu_casemap.c index 26aa737..1aa941b 100644 --- a/src/icu_casemap.c +++ b/src/icu_casemap.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data + * Copyright (C) 1995-2012 Index Data * See the file LICENSE for details. */ @@ -31,21 +31,21 @@ struct icu_casemap }; struct icu_casemap * icu_casemap_create(char action, UErrorCode *status) -{ +{ struct icu_casemap * casemap = (struct icu_casemap *) xmalloc(sizeof(struct icu_casemap)); casemap->action = action; switch (casemap->action) { - case 'l': - case 'L': - case 'u': - case 'U': - case 't': - case 'T': - case 'f': - case 'F': + case 'l': + case 'L': + case 'u': + case 'U': + case 't': + case 'T': + case 'f': + case 'F': break; default: icu_casemap_destroy(casemap); @@ -73,13 +73,52 @@ int icu_casemap_casemap(struct icu_casemap * casemap, UErrorCode *status, const char *locale) { - if(!casemap) + if (!casemap) return 0; - + return icu_utf16_casemap(dest16, src16, locale, casemap->action, status); } + +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': + return u_strToLower(dest16->utf16, dest16->utf16_cap, + src16->utf16, src16->utf16_len, + locale, status); + case 'u': + case 'U': + return u_strToUpper(dest16->utf16, dest16->utf16_cap, + src16->utf16, src16->utf16_len, + locale, status); + break; + case 't': + case 'T': + return u_strToTitle(dest16->utf16, dest16->utf16_cap, + src16->utf16, src16->utf16_len, + 0, locale, status); + break; + case 'f': + case 'F': + return u_strFoldCase(dest16->utf16, dest16->utf16_cap, + src16->utf16, src16->utf16_len, + U_FOLD_CASE_DEFAULT, status); + break; + default: + *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, @@ -94,81 +133,20 @@ int icu_utf16_casemap(struct icu_buf_utf16 * dest16, dest16->utf16_len = 0; return 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; - } + + 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 { @@ -176,7 +154,7 @@ int icu_utf16_casemap(struct icu_buf_utf16 * dest16, dest16->utf16[0] = (UChar) 0; dest16->utf16_len = 0; } - + return *status; }