Watt-32 tcp/ip  2.2 dev-rel.10
punycode.h
1 /*
2  * punycode from RFC 3492
3  * http://www.nicemice.net/idn/
4  * Adam M. Costello
5  * http://www.nicemice.net/amc/
6  */
7 
8 #ifndef _w32_PUNYCODE_H
9 #define _w32_PUNYCODE_H
10 
11 enum punycode_status {
12  punycode_success,
13  punycode_bad_input, /* Input is invalid. */
14  punycode_big_output, /* Output would exceed the space provided. */
15  punycode_overflow /* Input needs wider integers to process. */
16  };
17 
18 /*
19  * punycode_encode() converts Unicode to Punycode. The input
20  * is represented as an array of Unicode code points (not code
21  * units; surrogate pairs are not allowed), and the output
22  * will be represented as an array of ASCII code points. The
23  * output string is *not* null-terminated; it will contain
24  * zeros if and only if the input contains zeros. (Of course
25  * the caller can leave room for a terminator and add one if
26  * needed.) The input_length is the number of code points in
27  * the input. The output_length is an in/out argument: the
28  * caller passes in the maximum number of code points that it
29  * can receive, and on successful return it will contain the
30  * number of code points actually output. The case_flags array
31  * holds input_length boolean values, where nonzero suggests that
32  * the corresponding Unicode character be forced to uppercase
33  * after being decoded (if possible), and zero suggests that
34  * it be forced to lowercase (if possible). ASCII code points
35  * are encoded literally, except that ASCII letters are forced
36  * to uppercase or lowercase according to the corresponding
37  * uppercase flags. If case_flags is a null pointer then ASCII
38  * letters are left as they are, and other code points are
39  * treated as if their uppercase flags were zero. The return
40  * value can be any of the punycode_status values defined above
41  * except punycode_bad_input; if not punycode_success, then
42  * output_size and output might contain garbage.
43  */
44 enum punycode_status punycode_encode (size_t input_length,
45  const DWORD *input,
46  const BYTE *case_flags,
47  size_t *output_length,
48  char *output);
49 
50 
51 /*
52  * punycode_decode() converts Punycode to Unicode. The input is
53  * represented as an array of ASCII code points, and the output
54  * will be represented as an array of Unicode code points. The
55  * input_length is the number of code points in the input. The
56  * output_length is an in/out argument: the caller passes in
57  * the maximum number of code points that it can receive, and
58  * on successful return it will contain the actual number of
59  * code points output. The case_flags array needs room for at
60  * least output_length values, or it can be a null pointer if the
61  * case information is not needed. A nonzero flag suggests that
62  * the corresponding Unicode character be forced to uppercase
63  * by the caller (if possible), while zero suggests that it be
64  * forced to lowercase (if possible). ASCII code points are
65  * output already in the proper case, but their flags will be set
66  * appropriately so that applying the flags would be harmless.
67  * The return value can be any of the punycode_status values
68  * defined above; if not punycode_success, then output_length,
69  * output, and case_flags might contain garbage. On success, the
70  * decoder will never need to write an output_length greater than
71  * input_length, because of how the encoding is defined.
72  */
73 enum punycode_status punycode_decode (DWORD input_length,
74  const char *input,
75  size_t *output_length,
76  DWORD *output,
77  BYTE *case_flags);
78 #endif