encode method
字符转电码
Implementation
String encode(String text) {
if (text.trim().isEmpty) return "";
StringBuffer stringBuffer = StringBuffer();
String tempText = text.toUpperCase();
for (int i = 0; i < tempText.length; i++) {
int codePoint = tempText.codeUnitAt(i); //此处获取的是unitCode值,十进制数值
String word = "";
//先判断_alphabets当前字符是否在标准摩尔斯电码表字典中
if (_alphabets.containsKey(codePoint)) {
word = _alphabets[codePoint];
} else {
//将uniCode十进制值转成二进制值
word = codePoint.toRadixString(2);
}
stringBuffer.write(word.replaceAll('0', _dit).replaceAll('1', _dah));
stringBuffer.write(_split);
}
return stringBuffer.toString();
}