TF-3267 Implement HTML attachment preview
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'app_logger.dart';
|
||||
|
||||
import 'package:core/domain/exceptions/string_exception.dart';
|
||||
|
||||
class StringConvert {
|
||||
static const String separatorPattern = r'[ ,;]+';
|
||||
|
||||
@@ -38,4 +41,24 @@ class StringConvert {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
static String decodeFromBytes(
|
||||
Uint8List bytes, {
|
||||
required String? charset,
|
||||
bool isHtml = false,
|
||||
}) {
|
||||
if (isHtml) {
|
||||
return utf8.decode(bytes);
|
||||
} else if (charset == null) {
|
||||
throw const NullCharsetException();
|
||||
} else if (charset.toLowerCase().contains('utf-8')) {
|
||||
return utf8.decode(bytes);
|
||||
} else if (charset.toLowerCase().contains('latin')) {
|
||||
return latin1.decode(bytes);
|
||||
} else if (charset.toLowerCase().contains('ascii')) {
|
||||
return ascii.decode(bytes);
|
||||
} else {
|
||||
throw const UnsupportedCharsetException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user