update
This commit is contained in:
No files matched your search
@@ -138,3 +138,32 @@ List<dynamic> asList(Object? value) => value is List ? value : <dynamic>[];
|
||||
String _message(Object? error) => error is ApiException
|
||||
? error.message
|
||||
: 'Terjadi kesalahan saat memuat data.';
|
||||
|
||||
String decodeHtmlEntities(String value) {
|
||||
var result = value;
|
||||
for (var i = 0; i < 3; i += 1) {
|
||||
final previous = result;
|
||||
result = result
|
||||
.replaceAll(RegExp(r'<\s*br\s*/?\s*>', caseSensitive: false), '\n')
|
||||
.replaceAll(RegExp(r'</\s*p\s*>', caseSensitive: false), '\n')
|
||||
.replaceAll(RegExp(r'<[^>]*>'), '')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll(''', "'")
|
||||
.replaceAll(''', "'");
|
||||
result = result.replaceAllMapped(RegExp(r'&#(\d+);'), (match) {
|
||||
final code = int.tryParse(match.group(1) ?? '');
|
||||
return code == null ? match.group(0)! : String.fromCharCode(code);
|
||||
});
|
||||
result = result.replaceAllMapped(RegExp(r'&#x([0-9a-fA-F]+);'), (match) {
|
||||
final code = int.tryParse(match.group(1) ?? '', radix: 16);
|
||||
return code == null ? match.group(0)! : String.fromCharCode(code);
|
||||
});
|
||||
if (result == previous) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user