Mercurial > thymian
comparison 3rdparty/vmime/contrib/punycode/punycode.h @ 0:a4671277546c tip
created the repository for the thymian project
| author | ferencd |
|---|---|
| date | Tue, 17 Aug 2021 11:19:54 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a4671277546c |
|---|---|
| 1 /* | |
| 2 punycode.h from RFC 3492 | |
| 3 http://www.nicemice.net/idn/ | |
| 4 Adam M. Costello | |
| 5 http://www.nicemice.net/amc/ | |
| 6 | |
| 7 This is ANSI C code (C89) implementing Punycode (RFC 3492). | |
| 8 | |
| 9 */ | |
| 10 | |
| 11 #include <limits.h> | |
| 12 | |
| 13 enum punycode_status { | |
| 14 punycode_success, | |
| 15 punycode_bad_input, /* Input is invalid. */ | |
| 16 punycode_big_output, /* Output would exceed the space provided. */ | |
| 17 punycode_overflow /* Input needs wider integers to process. */ | |
| 18 }; | |
| 19 | |
| 20 #if UINT_MAX >= (1 << 26) - 1 | |
| 21 typedef unsigned int punycode_uint; | |
| 22 #else | |
| 23 typedef unsigned long punycode_uint; | |
| 24 #endif | |
| 25 | |
| 26 enum punycode_status punycode_encode( | |
| 27 punycode_uint input_length, | |
| 28 const punycode_uint input[], | |
| 29 const unsigned char case_flags[], | |
| 30 punycode_uint *output_length, | |
| 31 char output[] ); | |
| 32 | |
| 33 /* punycode_encode() converts Unicode to Punycode. The input */ | |
| 34 /* is represented as an array of Unicode code points (not code */ | |
| 35 /* units; surrogate pairs are not allowed), and the output */ | |
| 36 /* will be represented as an array of ASCII code points. The */ | |
| 37 /* output string is *not* null-terminated; it will contain */ | |
| 38 /* zeros if and only if the input contains zeros. (Of course */ | |
| 39 /* the caller can leave room for a terminator and add one if */ | |
| 40 /* needed.) The input_length is the number of code points in */ | |
| 41 /* the input. The output_length is an in/out argument: the */ | |
| 42 /* caller passes in the maximum number of code points that it */ | |
| 43 /* can receive, and on successful return it will contain the */ | |
| 44 /* number of code points actually output. The case_flags array */ | |
| 45 /* holds input_length boolean values, where nonzero suggests that */ | |
| 46 /* the corresponding Unicode character be forced to uppercase */ | |
| 47 /* after being decoded (if possible), and zero suggests that */ | |
| 48 /* it be forced to lowercase (if possible). ASCII code points */ | |
| 49 /* are encoded literally, except that ASCII letters are forced */ | |
| 50 /* to uppercase or lowercase according to the corresponding */ | |
| 51 /* uppercase flags. If case_flags is a null pointer then ASCII */ | |
| 52 /* letters are left as they are, and other code points are */ | |
| 53 /* treated as if their uppercase flags were zero. The return */ | |
| 54 /* value can be any of the punycode_status values defined above */ | |
| 55 /* except punycode_bad_input; if not punycode_success, then */ | |
| 56 /* output_size and output might contain garbage. */ | |
| 57 | |
| 58 enum punycode_status punycode_decode( | |
| 59 punycode_uint input_length, | |
| 60 const char input[], | |
| 61 punycode_uint *output_length, | |
| 62 punycode_uint output[], | |
| 63 unsigned char case_flags[] ); | |
| 64 | |
| 65 /* punycode_decode() converts Punycode to Unicode. The input is */ | |
| 66 /* represented as an array of ASCII code points, and the output */ | |
| 67 /* will be represented as an array of Unicode code points. The */ | |
| 68 /* input_length is the number of code points in the input. The */ | |
| 69 /* output_length is an in/out argument: the caller passes in */ | |
| 70 /* the maximum number of code points that it can receive, and */ | |
| 71 /* on successful return it will contain the actual number of */ | |
| 72 /* code points output. The case_flags array needs room for at */ | |
| 73 /* least output_length values, or it can be a null pointer if the */ | |
| 74 /* case information is not needed. A nonzero flag suggests that */ | |
| 75 /* the corresponding Unicode character be forced to uppercase */ | |
| 76 /* by the caller (if possible), while zero suggests that it be */ | |
| 77 /* forced to lowercase (if possible). ASCII code points are */ | |
| 78 /* output already in the proper case, but their flags will be set */ | |
| 79 /* appropriately so that applying the flags would be harmless. */ | |
| 80 /* The return value can be any of the punycode_status values */ | |
| 81 /* defined above; if not punycode_success, then output_length, */ | |
| 82 /* output, and case_flags might contain garbage. On success, the */ | |
| 83 /* decoder will never need to write an output_length greater than */ | |
| 84 /* input_length, because of how the encoding is defined. */ |
