1/* $Id: ucsmap.h,v 1.1 2003/06/04 00:25:42 marka Exp $ */
2/*
3 * Copyright (c) 2001 Japan Network Information Center.  All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set forth bellow.
6 *
7 * 			LICENSE TERMS AND CONDITIONS
8 *
9 * The following License Terms and Conditions apply, unless a different
10 * license is obtained from Japan Network Information Center ("JPNIC"),
11 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
12 * Chiyoda-ku, Tokyo 101-0047, Japan.
13 *
14 * 1. Use, Modification and Redistribution (including distribution of any
15 *    modified or derived work) in source and/or binary forms is permitted
16 *    under this License Terms and Conditions.
17 *
18 * 2. Redistribution of source code must retain the copyright notices as they
19 *    appear in each source code file, this License Terms and Conditions.
20 *
21 * 3. Redistribution in binary form must reproduce the Copyright Notice,
22 *    this License Terms and Conditions, in the documentation and/or other
23 *    materials provided with the distribution.  For the purposes of binary
24 *    distribution the "Copyright Notice" refers to the following language:
25 *    "Copyright (c) 2000-2002 Japan Network Information Center.  All rights reserved."
26 *
27 * 4. The name of JPNIC may not be used to endorse or promote products
28 *    derived from this Software without specific prior written approval of
29 *    JPNIC.
30 *
31 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
32 *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
34 *    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL JPNIC BE LIABLE
35 *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 *    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#ifndef IDN_UCSMAP_H
45#define IDN_UCSMAP_H 1
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/*
52 * Perform UCS character mapping.
53 * This module support one-to-N mapping (N may be zero, one or more).
54 */
55
56#include <idn/export.h>
57#include <idn/result.h>
58
59/*
60 * Mapper type (opaque).
61 */
62typedef struct idn_ucsmap *idn_ucsmap_t;
63
64/*
65 * Create an empty mapping.  The reference count is set to 1.
66 *
67 * Returns:
68 *	idn_success		-- ok.
69 *	idn_nomemory		-- malloc failed.
70 */
71IDN_EXPORT idn_result_t
72idn_ucsmap_create(idn_ucsmap_t *ctxp);
73
74/*
75 * Decrement the reference count of the given set, and if it reaches zero,
76 * release all the memory allocated for it.
77 */
78IDN_EXPORT void
79idn_ucsmap_destroy(idn_ucsmap_t ctx);
80
81/*
82 * Increment the reference count of the given set by one, so that
83 * the map can be shared.
84 */
85IDN_EXPORT void
86idn_ucsmap_incrref(idn_ucsmap_t ctx);
87
88/*
89 * Add a mapping.
90 * 'ucs' is the character to be mapped, 'map' points an array of mapped
91 * characters of length 'maplen'.  'map' may be NULL if 'maplen' is zero,
92 * meaning one-to-none mapping.
93 *
94 * Returns:
95 *	idn_success		-- ok.
96 *	idn_nomemory		-- malloc failed.
97 *	idn_failure		-- already fixed by 'idn_ucsmap_fix',
98 *				   or too large maplen.
99 */
100IDN_EXPORT idn_result_t
101idn_ucsmap_add(idn_ucsmap_t ctx, unsigned long ucs, unsigned long *map,
102	       size_t maplen);
103
104/*
105 * Perform internal arrangement of the map for lookup.
106 * Once it is fixed, 'idn_ucsmap_add' cannot be permitted to the map.
107 */
108IDN_EXPORT void
109idn_ucsmap_fix(idn_ucsmap_t ctx);
110
111/*
112 * Find the mapping for the given character.
113 * 'idn_ucsmap_fix' must be performed before calling this function.
114 * Find the mapping for 'v' and store the result to 'to'.  The length
115 * of the mapped sequence is stored in '*maplenp'.  'tolen' specifies
116 * the length allocated for 'to'.
117 *
118 * Returns:
119 *	idn_success		-- ok.
120 *	idn_nomapping		-- specified character has no mapping.
121 *	idn_failure		-- not fixed by 'idn_ucsmap_fix' yet.
122 */
123IDN_EXPORT idn_result_t
124idn_ucsmap_map(idn_ucsmap_t ctx, unsigned long v, unsigned long *to,
125	       size_t tolen, size_t *maplenp);
126
127#ifdef __cplusplus
128}
129#endif
130
131#endif /* IDN_UCSMAP_H */
132