decode method
电码转字符
Implementation
String decode(String morse) {
if (morse.trim().isEmpty) return "";
List<String> splitList = morse.split(_split);
StringBuffer textBuffer = StringBuffer();
for (String s in splitList) {
try {
if (s.isNotEmpty) {
String codePoint = s.replaceAll(_dit, '0').replaceAll(_dah, '1');
String? word = "";
//判断_dictionaries字典中是否包含此值
if (_dictionaries.containsValue(codePoint)) {
codePoint = _dictionaries[codePoint];
} else {
//将二进制转成uniCode值,dart中unitCode值是十进制
word = int.tryParse(codePoint, radix: 2)?.toRadixString(10);
}
//将uniCode码转成对应的字符
textBuffer.writeCharCode(int.tryParse(word ?? "") ?? 0);
}
} catch (e) {
print("解码错误:$e");
}
}
return textBuffer.toString();
}