-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 코드 리팩토링 * 개발용 성능 측정 코드 제거
- Loading branch information
Showing
2 changed files
with
36 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,56 @@ | ||
var ChoseongList = ['ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅌ', 'ㅋ', 'ㅍ', 'ㅎ']; | ||
|
||
function getRegexpWord(word) { | ||
var startRegexpWord = ''; | ||
var endRegexpWord = ''; | ||
var oSplitWord = SplitKor(word); | ||
var startRegexpWord = ''; | ||
var endRegexpWord = ''; | ||
|
||
if (ChoseongList.indexOf(word) > -1) { // 초성만 들어왔을 경우 | ||
startRegexpWord = String.fromCharCode((((ChoseongList.indexOf(word) * 21) + 0) * 28) + 0xAC00); | ||
endRegexpWord = String.fromCharCode((((ChoseongList.indexOf(word) * 21) + 20) * 28) + 27 + 0xAC00); | ||
} else { // 완성된 글자일 경우 | ||
startRegexpWord = word; | ||
endRegexpWord = String.fromCharCode((((oSplitWord.cho * 21) + oSplitWord.jung) * 28) + 27 + 0xAC00); | ||
} | ||
if (ChoseongList.indexOf(word) > -1) { // 초성만 들어왔을 경우 | ||
var c = (ChoseongList.indexOf(word) * 21); | ||
|
||
var regexp = ['[', startRegexpWord, '-', endRegexpWord, ']'].join(''); | ||
startRegexpWord = String.fromCharCode((c * 28) + 0xAC00); | ||
endRegexpWord = String.fromCharCode(((c + 20) * 28) + 27 + 0xAC00); | ||
} else { // 완성된 글자일 경우 | ||
var oSplitWord = SplitKor(word); | ||
|
||
return regexp; | ||
startRegexpWord = word; | ||
endRegexpWord = String.fromCharCode((((oSplitWord.cho * 21) + oSplitWord.jung) * 28) + 27 + 0xAC00); | ||
} | ||
|
||
return ['[', startRegexpWord, '-', endRegexpWord, ']'].join(''); | ||
} | ||
|
||
function SplitKor(str) { | ||
var cCode = str.charCodeAt(0) - 0xAC00; | ||
var cCode = str.charCodeAt(0) - 0xAC00; | ||
|
||
var jong = cCode % 28; // 종성 | ||
var c = (cCode - jong) / 28; | ||
|
||
var jong = cCode % 28; // 종성 | ||
var jung = ((cCode - jong) / 28 ) % 21 // 중성 | ||
var cho = (((cCode - jong) / 28 ) - jung ) / 21 // 초성 | ||
var jung = c % 21; // 중성 | ||
var cho = (c - jung ) / 21; // 초성 | ||
|
||
return { | ||
cho: cho, | ||
jung: jung, | ||
jong: jong | ||
} | ||
return { | ||
"cho": cho, | ||
"jung": jung, | ||
"jong": jong | ||
} | ||
} | ||
|
||
var SearchKor = function (input, isStartWord) { | ||
console.time('start search choseong...'); | ||
var wordLength = input.length; | ||
var regexp = ''; | ||
|
||
if (isStartWord === true) { | ||
regexp = '^'; | ||
} | ||
|
||
var word = ''; | ||
for (var i = 0; i < wordLength; i++) { | ||
word = input.charAt(i); | ||
var wordLength = input.length; | ||
var regexp = ''; | ||
|
||
regexp += getRegexpWord(word); | ||
} | ||
if (isStartWord === true) { | ||
regexp = '^'; | ||
} | ||
|
||
var result = this.match(new RegExp(regexp, 'g')); | ||
var word = ''; | ||
for (var i = 0; i < wordLength; i++) { | ||
word = input[i]; | ||
|
||
console.timeEnd('start search choseong...'); | ||
regexp += getRegexpWord(word); | ||
} | ||
|
||
return result; | ||
return this.match(new RegExp(regexp, 'g')); | ||
}; | ||
|
||
module.exports = SearchKor; |