Back to index

lightning-sunbird  0.9+nobinonly
unistring.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is lineterm.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Ramalingam Saravanan.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /* unistring.h: Unicode string operations header
00038  * (used by lineterm.h)
00039  * CPP options:
00040  *   USE_WCHAR:   use system wchar implementation, rather than unsigned short
00041  *   HAVE_WCSSTR: use wcsstr rather than wcswcs (used for wchar only)
00042  */
00043 
00044 #ifndef _UNISTRING_H
00045 
00046 #define _UNISTRING_H   1
00047 
00048 #ifdef  __cplusplus
00049 extern "C" {
00050 #endif
00051 
00052 /* Standard C header files */
00053 #include <stdio.h>
00054 
00055 /* Unicode character type:
00056  * Use either the wchar_t implementation or unsigned short
00057  */
00058 
00059 #ifdef USE_WCHAR
00060 #include <wchar.h>
00061 typedef wchar_t UNICHAR;
00062 #else /* !USE_WCHAR */
00063 typedef unsigned short UNICHAR;
00064 #endif
00065 
00066 /* Unicode string functions:
00067  * use the wchar_t implementation for moment
00068  */
00069 
00074 void ucstoutf8(const UNICHAR* us, int nus, char* s, int ns, 
00075                int* remaining, int* encoded);
00076 
00084 int utf8toucs(const char* s, int ns, UNICHAR* us, int nus,
00085               int skipNUL, int* remaining, int* decoded);
00086 
00090 void ucsprint(FILE* stream, const UNICHAR* us, int nus);
00091 
00096 UNICHAR* ucscopy(UNICHAR* dest, const char* srcplain, size_t n);
00097 
00098 #ifdef USE_WCHAR
00099 
00100 #define ucscpy    wcscpy
00101 #define ucsncpy   wcsncpy
00102 
00103 #define ucscat    wcscat
00104 #define ucsncat   wcsncat
00105 
00106 #define ucscmp    wcscmp
00107 #define ucsncmp   wcsncmp
00108 
00109 #define ucschr    wcschr
00110 #define ucsrchr   wcsrchr
00111 
00112 #define ucsspn    wcsspn
00113 #define ucscspn   wcscspn
00114 
00115 #define ucspbrk   wcspbrk
00116 
00117 #ifdef HAVE_WCSSTR
00118 #define ucsstr    wcsstr
00119 #else
00120 #define ucsstr    wcswcs
00121 #endif
00122 
00123 #define ucslen    wcslen
00124 
00125 #define ucstok    wcstok
00126 
00127 #else /* !USE_WCHAR */
00128 
00131 UNICHAR* ucschr(const UNICHAR* str, const UNICHAR chr);
00132 
00136 UNICHAR* ucsrchr(const UNICHAR* str, const UNICHAR chr);
00137 
00144 int ucscmp(register const UNICHAR* str1, register const UNICHAR* str2);
00145 
00152 int ucsncmp(const UNICHAR* str1, const UNICHAR* str2,
00153             size_t n);
00154 
00159 UNICHAR* ucsncpy(UNICHAR* dest, const UNICHAR* src,
00160                  size_t n);
00161 
00164 size_t ucslen(const UNICHAR* str);
00165 
00170 UNICHAR* ucsstr(const UNICHAR* str, const UNICHAR* substr);
00171 
00175 size_t ucsspn(const UNICHAR* str, const UNICHAR* chars);
00176     
00180 size_t ucscspn(const UNICHAR* str, const UNICHAR* chars);
00181 
00182 #endif  /* !USE_WCHAR */
00183 
00184 /* unsigned short constants */
00185 #define U_NUL         0x00U
00186 
00187 #define U_CTL_A       0x01U
00188 #define U_CTL_B       0x02U
00189 #define U_CTL_C       0x03U
00190 #define U_CTL_D       0x04U
00191 #define U_CTL_E       0x05U
00192 #define U_CTL_F       0x06U
00193 
00194 #define U_BEL         0x07U      /* ^G */
00195 #define U_BACKSPACE   0x08U      /* ^H */
00196 #define U_TAB         0x09U      /* ^I */
00197 #define U_LINEFEED    0x0AU      /* ^J */
00198 
00199 #define U_CTL_K       0x0BU
00200 #define U_CTL_L       0x0CU
00201 
00202 #define U_CRETURN     0x0DU      /* ^M */
00203 
00204 #define U_CTL_N       0x0EU
00205 #define U_CTL_O       0x0FU
00206 #define U_CTL_P       0x10U
00207 #define U_CTL_Q       0x11U
00208 #define U_CTL_R       0x12U
00209 #define U_CTL_S       0x13U
00210 #define U_CTL_T       0x14U
00211 #define U_CTL_U       0x15U
00212 #define U_CTL_V       0x16U
00213 #define U_CTL_W       0x17U
00214 #define U_CTL_X       0x18U
00215 #define U_CTL_Y       0x19U
00216 #define U_CTL_Z       0x1AU
00217 
00218 #define U_ESCAPE      0x1BU      /* escape */
00219 
00220 #define U_SPACE       0x20U      /* space */
00221 #define U_EXCLAMATION 0x21U      /* ! */
00222 #define U_DBLQUOTE    0x22U      /* " */
00223 #define U_NUMBER      0x23U      /* # */
00224 #define U_DOLLAR      0x24U      /* $ */
00225 #define U_PERCENT     0x25U      /* % */
00226 #define U_AMPERSAND   0x26U      /* & */
00227 #define U_SNGLQUOTE   0x27U      /* ' */
00228 #define U_LPAREN      0x28U      /* ( */
00229 #define U_RPAREN      0x29U      /* ) */
00230 
00231 #define U_STAR        0x2AU      /* * */
00232 #define U_PLUS        0x2BU      /* + */
00233 #define U_COMMA       0x2CU      /* , */
00234 #define U_DASH        0x2DU      /* - */
00235 #define U_PERIOD      0x2EU      /* . */
00236 #define U_SLASH       0x2FU      /* / */
00237 
00238 #define U_ZERO        0x30U      /* 0 */
00239 #define U_ONE         0x31U      /* 1 */
00240 #define U_TWO         0x32U      /* 2 */
00241 #define U_THREE       0x33U      /* 3 */
00242 #define U_FOUR        0x34U      /* 4 */
00243 #define U_FIVE        0x35U      /* 5 */
00244 #define U_SIX         0x36U      /* 6 */
00245 #define U_SEVEN       0x37U      /* 7 */
00246 #define U_EIGHT       0x38U      /* 8 */
00247 #define U_NINE        0x39U      /* 9 */
00248 
00249 #define U_COLON       0x3AU      /* : */
00250 #define U_SEMICOLON   0x3BU      /* ; */
00251 #define U_LESSTHAN    0x3CU      /* < */
00252 #define U_EQUALS      0x3DU      /* = */
00253 #define U_GREATERTHAN 0x3EU      /* > */
00254 #define U_QUERYMARK   0x3FU      /* ? */
00255 
00256 #define U_ATSIGN      0x40U      /* @ */
00257 
00258 #define U_A_CHAR      0x41U      /* A */
00259 #define U_B_CHAR      0x42U      /* B */
00260 #define U_C_CHAR      0x43U      /* C */
00261 #define U_D_CHAR      0x44U      /* D */
00262 #define U_E_CHAR      0x45U      /* E */
00263 #define U_F_CHAR      0x46U      /* F */
00264 #define U_G_CHAR      0x47U      /* G */
00265 #define U_H_CHAR      0x48U      /* H */
00266 #define U_I_CHAR      0x49U      /* I */
00267 #define U_J_CHAR      0x4AU      /* J */
00268 #define U_K_CHAR      0x4BU      /* K */
00269 #define U_L_CHAR      0x4CU      /* L */
00270 #define U_M_CHAR      0x4DU      /* M */
00271 #define U_N_CHAR      0x4EU      /* N */
00272 #define U_O_CHAR      0x4FU      /* O */
00273 #define U_P_CHAR      0x50U      /* P */
00274 #define U_Q_CHAR      0x51U      /* Q */
00275 #define U_R_CHAR      0x52U      /* R */
00276 #define U_S_CHAR      0x53U      /* S */
00277 #define U_T_CHAR      0x54U      /* T */
00278 #define U_U_CHAR      0x55U      /* U */
00279 #define U_V_CHAR      0x56U      /* V */
00280 #define U_W_CHAR      0x57U      /* W */
00281 #define U_X_CHAR      0x58U      /* X */
00282 #define U_Y_CHAR      0x59U      /* Y */
00283 #define U_Z_CHAR      0x5AU      /* Z */
00284 
00285 #define U_LBRACKET    0x5BU      /* [ */
00286 #define U_BACKSLASH   0x5CU      /* \ */
00287 #define U_RBRACKET    0x5DU      /* ] */
00288 
00289 #define U_CARET       0x5EU      /* ^ */
00290 #define U_UNDERSCORE  0x5FU      /* _ */
00291 #define U_BACKQUOTE   0x60U      /* ` */
00292 
00293 #define U_a_CHAR      0x61U      /* a */
00294 #define U_b_CHAR      0x62U      /* b */
00295 #define U_c_CHAR      0x63U      /* c */
00296 #define U_d_CHAR      0x64U      /* d */
00297 #define U_e_CHAR      0x65U      /* e */
00298 #define U_f_CHAR      0x66U      /* f */
00299 #define U_g_CHAR      0x67U      /* g */
00300 #define U_h_CHAR      0x68U      /* h */
00301 #define U_i_CHAR      0x69U      /* i */
00302 #define U_j_CHAR      0x6AU      /* j */
00303 #define U_k_CHAR      0x6BU      /* k */
00304 #define U_l_CHAR      0x6CU      /* l */
00305 #define U_m_CHAR      0x6DU      /* m */
00306 #define U_n_CHAR      0x6EU      /* n */
00307 #define U_o_CHAR      0x6FU      /* o */
00308 #define U_p_CHAR      0x70U      /* p */
00309 #define U_q_CHAR      0x71U      /* q */
00310 #define U_r_CHAR      0x72U      /* r */
00311 #define U_s_CHAR      0x73U      /* s */
00312 #define U_t_CHAR      0x74U      /* t */
00313 #define U_u_CHAR      0x75U      /* u */
00314 #define U_v_CHAR      0x76U      /* v */
00315 #define U_w_CHAR      0x77U      /* w */
00316 #define U_x_CHAR      0x78U      /* x */
00317 #define U_y_CHAR      0x79U      /* y */
00318 #define U_z_CHAR      0x7AU      /* z */
00319 
00320 #define U_LCURLY      0x7BU      /* { */
00321 #define U_VERTBAR     0x7CU      /* | */
00322 #define U_RCURLY      0x7DU      /* } */
00323 
00324 #define U_TILDE       0x7EU      /* ~ */
00325 #define U_DEL         0x7FU      /* delete */
00326 
00327 #define U_LATIN1LO    0xA0U      /* lowest Latin1 extension character */
00328 #define U_NOBRKSPACE  0xA0U      /* no-break space */
00329 #define U_LATIN1HI    0xFFU      /* highest Latin1 extension character */
00330 
00331 #define U_PRIVATE0    0xE000U    /* first private use Unicode character */
00332 
00333 #define IS_ASCII_LETTER(x) ( (((x) >= (UNICHAR)U_A_CHAR) &&  \
00334                               ((x) <= (UNICHAR)U_Z_CHAR)) || \
00335                              (((x) >= (UNICHAR)U_a_CHAR) &&  \
00336                               ((x) <= (UNICHAR)U_z_CHAR)) )
00337 
00338 #define IS_ASCII_DIGIT(x)  ( ((x) >= (UNICHAR)U_ZERO) && \
00339                              ((x) <= (UNICHAR)U_NINE) )
00340 
00341 
00342 #ifdef  __cplusplus
00343 }
00344 #endif
00345 
00346 #endif /* _UNISTRING_H */