pike.git / lib / modules / Standards.pmod / IDNA.pmod

version» Context lines:

pike.git/lib/modules/Standards.pmod/IDNA.pmod:1:   #pike __REAL_VERSION__    - //! This module implements various algorithms specified by - //! the Internationalizing Domain Names in Applications (IDNA) memo by - //! the Internet Engineering Task Force (IETF), see - //! @url{ftp://ftp.rfc-editor.org/in-notes/rfc3490.txt@}. + //! This module implements various algorithms specified by the + //! Internationalizing Domain Names in Applications (IDNA) memo by the + //! Internet Engineering Task Force (IETF), see @rfc{3490@}.    - //! Punycode transcoder, see - //! @url{ftp://ftp.rfc-editor.org/in-notes/rfc3492.txt@}. - //! Punycode is used by @[to_ascii] as an "ASCII Compatible Encoding" when - //! needed. + //! Punycode transcoder, see @rfc{3492@}. Punycode is used by + //! @[to_ascii] as an "ASCII Compatible Encoding" when needed.   object Punycode = class {       inherit String.Bootstring;       string decode(string s) {    array(string) x = s/"-";    x[-1] = lower_case(x[-1]);    return ::decode(x*"-");    }   
pike.git/lib/modules/Standards.pmod/IDNA.pmod:292:   "\x03B9\x0308\x0301\x03B9\x0308\x0342\x03C5\x0308\x0300\x03C5\x0308\x0301"   "\x03C5\x0308\x0342\x03C9\x0342\x03B9\x0074\x0065\x006C\x0068\x0070\x0061"   "\x006B\x0068\x007A\x006D\x0068\x007A\x0067\x0068\x007A\x0074\x0068\x007A"   "\x006B\x0070\x0061\x006D\x0070\x0061\x0067\x0070\x0061\x0063\x006F\x002E"   "\x0070\x0070\x006D\x0066\x0066\x0069\x0066\x0066\x006C"/3+   // 1 to 4   "\x0063\x2215\x006B\x0067"/4;          - //! Prepare a Unicode string for ACE transcoding. Used by @[to_ascii]. - //! Nameprep is a profile of Stringprep, which is described in RFC 3454. + //! Prepare a Unicode string for ACE transcoding. Used by + //! @[to_ascii]. Nameprep is a profile of Stringprep, which is + //! described in @rfc{3454@}.   //!   //! @param s   //! The string to prep.   //! @param allow_unassigned   //! Set this flag the the string to transform is a "query string", - //! and not a "stored string". See RFC 3454. + //! and not a "stored string". See @rfc{3454@}.   //!   string nameprep(string s, int(0..1)|void allow_unassigned)   {    // Mapping: Table B.1 - Map to nothing    s = replace(s,    "\x00AD\x034F\x1806\x180B\x180C\x180D\x200B\x200C\x200D"    "\x2060\xFE00\xFE01\xFE02\xFE03\xFE04\xFE05\xFE06\xFE07"    "\xFE08\xFE09\xFE0A\xFE0B\xFE0C\xFE0D\xFE0E\xFE0F\xFEFF"/"",    ({""})*27);   
pike.git/lib/modules/Standards.pmod/IDNA.pmod:364:      //! The to_ascii operation takes a sequence of Unicode code points that   //! make up one label and transforms it into a sequence of code points in   //! the ASCII range (0..7F). If to_ascci succeeds, the original sequence   //! and the resulting sequence are equivalent labels.   //!   //! @param s   //! The sequence of Unicode code points to transform.   //! @param allow_unassigned   //! Set this flag if the the string to transform is a "query string", - //! and not a "stored string". See RFC 3454. + //! and not a "stored string". See @rfc{3454@}.   //! @param use_std3_ascii_rules   //! Set this flag to enforce the restrictions on ASCII characters in   //! host names imposed by STD3.   //! - string to_ascii(string s, int(0..1)|void allow_unassigned, + string(7bit) to_ascii(string s, int(0..1)|void allow_unassigned,    int(0..1)|void use_std3_ascii_rules)   { -  int is_ascii = max(@values(s)) < 128; +  int is_ascii = String.range(s)[1] < 128;    if(!is_ascii) {    s = nameprep(s, allow_unassigned); -  is_ascii = max(@values(s)) < 128; +  is_ascii = String.range(s)[1] < 128;    }    if(use_std3_ascii_rules) {    if(array_sscanf(s, "%*[^\0-,./:-@[-`{-\x7f]%n")[0] != sizeof(s))    error("Label is not valid accoring to STD3: non-LDH codepoint\n");    if(sizeof(s) && (s[0] == '-' || s[-1] == '-'))    error("Label is not valid accoring to STD3: leading or trailing hyphen-minus\n");    }    if(!is_ascii) {    if(lower_case(s[..3]) == "xn--")    error("Label to encode begins with ACE prefix!\n");
pike.git/lib/modules/Standards.pmod/IDNA.pmod:405:   //! make up one label and returns a sequence of Unicode code points. If   //! the input sequence is a label in ACE form, then the result is an   //! equivalent internationalized label that is not in ACE form, otherwise   //! the original sequence is returned unaltered.   //!   //! @param s   //! The sequence of Unicode code points to transform.   string to_unicode(string s)   {    string s0 = s; -  if(max(@values(s)) >= 128 && +  if(String.range(s)[1] >= 128 &&    catch(s = nameprep(s, 1)))    return s0;    if(lower_case(s[..3]) != "xn--")    return s0;    string ascii_s = s;    catch {    s = Punycode->decode(s[4..]);    if(lower_case(to_ascii(s, 1)) == lower_case(ascii_s))    return s;    };    return s0;   }         //! Takes a sequence of labels separated by '.' and applies   //! @[to_ascii] on each. - string zone_to_ascii(string s, int(0..1)|void allow_unassigned, + string(7bit) zone_to_ascii(string s, int(0..1)|void allow_unassigned,    int(0..1)|void use_std3_ascii_rules)   {    if(has_suffix(s, ".") && !has_suffix(s, ".."))    return sizeof(s)>1?    zone_to_ascii(s[..<1], allow_unassigned,    use_std3_ascii_rules)+"."    : s;    else    return to_ascii((s/".")[*], allow_unassigned, use_std3_ascii_rules)*".";   }         //! Takes a sequence of labels separated by '.' and applies   //! @[to_unicode] on each.   string zone_to_unicode(string s)   {    return to_unicode((s/".")[*])*".";   }