decodeEntities static method
Implementation
static String decodeEntities(String source) {
if (!source.contains("&")) return source;
return source.replaceAllMapped(RegExp("&(#x?[0-9A-Fa-f]+|[A-Za-z]+);"), (Match match) {
final String token = match.group(1) ?? "";
if (token.startsWith("#x") || token.startsWith("#X")) {
final int? code = int.tryParse(token.substring(2), radix: 16);
return code == null ? match.group(0) ?? "" : String.fromCharCode(code);
}
if (token.startsWith("#")) {
final int? code = int.tryParse(token.substring(1));
return code == null ? match.group(0) ?? "" : String.fromCharCode(code);
}
return _entities[token.toLowerCase()] ?? match.group(0) ?? "";
});
}