Home | History | Annotate | Line # | Download | only in citrus
      1 /*	$NetBSD: citrus_ctype.h,v 1.3 2013/05/28 16:57:56 joerg Exp $	*/
      2 
      3 /*-
      4  * Copyright (c)2002 Citrus Project,
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  *
     28  */
     29 
     30 #ifndef _CITRUS_CTYPE_H_
     31 #define _CITRUS_CTYPE_H_
     32 
     33 #include "citrus_ctype_local.h"
     34 
     35 typedef struct _citrus_ctype_rec *_citrus_ctype_t;
     36 
     37 __BEGIN_DECLS
     38 int _citrus_ctype_open(_citrus_ctype_t * __restrict,
     39 		       char const * __restrict, void * __restrict,
     40 		       size_t, size_t);
     41 void _citrus_ctype_close(_citrus_ctype_t);
     42 __END_DECLS
     43 
     44 static __inline unsigned
     45 _citrus_ctype_get_mb_cur_max(_citrus_ctype_t cc)
     46 {
     47 
     48 	_DIAGASSERT(cc && cc->cc_ops);
     49 	return (*cc->cc_ops->co_get_mb_cur_max)(cc->cc_closure);
     50 }
     51 
     52 static __inline int
     53 _citrus_ctype_mblen(_citrus_ctype_t cc, const char *s, size_t n, int *nresult)
     54 {
     55 
     56 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mblen && nresult);
     57 	return (*cc->cc_ops->co_mblen)(cc->cc_closure, s, n, nresult);
     58 }
     59 
     60 static __inline int
     61 _citrus_ctype_mbrlen(_citrus_ctype_t cc, const char *s, size_t n,
     62 		     void *pspriv, size_t *nresult)
     63 {
     64 
     65 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbrlen && nresult);
     66 	return (*cc->cc_ops->co_mbrlen)(cc->cc_closure, s, n, pspriv, nresult);
     67 }
     68 
     69 static __inline int
     70 _citrus_ctype_mbrtowc(_citrus_ctype_t cc, wchar_t *pwc, const char *s,
     71 		      size_t n, void *pspriv, size_t *nresult)
     72 {
     73 
     74 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbrtowc);
     75 	return (*cc->cc_ops->co_mbrtowc)(cc->cc_closure, pwc, s, n, pspriv,
     76 					 nresult);
     77 }
     78 
     79 static __inline int
     80 _citrus_ctype_mbsinit(_citrus_ctype_t cc, void const *pspriv, int *nresult)
     81 {
     82 
     83 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbsinit && nresult);
     84 	return (*cc->cc_ops->co_mbsinit)(cc->cc_closure, pspriv, nresult);
     85 }
     86 
     87 static __inline int
     88 _citrus_ctype_mbsrtowcs(_citrus_ctype_t cc, wchar_t *pwcs, const char **s,
     89 			size_t n, void *pspriv, size_t *nresult)
     90 {
     91 
     92 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbsrtowcs && nresult);
     93 	return (*cc->cc_ops->co_mbsrtowcs)(cc->cc_closure, pwcs, s, n, pspriv,
     94 					   nresult);
     95 }
     96 
     97 static __inline int
     98 _citrus_ctype_mbsnrtowcs(_citrus_ctype_t cc, wchar_t *pwcs, const char **s,
     99 			size_t in, size_t n, void *pspriv, size_t *nresult)
    100 {
    101 
    102 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbsnrtowcs && nresult);
    103 	return (*cc->cc_ops->co_mbsnrtowcs)(cc, pwcs, s, in, n,
    104 					   pspriv, nresult);
    105 }
    106 
    107 static __inline int
    108 _citrus_ctype_mbstowcs(_citrus_ctype_t cc, wchar_t *pwcs, const char *s,
    109 		       size_t n, size_t *nresult)
    110 {
    111 
    112 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbstowcs && nresult);
    113 	return (*cc->cc_ops->co_mbstowcs)(cc->cc_closure, pwcs, s, n, nresult);
    114 }
    115 
    116 static __inline int
    117 _citrus_ctype_mbtowc(_citrus_ctype_t cc, wchar_t *pw, const char *s, size_t n,
    118 		     int *nresult)
    119 {
    120 
    121 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbtowc && nresult);
    122 	return (*cc->cc_ops->co_mbtowc)(cc->cc_closure, pw, s, n, nresult);
    123 }
    124 
    125 static __inline int
    126 _citrus_ctype_wcrtomb(_citrus_ctype_t cc, char *s, wchar_t wc,
    127 		      void *pspriv, size_t *nresult)
    128 {
    129 
    130 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wcrtomb && nresult);
    131 	return (*cc->cc_ops->co_wcrtomb)(cc->cc_closure, s, wc, pspriv,
    132 					 nresult);
    133 }
    134 
    135 static __inline int
    136 _citrus_ctype_wcsrtombs(_citrus_ctype_t cc, char *s, const wchar_t **ppwcs,
    137 			size_t n, void *pspriv, size_t *nresult)
    138 {
    139 
    140 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wcsrtombs && nresult);
    141 	return (*cc->cc_ops->co_wcsrtombs)(cc->cc_closure, s, ppwcs, n,
    142 					   pspriv, nresult);
    143 }
    144 
    145 static __inline int
    146 _citrus_ctype_wcsnrtombs(_citrus_ctype_t cc, char *s, const wchar_t **ppwcs,
    147 			size_t in, size_t n, void *pspriv, size_t *nresult)
    148 {
    149 
    150 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wcsnrtombs && nresult);
    151 	return (*cc->cc_ops->co_wcsnrtombs)(cc, s, ppwcs, in, n,
    152 					   pspriv, nresult);
    153 }
    154 
    155 static __inline int
    156 _citrus_ctype_wcstombs(_citrus_ctype_t cc, char *s, const wchar_t *wcs,
    157 		       size_t n, size_t *nresult)
    158 {
    159 
    160 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wcstombs && nresult);
    161 	return (*cc->cc_ops->co_wcstombs)(cc->cc_closure, s, wcs, n, nresult);
    162 }
    163 
    164 static __inline int
    165 _citrus_ctype_wctomb(_citrus_ctype_t cc, char *s, wchar_t wc, int *nresult)
    166 {
    167 
    168 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wctomb && nresult);
    169 	return (*cc->cc_ops->co_wctomb)(cc->cc_closure, s, wc, nresult);
    170 }
    171 
    172 static __inline int
    173 _citrus_ctype_btowc(_citrus_ctype_t cc, int c, wint_t *wcresult)
    174 {
    175 
    176 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_btowc && wcresult);
    177 	return (*cc->cc_ops->co_btowc)(cc, c, wcresult);
    178 }
    179 
    180 static __inline int
    181 _citrus_ctype_wctob(_citrus_ctype_t cc, wint_t c, int *cresult)
    182 {
    183 
    184 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wctob && cresult);
    185 	return (*cc->cc_ops->co_wctob)(cc, c, cresult);
    186 }
    187 
    188 extern _citrus_ctype_rec_t _citrus_ctype_default;
    189 
    190 #endif
    191