Skip to content

Commit

Permalink
Merge branch 'v1.0.3'
Browse files Browse the repository at this point in the history
* 코드 리팩토링
* 개발용 성능 측정 코드 제거
  • Loading branch information
kimshinelove committed Apr 29, 2015
2 parents 151739f + ae91abd commit 9b2b1f2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "choseong-search",
"version": "1.0.2",
"version": "1.0.3",
"description": "정규식을 통한 한글 초성 검색 모듈",
"author": {
"name": "JiTae, Kim",
Expand Down
72 changes: 35 additions & 37 deletions src/ChoseongSearchPolyfill.js
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;

0 comments on commit 9b2b1f2

Please sign in to comment.