23#define basic(cp) ((punycode_uint)(cp) < 0x80)
26#define delim(cp) ((cp) == delimiter)
34 return cp - 48 < 10 ? cp - 22 : cp - 65 < 26 ? cp - 65 :
35 cp - 97 < 26 ? cp - 97 :
base;
46 return d + 22 + 75 * (d < 26) - ((flag != 0) << 5);
55#define flagged(bcp) ((punycode_uint)(bcp) - 65 < 26)
65 bcp -= (bcp - 97 < 26) << 5;
66 return bcp + ((!flag && (bcp - 65 < 26)) << 5);
82 delta = firsttime ? delta /
damp : delta >> 1;
84 delta += delta / numpoints;
96 size_t input_length_orig,
98 const unsigned char case_flags[],
99 size_t *output_length,
102 punycode_uint input_length, n, delta, h, b, bias, j, m, q, k, t;
117 max_out = *output_length;
122 for (j = 0; j < input_length; ++j) {
123 if (
basic(input[j])) {
125 output[out++] = case_flags ?
126 encode_basic(input[j], case_flags[j]) : (char) input[j];
143 while (h < input_length) {
147 for (m =
maxint, j = 0; j < input_length; ++j) {
150 if (input[j] >= n && input[j] < m) m = input[j];
157 delta += (m - n) * (h + 1);
160 for (j = 0; j < input_length; ++j) {
169 for (q = delta, k =
base; ; k +=
base) {
171 t = k <= bias ?
tmin :
175 q = (q - t) / (
base - t);
178 output[out++] =
encode_digit(q, case_flags && case_flags[j]);
179 bias =
adapt(delta, h + 1, h == b);
188 *output_length = out;
197 size_t *output_length,
199 unsigned char case_flags[] )
201 punycode_uint n, out, i, max_out, bias, oldi, w, k, digit, t;
216 for (b = j = 0; j < input_length; ++j)
if (
delim(input[j])) b = j;
219 for (j = 0; j < b; ++j) {
220 if (case_flags) case_flags[out] =
flagged(input[j]);
222 output[out++] = input[j];
228 for (in = b > 0 ? b + 1 : 0; in < input_length; ++out) {
238 for (oldi = i, w = 1, k =
base; ; k +=
base) {
244 t = k <= bias ?
tmin :
246 if (digit < t)
break;
251 bias =
adapt(i - oldi, out + 1, oldi == 0);
267 memmove(case_flags + i + 1, case_flags + i, out - i);
269 case_flags[i] =
flagged(input[in - 1]);
272 memmove(output + i + 1, output + i, (out - i) *
sizeof *output);
276 *output_length = (size_t) out;
enum punycode_status punycode_decode(size_t input_length, const char input[], size_t *output_length, punycode_uint output[], unsigned char case_flags[])
static char encode_basic(punycode_uint bcp, int flag)
static char encode_digit(punycode_uint d, int flag)
enum punycode_status punycode_encode(size_t input_length_orig, const punycode_uint input[], const unsigned char case_flags[], size_t *output_length, char output[])
static punycode_uint decode_digit(punycode_uint cp)
static const punycode_uint maxint
static punycode_uint adapt(punycode_uint delta, punycode_uint numpoints, int firsttime)
unsigned long punycode_uint
Interface to utility string handling.