Sync with RFC.
[libidn.git] / punycode.h
blob2bcbb07878790479e6e4b3e3c2567e9178de66d6
1 /* punycode.h Declarations for punycode functions.
2 * Copyright (C) 2002, 2003 Simon Josefsson
3 * Copyright (C) 2002 Adam M. Costello
5 * This file is part of GNU Libidn.
7 * GNU Libidn is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * GNU Libidn is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with GNU Libidn; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This file is derived from RFC 3492 written by Adam M. Costello.
26 * Disclaimer and license: Regarding this entire document or any
27 * portion of it (including the pseudocode and C code), the author
28 * makes no guarantees and is not responsible for any damage resulting
29 * from its use. The author grants irrevocable permission to anyone
30 * to use, modify, and distribute it in any way that does not diminish
31 * the rights of anyone else to use, modify, and distribute it,
32 * provided that redistributed derivative works do not contain
33 * misleading author or version information. Derivative works need
34 * not be licensed under similar terms.
38 #ifndef _PUNYCODE_H
39 #define _PUNYCODE_H
41 #ifdef __cplusplus
42 extern "C"
44 #endif
46 enum
48 PUNYCODE_SUCCESS = 0,
49 PUNYCODE_BAD_INPUT, /* Input is invalid. */
50 PUNYCODE_BIG_OUTPUT, /* Output would exceed the space provided. */
51 PUNYCODE_OVERFLOW /* Input needs wider integers to process. */
54 int punycode_encode (size_t input_length,
55 const unsigned long input[],
56 const unsigned char case_flags[],
57 size_t * output_length, char output[]);
59 /* punycode_encode() converts Unicode to Punycode. The input */
60 /* is represented as an array of Unicode code points (not code */
61 /* units; surrogate pairs are not allowed), and the output */
62 /* will be represented as an array of ASCII code points. The */
63 /* output string is *not* null-terminated; it will contain */
64 /* zeros if and only if the input contains zeros. (Of course */
65 /* the caller can leave room for a terminator and add one if */
66 /* needed.) The input_length is the number of code points in */
67 /* the input. The output_length is an in/out argument: the */
68 /* caller passes in the maximum number of code points that it */
69 /* can receive, and on successful return it will contain the */
70 /* number of code points actually output. The case_flags array */
71 /* holds input_length boolean values, where nonzero suggests that */
72 /* the corresponding Unicode character be forced to uppercase */
73 /* after being decoded (if possible), and zero suggests that */
74 /* it be forced to lowercase (if possible). ASCII code points */
75 /* are encoded literally, except that ASCII letters are forced */
76 /* to uppercase or lowercase according to the corresponding */
77 /* uppercase flags. If case_flags is a null pointer then ASCII */
78 /* letters are left as they are, and other code points are */
79 /* treated as if their uppercase flags were zero. The return */
80 /* value can be any of the punycode_status values defined above */
81 /* except punycode_bad_input; if not punycode_success, then */
82 /* output_size and output might contain garbage. */
84 int punycode_decode (size_t input_length,
85 const char input[],
86 size_t * output_length,
87 unsigned long output[], unsigned char case_flags[]);
89 /* punycode_decode() converts Punycode to Unicode. The input is */
90 /* represented as an array of ASCII code points, and the output */
91 /* will be represented as an array of Unicode code points. The */
92 /* input_length is the number of code points in the input. The */
93 /* output_length is an in/out argument: the caller passes in */
94 /* the maximum number of code points that it can receive, and */
95 /* on successful return it will contain the actual number of */
96 /* code points output. The case_flags array needs room for at */
97 /* least output_length values, or it can be a null pointer if the */
98 /* case information is not needed. A nonzero flag suggests that */
99 /* the corresponding Unicode character be forced to uppercase */
100 /* by the caller (if possible), while zero suggests that it be */
101 /* forced to lowercase (if possible). ASCII code points are */
102 /* output already in the proper case, but their flags will be set */
103 /* appropriately so that applying the flags would be harmless. */
104 /* The return value can be any of the punycode_status values */
105 /* defined above; if not punycode_success, then output_length, */
106 /* output, and case_flags might contain garbage. On success, the */
107 /* decoder will never need to write an output_length greater than */
108 /* input_length, because of how the encoding is defined. */
110 #ifdef __cplusplus
112 #endif
113 #endif /* _PUNYCODE_H */