1 /* $Id: icu_I18N.c,v 1.1 2007-04-30 13:56:52 marc Exp $
2 Copyright (c) 2006-2007, Index Data.
4 This file is part of Pazpar2.
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 #include <yaz/timing.h>
38 #include <unicode/ustring.h> /* some more string fcns*/
40 //#include <unicode/ustdio.h>
41 //#include <unicode/utypes.h> /* Basic ICU data types */
42 //#include <unicode/ucol.h>
43 //#include <unicode/ucnv.h> /* C Converter API */
44 //#include <unicode/uchar.h> /* char names */
45 //#include <unicode/uloc.h>
46 //#include <unicode/ubrk.h>
47 /* #include <unicode/unistr.h> */
51 int icu_check_status (UErrorCode status)
55 "ICU Error: %d %s\n", status, u_errorName(status));
60 UChar* icu_utf16_from_utf8(UChar *utf16,
65 size_t utf8_len = strlen(utf8);
66 return icu_utf16_from_utf8n(utf16, utf16_cap, utf16_len,
71 UChar* icu_utf16_from_utf8n(UChar *utf16,
77 UErrorCode status = U_ZERO_ERROR;
78 u_strFromUTF8(utf16, utf16_cap, utf16_len, utf8, (int32_t) utf8_len,
80 if (U_ZERO_ERROR != icu_check_status(status))
87 char* icu_utf16_to_utf8(char *utf8,
93 UErrorCode status = U_ZERO_ERROR;
94 u_strToUTF8(utf8, (int32_t) utf8_cap, (int32_t *)utf8_len,
95 utf16, utf16_len, &status);
96 if (U_ZERO_ERROR != icu_check_status(status))
103 int32_t icu_utf16_casemap(UChar *dest16, int32_t dest16_cap,
104 const UChar *src16, int32_t src16_len,
105 const char *locale, char action)
107 UErrorCode status = U_ZERO_ERROR;
108 int32_t dest16_len = 0;
112 dest16_len = u_strToLower(dest16, dest16_cap, src16, src16_len,
116 dest16_len = u_strToUpper(dest16, dest16_cap, src16, src16_len,
120 dest16_len = u_strToTitle(dest16, dest16_cap, src16, src16_len,
124 dest16_len = u_strFoldCase(dest16, dest16_cap, src16, src16_len,
125 U_FOLD_CASE_DEFAULT, &status);
133 if (U_ZERO_ERROR != icu_check_status(status))
140 char * icu_casemap(NMEM nmem, char *buf, size_t buf_cap,
141 size_t *dest8_len, const char *src8,
142 const char *locale, char action)
144 size_t src8_len = strlen(src8);
151 if (!buf || !(buf_cap > 0) || !src8_len)
154 // converting buf to utf16
155 buf = (char *)icu_utf16_from_utf8n((UChar *) buf,
156 (int32_t) buf_cap, &buf_len,
160 buf_len = (size_t) icu_utf16_casemap((UChar *)buf, (int32_t) buf_cap,
161 (const UChar *)buf, (int32_t) buf_len,
164 // converting buf to utf8
165 buf = icu_utf16_to_utf8(buf, buf_cap, (size_t *) &buf_len,
166 (const UChar *) buf, (int32_t) buf_len);
169 // copying out to nmem
173 *dest8_len = buf_len;
175 dest8 = nmem_strdup(nmem, buf);
190 * indent-tabs-mode: nil
192 * vim: shiftwidth=4 tabstop=8 expandtab