Fix: split multibyte sentence with unicodeIndex

This commit is contained in:
2019-06-25 11:10:57 +09:00
parent cb9ac3a017
commit 5638266178
4 changed files with 144 additions and 37 deletions
+48
View File
@@ -177,6 +177,54 @@ StringUtil.isSameKoreanAlphabet = function(firstAlphabet, secondAlphabet) {
return false;
};
StringUtil.isKoreanAlphabet = function(char) {
c = char.charCodeAt(0);
if(0x1100 <= c && c <= 0x11FF)
return true;
if(0x3130 <= c && c <= 0x318F)
return true;
if(0xAC00 <= c && c <= 0xD7A3)
return true;
return false;
};
StringUtil.getUnicodeAlphabetCount = function(text) {
var count = 0;
var textLen = text.length
for(var i = 0; i < textLen; i++) {
if(StringUtil.isKoreanAlphabet(text[i]))
count += 2;
else
count++
}
return count;
};
StringUtil.getMultibyteIndex = function(multibyteText, unicodeCharIndex) {
var multibyteTextIndex = 0;
var index = 0;
while(index < unicodeCharIndex) {
var unicodeChar = multibyteText[multibyteTextIndex];
if(typeof unicodeChar == "undefined")
break;
if(StringUtil.isKoreanAlphabet(unicodeChar)) {
if(index + 2 <= unicodeCharIndex)
index += 2;
else
break;
} else
index += 1;
multibyteTextIndex++;
}
return multibyteTextIndex;
};
StringUtil.getScoreUnit = function(playingAppID) {
if(playingAppID == 104)
return " 초";