PeterO.Text.Idna
## PeterO.Text.Idna
public static class Idna
Contains methods that implement Internationalized Domain Names in Applications (IDNA). IDNA enables using a wider range of letters, numbers, and certain other characters in domain names. This class implements the 2008 revision of IDNA, also known as IDNA2008.
The following summarizes the rules for domain names in IDNA2008; see RFC5890 for more information and additional terminology.
A domain name is divided into one or more strings separated by dots (“.”), called labels. For IDNA2008’s purposes, a valid label can be an NR-LDH label, an A-label, or a U-label.
An LDH label contains only basic uppercase letters, basic lowercase letters, basic digits, and/or “-“, and neither begins nor ends with “-“. For example, “exa-mple”, “EXAMPLE”, and “1example” are LDH labels, but not “-example”.
An NR-LDH label is an LDH label whose third and fourth characters are not both “-“. For example, “ex–ample” is not an NR-LDH label.
A U-label contains one or more characters outside the Basic Latin range (U+0000 to U+007F) and meets IDNA2008 requirements for labels with such characters. An example is “eá”.
An A-label is an LDH label beginning with “xn–” where the letters can be any combination of basic upper-case and/or basic lower-case letters, and is convertible to a U-label. An example is “xn–e-ufa”.
An XN-label is an LDH label beginning with “xn–” where the letters can be any combination of basic upper-case and/or basic lower-case letters.
NOTICE: While this class’s source code is in the public domain, the class uses two internal classes, called NormalizationData
and IdnaData
, that include data derived from the Unicode Character Database. See the documentation for the NormalizerInput class for the permission notice for the Unicode Character Database.
Member Summary
[DecodeDomainName(string)](#DecodeDomainName_string)
- Tries to encode each XN-label of the given domain name into Unicode.[EncodeDomainName(string)](#EncodeDomainName_string)
- Tries to encode each label of a domain name with code points outside the Basic Latin range (U+0000 to U+007F) into an XN-label.[IsValidDomainName(string, bool)](#IsValidDomainName_string_bool)
- Determines whether the given string is a domain name containing only U-labels, A-labels, NR-LDH labels, or any combination of these, separated by dots (“.
public static string DecodeDomainName( string value);
Tries to encode each XN-label of the given domain name into Unicode. This method does not check the syntactic validity of the domain name before proceeding.
Parameters:
- value: A domain name.
Return Value:
The domain name where each XN-label is encoded into Unicode. Labels where this is not possible remain unchanged.
Exceptions:
- System.ArgumentNullException: The parameter value is null.
public static string EncodeDomainName( string value);
Tries to encode each label of a domain name with code points outside the Basic Latin range (U+0000 to U+007F) into an XN-label. This method does not check the syntactic validity of the domain name before proceeding.
Parameters:
- value: A domain name.
Return Value:
The domain name where each label with code points outside the Basic Latin range (U+0000 to U+007F) is encoded into an XN-label. Labels where this is not possible remain unchanged.
Exceptions:
- System.ArgumentNullException: The parameter value is null.
public static bool IsValidDomainName( string str, bool lookupRules);
Determines whether the given string is a domain name containing only U-labels, A-labels, NR-LDH labels, or any combination of these, separated by dots (“.”).
Parameters:
-
str: The parameter str is a text string.
-
lookupRules: If true, uses rules to apply when looking up the string as a domain name. If false, uses rules to apply when registering the string as a domain name.
Return Value:
true
if the given string is a syntactically valid domain name; otherwise; false.
Exceptions:
- System.ArgumentNullException: The parameter str is null.