1 /*	$NetBSD: unicode.h,v 1.4 2014/12/10 04:37:55 christos Exp $	*/
2 
3 /* Id: unicode.h,v 1.1 2003/06/04 00:25:43 marka Exp  */
4 /*
5  * Copyright (c) 2000,2001 Japan Network Information Center.
6  * All rights reserved.
7  *
8  * By using this file, you agree to the terms and conditions set forth bellow.
9  *
10  * 			LICENSE TERMS AND CONDITIONS
11  *
12  * The following License Terms and Conditions apply, unless a different
13  * license is obtained from Japan Network Information Center ("JPNIC"),
14  * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
15  * Chiyoda-ku, Tokyo 101-0047, Japan.
16  *
17  * 1. Use, Modification and Redistribution (including distribution of any
18  *    modified or derived work) in source and/or binary forms is permitted
19  *    under this License Terms and Conditions.
20  *
21  * 2. Redistribution of source code must retain the copyright notices as they
22  *    appear in each source code file, this License Terms and Conditions.
23  *
24  * 3. Redistribution in binary form must reproduce the Copyright Notice,
25  *    this License Terms and Conditions, in the documentation and/or other
26  *    materials provided with the distribution.  For the purposes of binary
27  *    distribution the "Copyright Notice" refers to the following language:
28  *    "Copyright (c) 2000-2002 Japan Network Information Center.  All rights reserved."
29  *
30  * 4. The name of JPNIC may not be used to endorse or promote products
31  *    derived from this Software without specific prior written approval of
32  *    JPNIC.
33  *
34  * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
35  *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36  *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
37  *    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL JPNIC BE LIABLE
38  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41  *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42  *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
43  *    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
44  *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
45  */
46 
47 #ifndef IDN_UNICODE_H
48 #define IDN_UNICODE_H 1
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /*
55  * Unicode attributes retriever.
56  *
57  * All the information this module provides is based on UnicodeData.txt,
58  * CompositionExclusions-1.txt and SpecialCasing.txt, all of which can be
59  * obtained from unicode.org.
60  *
61  * Unicode characters are represented as 'unsigned long'.
62  */
63 
64 #include <idn/result.h>
65 
66 /*
67  * A Handle for Unicode versions.
68  */
69 typedef struct idn__unicode_ops *idn__unicode_version_t;
70 
71 /*
72  * Context information for case conversion.
73  */
74 typedef enum {
75 	idn__unicode_context_unknown,
76 	idn__unicode_context_final,
77 	idn__unicode_context_nonfinal
78 } idn__unicode_context_t;
79 
80 /*
81  * Create a handle for a specific Unicode version.
82  * The version number (such as "3.0.1") is specified by 'version' parameter.
83  * If it is NULL, the latest version is used.
84  * The handle is stored in '*versionp', which is used various functions
85  * in this and unormalize modules.
86  *
87  * Returns:
88  *	idn_success		-- ok.
89  *	idn_notfound		-- specified version not found.
90  */
91 extern idn_result_t
92 idn__unicode_create(const char *version, idn__unicode_version_t *versionp);
93 
94 /*
95  * Close a handle which was created by 'idn__unicode_create'.
96  */
97 extern void
98 idn__unicode_destroy(idn__unicode_version_t version);
99 
100 /*
101  * Get canonical class.
102  *
103  * For characters out of unicode range (i.e. above 0xffff), 0 will
104  * be returned.
105  */
106 extern int
107 idn__unicode_canonicalclass(idn__unicode_version_t version, unsigned long c);
108 
109 /*
110  * Decompose a character.
111  *
112  * Decompose character given by 'c', and put the result into 'v',
113  * which can hold 'vlen' characters.  The number of decomposed characters
114  * will be stored in '*decomp_lenp'.
115  *
116  * If 'compat' is true, compatibility decomposition is performed.
117  * Otherwise canonical decomposition is done.
118  *
119  * Since decomposition is done recursively, no further decomposition
120  * will be needed.
121  *
122  * Returns:
123  *	idn_success		-- ok, decomposed.
124  *	idn_notfound		-- no decomposition possible.
125  *	idn_buffer_overflow	-- 'vlen' is too small.
126  */
127 extern idn_result_t
128 idn__unicode_decompose(idn__unicode_version_t version,
129 		       int compat, unsigned long *v, size_t vlen,
130 		       unsigned long c, int *decomp_lenp);
131 
132 /*
133  * Perform canonical composition.
134  *
135  * Do canonical composition to the character sequence 'c1' and 'c2', put the
136  * result into '*compp'.
137  *
138  * Since Unicode Nomalization Froms requires only canonical composition,
139  * compatibility composition is not supported.
140  *
141  * Returns:
142  *	idn_success		-- ok, composed.
143  *	idn_notfound		-- no composition possible.
144  */
145 extern idn_result_t
146 idn__unicode_compose(idn__unicode_version_t version,
147 		     unsigned long c1, unsigned long c2, unsigned long *compp);
148 
149 /*
150  * Returns if there may be a canonical composition sequence which starts
151  * with the given character.
152  *
153  * Returns:
154  *	1			-- there may be a composition sequence
155  *				   (maybe not).
156  *	0			-- no, there is definitely no such sequences.
157  */
158 extern int
159 idn__unicode_iscompositecandidate(idn__unicode_version_t version,
160 				  unsigned long c);
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif /* IDN_UNICODE_H */
167