replaceSpecialCharsWithKorean static method
String
replaceSpecialCharsWithKorean(
- String text, {
- required List<
SpecialCharToSpeech> specialCharToSpeech,
Replaces special characters in the text with their Korean equivalents based on provided options.
Parameters:
text
: The input text to be processed.specialCharToSpeech
: Options for replacing special characters.
Returns the text with special characters replaced by their Korean equivalents.
Implementation
static String replaceSpecialCharsWithKorean(
String text, {
required List<SpecialCharToSpeech> specialCharToSpeech,
}) {
Map<String, String> specialCharsToKoreanMap = {};
if (specialCharToSpeech.isNotEmpty) {
specialCharsToKoreanMap.addAll(
{for (var v in specialCharToSpeech) v.specialChar: v.speech},
);
}
String result = '';
for (int i = 0; i < text.length; i++) {
String char = text[i];
if (specialCharsToKoreanMap.containsKey(char)) {
result += specialCharsToKoreanMap[char] ?? '';
} else {
result += char;
}
}
// Remove any special characters that were not replaced.
result = result.removeAllSpecialCharsNotKorean();
return result;
}