Annotation of parser3/src/lib/punycode/pa_punycode.h, revision 1.2
1.1 moko 1: /* punycode.h --- Declarations for punycode functions.
2: Copyright (C) 2002-2013 Simon Josefsson
3:
4: This file is part of GNU Libidn.
5:
6: GNU Libidn is free software: you can redistribute it and/or
7: modify it under the terms of either:
8:
9: * the GNU Lesser General Public License as published by the Free
10: Software Foundation; either version 3 of the License, or (at
11: your option) any later version.
12:
13: or
14:
15: * the GNU General Public License as published by the Free
16: Software Foundation; either version 2 of the License, or (at
17: your option) any later version.
18:
19: or both in parallel, as here.
20:
21: GNU Libidn is distributed in the hope that it will be useful,
22: but WITHOUT ANY WARRANTY; without even the implied warranty of
23: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24: General Public License for more details.
25:
26: You should have received copies of the GNU General Public License and
27: the GNU Lesser General Public License along with this program. If
28: not, see <http://www.gnu.org/licenses/>. */
29:
30: /*
31: * This file contains content derived from RFC 3492bis written by Adam
32: * M. Costello.
33: *
34: * Disclaimer and license: Regarding this entire document or any
35: * portion of it (including the pseudocode and C code), the author
36: * makes no guarantees and is not responsible for any damage resulting
37: * from its use. The author grants irrevocable permission to anyone
38: * to use, modify, and distribute it in any way that does not diminish
39: * the rights of anyone else to use, modify, and distribute it,
40: * provided that redistributed derivative works do not contain
41: * misleading author or version information. Derivative works need
42: * not be licensed under similar terms.
43: *
44: * Copyright (C) The Internet Society (2003). All Rights Reserved.
45: *
46: * This document and translations of it may be copied and furnished to
47: * others, and derivative works that comment on or otherwise explain it
48: * or assist in its implementation may be prepared, copied, published
49: * and distributed, in whole or in part, without restriction of any
50: * kind, provided that the above copyright notice and this paragraph are
51: * included on all such copies and derivative works. However, this
52: * document itself may not be modified in any way, such as by removing
53: * the copyright notice or references to the Internet Society or other
54: * Internet organizations, except as needed for the purpose of
55: * developing Internet standards in which case the procedures for
56: * copyrights defined in the Internet Standards process must be
57: * followed, or as required to translate it into languages other than
58: * English.
59: *
60: * The limited permissions granted above are perpetual and will not be
61: * revoked by the Internet Society or its successors or assigns.
62: *
63: * This document and the information contained herein is provided on an
64: * "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
65: * TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
66: * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
67: * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
68: * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
69: */
70:
71: #ifndef PA_PUNYCODE_H
72: # define PA_PUNYCODE_H
73:
74: #ifdef __cplusplus
75: extern "C"
76: {
77: #endif
78:
79: #include "pa_config_includes.h"
80:
1.2 ! moko 81: enum punycode_status {
! 82: punycode_success = 0,
! 83: punycode_bad_input = 1, /* Input is invalid. */
! 84: punycode_big_output = 2, /* Output would exceed the space provided. */
! 85: punycode_overflow = 3 /* Wider integers needed to process input. */
! 86: };
! 87:
! 88: typedef enum {
! 89: PUNYCODE_SUCCESS = punycode_success,
! 90: PUNYCODE_BAD_INPUT = punycode_bad_input,
! 91: PUNYCODE_BIG_OUTPUT = punycode_big_output,
! 92: PUNYCODE_OVERFLOW = punycode_overflow
! 93: } Punycode_status;
1.1 moko 94:
1.2 ! moko 95: const char *punycode_strerror (Punycode_status rc);
1.1 moko 96:
97: /* punycode_uint needs to be unsigned and needs to be */
98: /* at least 26 bits wide. */
99:
1.2 ! moko 100: typedef uint32_t punycode_uint;
1.1 moko 101:
1.2 ! moko 102: int punycode_encode (size_t input_length, const punycode_uint input[], const unsigned char case_flags[], size_t * output_length, char output[]);
1.1 moko 103:
104: /*
105: punycode_encode() converts a sequence of code points (presumed to be
106: Unicode code points) to Punycode.
107:
108: Input arguments (to be supplied by the caller):
109:
110: input_length
111: The number of code points in the input array and the number
112: of flags in the case_flags array.
113:
114: input
115: An array of code points. They are presumed to be Unicode
116: code points, but that is not strictly REQUIRED. The
117: array contains code points, not code units. UTF-16 uses
118: code units D800 through DFFF to refer to code points
119: 10000..10FFFF. The code points D800..DFFF do not occur in
120: any valid Unicode string. The code points that can occur in
121: Unicode strings (0..D7FF and E000..10FFFF) are also called
122: Unicode scalar values.
123:
124: case_flags
125: A null pointer or an array of boolean values parallel to
126: the input array. Nonzero (true, flagged) suggests that the
127: corresponding Unicode character be forced to uppercase after
128: being decoded (if possible), and zero (false, unflagged)
129: suggests that it be forced to lowercase (if possible).
130: ASCII code points (0..7F) are encoded literally, except that
131: ASCII letters are forced to uppercase or lowercase according
132: to the corresponding case flags. If case_flags is a null
133: pointer then ASCII letters are left as they are, and other
134: code points are treated as unflagged.
135:
136: Output arguments (to be filled in by the function):
137:
138: output
139: An array of ASCII code points. It is *not* null-terminated;
140: it will contain zeros if and only if the input contains
141: zeros. (Of course the caller can leave room for a
142: terminator and add one if needed.)
143:
144: Input/output arguments (to be supplied by the caller and overwritten
145: by the function):
146:
147: output_length
148: The caller passes in the maximum number of ASCII code points
149: that it can receive. On successful return it will contain
150: the number of ASCII code points actually output.
151:
152: Return value:
153:
154: Can be any of the punycode_status values defined above except
155: punycode_bad_input. If not punycode_success, then output_size
156: and output might contain garbage.
157: */
158:
1.2 ! moko 159: int punycode_decode (size_t input_length, const char input[], size_t * output_length, punycode_uint output[], unsigned char case_flags[]);
1.1 moko 160:
161: /*
162: punycode_decode() converts Punycode to a sequence of code points
163: (presumed to be Unicode code points).
164:
165: Input arguments (to be supplied by the caller):
166:
167: input_length
168: The number of ASCII code points in the input array.
169:
170: input
171: An array of ASCII code points (0..7F).
172:
173: Output arguments (to be filled in by the function):
174:
175: output
176: An array of code points like the input argument of
177: punycode_encode() (see above).
178:
179: case_flags
180: A null pointer (if the flags are not needed by the caller)
181: or an array of boolean values parallel to the output array.
182: Nonzero (true, flagged) suggests that the corresponding
183: Unicode character be forced to uppercase by the caller (if
184: possible), and zero (false, unflagged) suggests that it
185: be forced to lowercase (if possible). ASCII code points
186: (0..7F) are output already in the proper case, but their
187: flags will be set appropriately so that applying the flags
188: would be harmless.
189:
190: Input/output arguments (to be supplied by the caller and overwritten
191: by the function):
192:
193: output_length
194: The caller passes in the maximum number of code points
195: that it can receive into the output array (which is also
196: the maximum number of flags that it can receive into the
197: case_flags array, if case_flags is not a null pointer). On
198: successful return it will contain the number of code points
199: actually output (which is also the number of flags actually
200: output, if case_flags is not a null pointer). The decoder
201: will never need to output more code points than the number
202: of ASCII code points in the input, because of the way the
203: encoding is defined. The number of code points output
204: cannot exceed the maximum possible value of a punycode_uint,
205: even if the supplied output_length is greater than that.
206:
207: Return value:
208:
209: Can be any of the punycode_status values defined above. If not
210: punycode_success, then output_length, output, and case_flags
211: might contain garbage.
212: */
213:
214: #ifdef __cplusplus
215: }
216: #endif
217: #endif /* PA_PUNYCODE_H */
E-mail: