This commit is contained in:
Dwi Swandhana
2026-07-22 09:07:43 +07:00
parent 92dc35396b
commit 9e4774bd5e
22 changed files with 2272 additions and 850 deletions

No files matched your search

+29
View File
@@ -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('&gt;', '>')
.replaceAll('&lt;', '<')
.replaceAll('&amp;', '&')
.replaceAll('&quot;', '"')
.replaceAll('&#039;', "'")
.replaceAll('&apos;', "'");
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;
}