PunycodeCodec class
A codec for encoding and decoding strings using the Punycode algorithm.
Punycode is a character encoding scheme used to represent Unicode characters in ASCII strings. It is commonly used for Internationalized Domain Names (IDNs).
This codec provides methods to convert between Unicode strings and their Punycode representations.
Example:
import 'package:punycoder/punycoder.dart';
void main() {
// Designed to be used with domains and emails which have special rules
const domainCodec = PunycodeCodec();
// Designed to work with simple strings
const simpleCodec = PunycodeCodec.simple();
final encodedString = simpleCodec.encode('münchen');
final encodedDomain = domainCodec.encode('münchen.com');
final encodedEmail = domainCodec.encode('münchen@münchen.com');
print(encodedString); // Output: mnchen-3ya
// Uses the correct prefix for the domain
print(encodedDomain); // Output: xn--mnchen-3ya.com
// Only the domain should be encoded
print(encodedEmail); // Output: münchen@xn--mnchen-3ya.com
final decodedString = simpleCodec.decode('mnchen-3ya');
final decodecDomain = domainCodec.decode('xn--mnchen-3ya.com');
final decodedEmail = domainCodec.decode('münchen@xn--mnchen-3ya.com');
print(decodedString); // Output: münchen
print(decodecDomain); // Output: münchen.com
print(decodedEmail); // Output: münchen@münchen.com
}
Constructors
- PunycodeCodec.new()
-
Creates a new instance of the Punycode codec designed
for working with domains and email addresses where
additional rules apply about how it is converted
const
- PunycodeCodec.simple()
-
Creates a new instance of the Punycode codec just designed
for working with simple strings
const
Properties
-
decoder
→ Converter<
String, String> -
Returns the decoder of
this
, converting fromT
toS
.no setteroverride -
encoder
→ Converter<
String, String> -
Returns the encoder from
S
toT
.no setteroverride - hashCode → int
-
The hash code for this object.
no setterinherited
-
inverted
→ Codec<
String, String> -
Inverts
this
.no setterinherited - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
decode(
String encoded) → String -
Decodes
encoded
data.inherited -
encode(
String input) → String -
Encodes
input
.inherited -
fuse<
R> (Codec< String, R> other) → Codec<String, R> -
Fuses
this
withother
.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited