OLD | NEW |
(Empty) | |
| 1 /* |
| 2 ****************************************************************************** |
| 3 * |
| 4 * Copyright (C) 2003, International Business Machines |
| 5 * Corporation and others. All Rights Reserved. |
| 6 * |
| 7 ****************************************************************************** |
| 8 */ |
| 9 /* |
| 10 punycode.c from draft-ietf-idn-punycode-03 |
| 11 http://www.nicemice.net/idn/ |
| 12 Adam M. Costello |
| 13 http://www.nicemice.net/amc/ |
| 14 |
| 15 This is ANSI C code (C89) implementing |
| 16 Punycode (draft-ietf-idn-punycode-03). |
| 17 |
| 18 Disclaimer and license |
| 19 |
| 20 Regarding this entire document or any portion of it (including |
| 21 the pseudocode and C code), the author makes no guarantees and |
| 22 is not responsible for any damage resulting from its use. The |
| 23 author grants irrevocable permission to anyone to use, modify, |
| 24 and distribute it in any way that does not diminish the rights |
| 25 of anyone else to use, modify, and distribute it, provided that |
| 26 redistributed derivative works do not contain misleading author or |
| 27 version information. Derivative works need not be licensed under |
| 28 similar terms. |
| 29 |
| 30 */ |
| 31 #ifndef _PUNYREF_H |
| 32 #define _PUNYREF_H |
| 33 |
| 34 /************************************************************/ |
| 35 /* Public interface (would normally go in its own .h file): */ |
| 36 |
| 37 #include "unicode/utypes.h" |
| 38 |
| 39 #if !UCONFIG_NO_IDNA |
| 40 |
| 41 enum punycode_status { |
| 42 punycode_success, |
| 43 punycode_bad_input, /* Input is invalid. */ |
| 44 punycode_big_output, /* Output would exceed the space provided. */ |
| 45 punycode_overflow /* Input needs wider integers to process. */ |
| 46 }; |
| 47 |
| 48 |
| 49 typedef uint32_t punycode_uint; |
| 50 |
| 51 U_CDECL_BEGIN |
| 52 |
| 53 enum punycode_status punycode_encode( |
| 54 punycode_uint input_length, |
| 55 const punycode_uint input[], |
| 56 const unsigned char case_flags[], |
| 57 punycode_uint *output_length, |
| 58 char output[] ); |
| 59 |
| 60 /* punycode_encode() converts Unicode to Punycode. The input */ |
| 61 /* is represented as an array of Unicode code points (not code */ |
| 62 /* units; surrogate pairs are not allowed), and the output */ |
| 63 /* will be represented as an array of ASCII code points. The */ |
| 64 /* output string is *not* null-terminated; it will contain */ |
| 65 /* zeros if and only if the input contains zeros. (Of course */ |
| 66 /* the caller can leave room for a terminator and add one if */ |
| 67 /* needed.) The input_length is the number of code points in */ |
| 68 /* the input. The output_length is an in/out argument: the */ |
| 69 /* caller passes in the maximum number of code points that it */ |
| 70 /* can receive, and on successful return it will contain the */ |
| 71 /* number of code points actually output. The case_flags array */ |
| 72 /* holds input_length boolean values, where nonzero suggests that */ |
| 73 /* the corresponding Unicode character be forced to uppercase */ |
| 74 /* after being decoded (if possible), and zero suggests that */ |
| 75 /* it be forced to lowercase (if possible). ASCII code points */ |
| 76 /* are encoded literally, except that ASCII letters are forced */ |
| 77 /* to uppercase or lowercase according to the corresponding */ |
| 78 /* uppercase flags. If case_flags is a null pointer then ASCII */ |
| 79 /* letters are left as they are, and other code points are */ |
| 80 /* treated as if their uppercase flags were zero. The return */ |
| 81 /* value can be any of the punycode_status values defined above */ |
| 82 /* except punycode_bad_input; if not punycode_success, then */ |
| 83 /* output_size and output might contain garbage. */ |
| 84 |
| 85 enum punycode_status punycode_decode( |
| 86 punycode_uint input_length, |
| 87 const char input[], |
| 88 punycode_uint *output_length, |
| 89 punycode_uint output[], |
| 90 unsigned char case_flags[] ); |
| 91 |
| 92 /* punycode_decode() converts Punycode to Unicode. The input is */ |
| 93 /* represented as an array of ASCII code points, and the output */ |
| 94 /* will be represented as an array of Unicode code points. The */ |
| 95 /* input_length is the number of code points in the input. The */ |
| 96 /* output_length is an in/out argument: the caller passes in */ |
| 97 /* the maximum number of code points that it can receive, and */ |
| 98 /* on successful return it will contain the actual number of */ |
| 99 /* code points output. The case_flags array needs room for at */ |
| 100 /* least output_length values, or it can be a null pointer if the */ |
| 101 /* case information is not needed. A nonzero flag suggests that */ |
| 102 /* the corresponding Unicode character be forced to uppercase */ |
| 103 /* by the caller (if possible), while zero suggests that it be */ |
| 104 /* forced to lowercase (if possible). ASCII code points are */ |
| 105 /* output already in the proper case, but their flags will be set */ |
| 106 /* appropriately so that applying the flags would be harmless. */ |
| 107 /* The return value can be any of the punycode_status values */ |
| 108 /* defined above; if not punycode_success, then output_length, */ |
| 109 /* output, and case_flags might contain garbage. On success, the */ |
| 110 /* decoder will never need to write an output_length greater than */ |
| 111 /* input_length, because of how the encoding is defined. */ |
| 112 U_CDECL_END |
| 113 |
| 114 #endif /* #if !UCONFIG_NO_IDNA */ |
| 115 |
| 116 #endif |
OLD | NEW |