1 /* $NetBSD: citrus_stdenc.h,v 1.4 2005/10/29 18:02:04 tshiozak Exp $ */
4 * Copyright (c)2003 Citrus Project,
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
30 #ifndef _CITRUS_STDENC_H_
31 #define _CITRUS_STDENC_H_
33 struct _citrus_stdenc
;
34 struct _citrus_stdenc_ops
;
35 struct _citrus_stdenc_traits
;
37 #define _CITRUS_STDENC_SDID_GENERIC 0
38 struct _citrus_stdenc_state_desc
43 #define _CITRUS_STDENC_SDGEN_UNKNOWN 0
44 #define _CITRUS_STDENC_SDGEN_INITIAL 1
45 #define _CITRUS_STDENC_SDGEN_STABLE 2
46 #define _CITRUS_STDENC_SDGEN_INCOMPLETE_CHAR 3
47 #define _CITRUS_STDENC_SDGEN_INCOMPLETE_SHIFT 4
52 #include "citrus_stdenc_local.h"
55 int _citrus_stdenc_open(struct _citrus_stdenc
* __restrict
* __restrict
,
56 char const * __restrict
,
57 const void * __restrict
, size_t);
58 void _citrus_stdenc_close(struct _citrus_stdenc
*);
62 _citrus_stdenc_init_state(struct _citrus_stdenc
* __restrict ce
,
65 _DIAGASSERT(ce
&& ce
->ce_ops
&& ce
->ce_ops
->eo_init_state
);
66 return (*ce
->ce_ops
->eo_init_state
)(ce
, ps
);
70 _citrus_stdenc_mbtocs(struct _citrus_stdenc
* __restrict ce
,
71 _citrus_csid_t
* __restrict csid
,
72 _citrus_index_t
* __restrict idx
,
73 const char ** __restrict s
, size_t n
,
74 void * __restrict ps
, size_t * __restrict nresult
)
76 _DIAGASSERT(ce
&& ce
->ce_ops
&& ce
->ce_ops
->eo_mbtocs
);
77 return (*ce
->ce_ops
->eo_mbtocs
)(ce
, csid
, idx
, s
, n
, ps
, nresult
);
81 _citrus_stdenc_cstomb(struct _citrus_stdenc
* __restrict ce
,
82 char * __restrict s
, size_t n
,
83 _citrus_csid_t csid
, _citrus_index_t idx
,
84 void * __restrict ps
, size_t * __restrict nresult
)
86 _DIAGASSERT(ce
&& ce
->ce_ops
&& ce
->ce_ops
->eo_cstomb
);
87 return (*ce
->ce_ops
->eo_cstomb
)(ce
, s
, n
, csid
, idx
, ps
, nresult
);
91 _citrus_stdenc_mbtowc(struct _citrus_stdenc
* __restrict ce
,
92 _citrus_wc_t
* __restrict wc
,
93 const char ** __restrict s
, size_t n
,
94 void * __restrict ps
, size_t * __restrict nresult
)
96 _DIAGASSERT(ce
&& ce
->ce_ops
&& ce
->ce_ops
->eo_mbtocs
);
97 return (*ce
->ce_ops
->eo_mbtowc
)(ce
, wc
, s
, n
, ps
, nresult
);
101 _citrus_stdenc_wctomb(struct _citrus_stdenc
* __restrict ce
,
102 char * __restrict s
, size_t n
, _citrus_wc_t wc
,
103 void * __restrict ps
, size_t * __restrict nresult
)
105 _DIAGASSERT(ce
&& ce
->ce_ops
&& ce
->ce_ops
->eo_cstomb
);
106 return (*ce
->ce_ops
->eo_wctomb
)(ce
, s
, n
, wc
, ps
, nresult
);
110 _citrus_stdenc_put_state_reset(struct _citrus_stdenc
* __restrict ce
,
111 char * __restrict s
, size_t n
,
112 void * __restrict ps
,
113 size_t * __restrict nresult
)
115 _DIAGASSERT(ce
&& ce
->ce_ops
&& ce
->ce_ops
->eo_put_state_reset
);
116 return (*ce
->ce_ops
->eo_put_state_reset
)(ce
, s
, n
, ps
, nresult
);
119 static __inline
size_t
120 _citrus_stdenc_get_state_size(struct _citrus_stdenc
*ce
)
122 _DIAGASSERT(ce
&& ce
->ce_traits
);
123 return ce
->ce_traits
->et_state_size
;
126 static __inline
size_t
127 _citrus_stdenc_get_mb_cur_max(struct _citrus_stdenc
*ce
)
129 _DIAGASSERT(ce
&& ce
->ce_traits
);
130 return ce
->ce_traits
->et_mb_cur_max
;
134 _citrus_stdenc_get_state_desc(struct _citrus_stdenc
* __restrict ce
,
135 void * __restrict ps
,
137 struct _citrus_stdenc_state_desc
* __restrict d
)
140 _DIAGASSERT(ce
&& ce
->ce_ops
&& ce
->ce_ops
->eo_get_state_desc
);
142 return (*ce
->ce_ops
->eo_get_state_desc
)(ce
, ps
, id
, d
);