Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2001 Japan Network Information Center. All rights reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * By using this file, you agree to the terms and conditions set forth bellow. |
michael@0 | 5 | * |
michael@0 | 6 | * LICENSE TERMS AND CONDITIONS |
michael@0 | 7 | * |
michael@0 | 8 | * The following License Terms and Conditions apply, unless a different |
michael@0 | 9 | * license is obtained from Japan Network Information Center ("JPNIC"), |
michael@0 | 10 | * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda, |
michael@0 | 11 | * Chiyoda-ku, Tokyo 101-0047, Japan. |
michael@0 | 12 | * |
michael@0 | 13 | * 1. Use, Modification and Redistribution (including distribution of any |
michael@0 | 14 | * modified or derived work) in source and/or binary forms is permitted |
michael@0 | 15 | * under this License Terms and Conditions. |
michael@0 | 16 | * |
michael@0 | 17 | * 2. Redistribution of source code must retain the copyright notices as they |
michael@0 | 18 | * appear in each source code file, this License Terms and Conditions. |
michael@0 | 19 | * |
michael@0 | 20 | * 3. Redistribution in binary form must reproduce the Copyright Notice, |
michael@0 | 21 | * this License Terms and Conditions, in the documentation and/or other |
michael@0 | 22 | * materials provided with the distribution. For the purposes of binary |
michael@0 | 23 | * distribution the "Copyright Notice" refers to the following language: |
michael@0 | 24 | * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved." |
michael@0 | 25 | * |
michael@0 | 26 | * 4. The name of JPNIC may not be used to endorse or promote products |
michael@0 | 27 | * derived from this Software without specific prior written approval of |
michael@0 | 28 | * JPNIC. |
michael@0 | 29 | * |
michael@0 | 30 | * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC |
michael@0 | 31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
michael@0 | 33 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE |
michael@0 | 34 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
michael@0 | 35 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
michael@0 | 36 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
michael@0 | 37 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
michael@0 | 38 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
michael@0 | 39 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
michael@0 | 40 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
michael@0 | 41 | */ |
michael@0 | 42 | |
michael@0 | 43 | /* |
michael@0 | 44 | * Include this file once for each version of NAMEPREP. |
michael@0 | 45 | * VERSION should be defined to appropriate value before inclusion. |
michael@0 | 46 | */ |
michael@0 | 47 | |
michael@0 | 48 | #ifndef NAMEPREP_TEMPLATE_INIT |
michael@0 | 49 | #define NAMEPREP_TEMPLATE_INIT |
michael@0 | 50 | |
michael@0 | 51 | /* Symbol composition. */ |
michael@0 | 52 | #define compose_sym2(a, b) compose_sym2X(a, b) |
michael@0 | 53 | #define compose_sym2X(a, b) a ## b |
michael@0 | 54 | #define compose_sym3(a, b, c) compose_sym3X(a, b, c) |
michael@0 | 55 | #define compose_sym3X(a, b, c) a ## b ## c |
michael@0 | 56 | |
michael@0 | 57 | /* The table is based on "Optimized Two-Stage Table" mentioned in |
michael@0 | 58 | * Unicode 3.0 page 106, extended to handle 21bit data instead of 16 bit. |
michael@0 | 59 | */ |
michael@0 | 60 | |
michael@0 | 61 | /* Index calculation for multi-level index tables. */ |
michael@0 | 62 | #define IDX0(type, v) IDX_0(v, BITS1(type), BITS2(type)) |
michael@0 | 63 | #define IDX1(type, v) IDX_1(v, BITS1(type), BITS2(type)) |
michael@0 | 64 | #define IDX2(type, v) IDX_2(v, BITS1(type), BITS2(type)) |
michael@0 | 65 | |
michael@0 | 66 | #define IDX_0(v, bits1, bits2) ((v) >> ((bits1) + (bits2))) |
michael@0 | 67 | #define IDX_1(v, bits1, bits2) (((v) >> (bits2)) & ((1 << (bits1)) - 1)) |
michael@0 | 68 | #define IDX_2(v, bits1, bits2) ((v) & ((1 << (bits2)) - 1)) |
michael@0 | 69 | |
michael@0 | 70 | #define BITS1(type) type ## _BITS_1 |
michael@0 | 71 | #define BITS2(type) type ## _BITS_2 |
michael@0 | 72 | |
michael@0 | 73 | #endif /* NAMEPREP_TEMPLATE_INIT */ |
michael@0 | 74 | |
michael@0 | 75 | static const char * |
michael@0 | 76 | compose_sym2(nameprep_map_, VERSION) (uint32_t v) { |
michael@0 | 77 | int idx0 = IDX0(MAP, v); |
michael@0 | 78 | int idx1 = IDX1(MAP, v); |
michael@0 | 79 | int idx2 = IDX2(MAP, v); |
michael@0 | 80 | int offset; |
michael@0 | 81 | |
michael@0 | 82 | #define IMAP compose_sym3(nameprep_, VERSION, _map_imap) |
michael@0 | 83 | #define TABLE compose_sym3(nameprep_, VERSION, _map_table) |
michael@0 | 84 | #define DATA compose_sym3(nameprep_, VERSION, _map_data) |
michael@0 | 85 | offset = TABLE[IMAP[IMAP[idx0] + idx1]].tbl[idx2]; |
michael@0 | 86 | if (offset == 0) |
michael@0 | 87 | return (NULL); /* no mapping */ |
michael@0 | 88 | return (const char *)(DATA + offset); |
michael@0 | 89 | #undef IMAP |
michael@0 | 90 | #undef TABLE |
michael@0 | 91 | #undef DATA |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | static int |
michael@0 | 95 | compose_sym2(nameprep_prohibited_, VERSION) (uint32_t v) { |
michael@0 | 96 | int idx0 = IDX0(PROH, v); |
michael@0 | 97 | int idx1 = IDX1(PROH, v); |
michael@0 | 98 | int idx2 = IDX2(PROH, v); |
michael@0 | 99 | const unsigned char *bm; |
michael@0 | 100 | |
michael@0 | 101 | #define IMAP compose_sym3(nameprep_, VERSION, _prohibited_imap) |
michael@0 | 102 | #define BITMAP compose_sym3(nameprep_, VERSION, _prohibited_bitmap) |
michael@0 | 103 | bm = BITMAP[IMAP[IMAP[idx0] + idx1]].bm; |
michael@0 | 104 | return (bm[idx2 / 8] & (1 << (idx2 % 8))); |
michael@0 | 105 | #undef IMAP |
michael@0 | 106 | #undef BITMAP |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | static int |
michael@0 | 110 | compose_sym2(nameprep_unassigned_, VERSION) (uint32_t v) { |
michael@0 | 111 | int idx0 = IDX0(UNAS, v); |
michael@0 | 112 | int idx1 = IDX1(UNAS, v); |
michael@0 | 113 | int idx2 = IDX2(UNAS, v); |
michael@0 | 114 | const unsigned char *bm; |
michael@0 | 115 | |
michael@0 | 116 | #define IMAP compose_sym3(nameprep_, VERSION, _unassigned_imap) |
michael@0 | 117 | #define BITMAP compose_sym3(nameprep_, VERSION, _unassigned_bitmap) |
michael@0 | 118 | bm = BITMAP[IMAP[IMAP[idx0] + idx1]].bm; |
michael@0 | 119 | return (bm[idx2 / 8] & (1 << (idx2 % 8))); |
michael@0 | 120 | #undef IMAP |
michael@0 | 121 | #undef BITMAP |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | static idn_biditype_t |
michael@0 | 125 | compose_sym2(nameprep_biditype_, VERSION) (uint32_t v) { |
michael@0 | 126 | int idx0 = IDX0(BIDI, v); |
michael@0 | 127 | int idx1 = IDX1(BIDI, v); |
michael@0 | 128 | int idx2 = IDX2(BIDI, v); |
michael@0 | 129 | int offset; |
michael@0 | 130 | |
michael@0 | 131 | #define IMAP compose_sym3(nameprep_, VERSION, _bidi_imap) |
michael@0 | 132 | #define TABLE compose_sym3(nameprep_, VERSION, _bidi_table) |
michael@0 | 133 | #define DATA compose_sym3(nameprep_, VERSION, _bidi_data) |
michael@0 | 134 | offset = TABLE[IMAP[IMAP[idx0] + idx1]].tbl[idx2]; |
michael@0 | 135 | return DATA[offset]; |
michael@0 | 136 | #undef IMAP |
michael@0 | 137 | #undef TABLE |
michael@0 | 138 | #undef DATA |
michael@0 | 139 | } |