1 /* $Id: ucsset.h,v 1.1 2003/06/04 00:25:43 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_UCSSET_H 45 #define IDN_UCSSET_H 1 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 /* 52 * A 'set' of UCS codepoints. 53 */ 54 55 #include <idn/export.h> 56 #include <idn/result.h> 57 58 /* 59 * Type representing a set (opaque). 60 */ 61 typedef struct idn_ucsset *idn_ucsset_t; 62 63 64 /* 65 * Create an empty set. The reference count is set to 1. 66 * 67 * Returns: 68 * idn_success -- ok. 69 * idn_nomemory -- malloc failed. 70 */ 71 IDN_EXPORT idn_result_t 72 idn_ucsset_create(idn_ucsset_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 */ 78 IDN_EXPORT void 79 idn_ucsset_destroy(idn_ucsset_t ctx); 80 81 /* 82 * Increments the reference count by one. 83 */ 84 IDN_EXPORT void 85 idn_ucsset_incrref(idn_ucsset_t ctx); 86 87 /* 88 * Add a UCS code point to the set. 89 * The set must be in the building phase -- that is, before 'idn_ucsset_fix' 90 * is called for the set. 91 * 92 * Returns: 93 * idn_success -- ok. 94 * idn_invalid_code -- code point out of range. 95 * idn_nomemory -- malloc failed. 96 * idn_failure -- already fixed by 'idn_ucsset_fix'. 97 */ 98 IDN_EXPORT idn_result_t 99 idn_ucsset_add(idn_ucsset_t ctx, unsigned long v); 100 101 /* 102 * Add a range of code points (from 'from' to 'to', inclusive) to the set. 103 * 'from' must not be greater than 'to'. 104 * This function is similar to 'idn_ucsset_add' except that it accepts 105 * range of code points. 106 * 107 * Returns: 108 * idn_success -- ok. 109 * idn_invalid_code -- code point out of range, or the range 110 * specification is invalid. 111 * idn_nomemory -- malloc failed. 112 * idn_failure -- already fixed by 'idn_ucsset_fix'. 113 */ 114 IDN_EXPORT idn_result_t 115 idn_ucsset_addrange(idn_ucsset_t ctx, unsigned long from, unsigned long to); 116 117 /* 118 * Perform internal arrangement of the set for lookup. 119 * Before calling this function, a set is in 'building' phase, and code 120 * points can be added freely by 'idn_ucsset_add' or 'idn_ucsset_addrange'. 121 * But once it is fixed by this function, the set becomes immutable, and 122 * it shifts into 'lookup' phase. 123 */ 124 IDN_EXPORT void 125 idn_ucsset_fix(idn_ucsset_t ctx); 126 127 /* 128 * Find if the given code point is in the set. 129 * The set must be in the lookup phase -- in other words, 'idn_ucsset_fix' 130 * must be called for the set before calling this function. 131 * '*found' is set to 1 if the specified code point is in the set, 0 otherwise. 132 * 133 * Returns: 134 * idn_success -- ok. 135 * idn_invalid_code -- specified code point is out of range. 136 * idn_failure -- not fixed by 'idn_ucsset_fix' yet. 137 */ 138 IDN_EXPORT idn_result_t 139 idn_ucsset_lookup(idn_ucsset_t ctx, unsigned long v, int *found); 140 141 #ifdef __cplusplus 142 } 143 #endif 144 145 #endif /* IDN_UCSSET_H */ 146