1# pragma once
2
3/*
4This code is based on:
5
6punycode.c from RFC 3492
7http://www.nicemice.net/idn/
8Adam M. Costello
9http://www.nicemice.net/amc/
10
11This is ANSI C code (C89) implementing Punycode (RFC 3492).
12*/
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18/*** Bootstring parameters for Punycode ***/
19
20enum {
21 base = 36,
22 tmin = 1,
23 tmax = 26,
24 skew = 38,
25 damp = 700,
26 initial_bias = 72,
27 initial_n = 0x80,
28 delimiter = 0x2D
29};
30
31/* basic(cp) tests whether cp is a basic code point: */
32#define basic(cp) ((unsigned)(cp) < 0x80)
33
34/* delim(cp) tests whether cp is a delimiter: */
35#define delim(cp) ((cp) == delimiter)
36
37/* maxint is the maximum value of a punycode_uint variable: */
38static const unsigned maxint = -1;
39/* Because maxint is unsigned, -1 becomes the maximum value. */
40
41/*** Bias adaptation function ***/
42
43static unsigned adapt(unsigned delta, unsigned numpoints, bool firsttime)
44{
45 unsigned k;
46
47 delta = firsttime ? delta / damp : delta >> 1;
48 /* delta >> 1 is a faster way of doing delta / 2 */
49 delta += delta / numpoints;
50
51 for (k = 0; delta > ((base - tmin) * tmax) / 2; k += base) {
52 delta /= base - tmin;
53 }
54
55 return k + (base - tmin + 1) * delta / (delta + skew);
56}
57
58#ifdef __cplusplus
59}
60#endif