00001 /* Part of the culibs project, <http://www.eideticdew.org/culibs/>. 00002 * Copyright (C) 2007 Petter Urkedal <urkedal@nbi.dk> 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef CU_WCHAR_H 00019 #define CU_WCHAR_H 00020 00021 #include <cu/fwd.h> 00022 #include <wchar.h> 00023 #include <limits.h> 00024 #include <iconv.h> 00025 00026 CU_BEGIN_DECLARATIONS 00027 /** \defgroup cu_wchar_h cu/wchar.h: Unicode Characters 00028 ** @{ \ingroup cu_type_mod */ 00029 00030 /** A unicode character. This is defined as \c wchar_t if the compiler defines 00031 ** \c __STDC_ISO_10646__ and \c wchar_t is wide enough to hold characters 00032 ** beyond the BMP. Otherwise, a 32 bit integer type is used. */ 00033 #if defined(__STDC_ISO_10646__) && WCHAR_MAX >= 0x10ffff 00034 typedef wchar_t cu_wchar_t; 00035 typedef wint_t cu_wint_t; 00036 #define CU_WCHAR_IS_STDC 1 00037 #define CU_WCHAR_WIDTH CUCONF_WIDTHOF_WCHAR_T 00038 #else 00039 typedef uint32_t cu_wchar_t; 00040 typedef unsigned int cu_wint_t; 00041 #define CU_WCHAR_WIDTH 32 00042 #endif 00043 /** The maximum number of \c char elements needed to represent a \ref 00044 ** cu_wchar_t. */ 00045 #define CU_MAX_MBLEN 4 00046 00047 #ifndef CU_WCHAR_IS_STDC 00048 size_t cu_wcslen(cu_wchar_t const *s); 00049 int cu_wcscmp(cu_wchar_t const *s0, cu_wchar_t const *s1); 00050 int cu_wcsncmp(cu_wchar_t const *s0, cu_wchar_t const *s1, size_t n); 00051 #else 00052 # define cu_wcslen wcslen 00053 # define cu_wcscmp wcscmp 00054 # define cu_wcsncmp wcsncmp 00055 #endif 00056 00057 /** A thread-local \c iconv_t descriptor for converting from \ref cu_wchar_t 00058 ** strings to \c char strings. */ 00059 iconv_t cu_iconv_for_wchar_to_char(void); 00060 00061 /** A thread-local \c iconv_t descriptor for converting from \c char strings to 00062 ** \ref cu_wchar_t strings. */ 00063 iconv_t cu_iconv_for_char_to_wchar(void); 00064 00065 /** The name of the encoding used for \c cu_wchar_t, as suitable for passing to 00066 ** \c iconv_open. This is wide character encoding with Unicode compatible 00067 ** code-points and endianness according to the platform. The encoding is wide 00068 ** enough to hold Unicode characters beyond BMP. \see cu_wchar_t. */ 00069 extern char const *cu_wchar_encoding; 00070 00071 /** True if \a enc is the name of a character encoding known to be binary 00072 ** compatible with and array of \c cu_wchar_t. Conversely, a false return does 00073 ** not guarantee that the encoding is incompatible. */ 00074 cu_bool_t cu_encoding_is_wchar_compat(char const *enc); 00075 00076 /** @} */ 00077 CU_END_DECLARATIONS 00078 00079 #endif