이찬

조사를 지정해주는 js파일

1 +
2 + var _f = [
3 + function(string) { //을/를 구분
4 + return _hasJong(string) ? '을' : '를';
5 + },
6 + function(string){ //은/는 구분
7 + return _hasJong(string) ? '은' : '는';
8 + },
9 + function(string){ //이/가 구분
10 + return _hasJong(string) ? '이' : '가';
11 + },
12 + function(string){ //와/과 구분
13 + return _hasJong(string) ? '과' : '와';
14 + }
15 + ],
16 + _formats = {
17 + '을/를' : _f[0],
18 + '을' : _f[0],
19 + '를' : _f[0],
20 + '을를' : _f[0],
21 + '은/는' : _f[1],
22 + '은' : _f[1],
23 + '는' : _f[1],
24 + '은는' : _f[1],
25 + '이/가' : _f[2],
26 + '이' : _f[2],
27 + '가' : _f[2],
28 + '이가' : _f[2],
29 + '와/과' : _f[3],
30 + '와' : _f[3],
31 + '과' : _f[3],
32 + '와과' : _f[3]
33 + };
34 +
35 + function _hasJong(string){ //string의 마지막 글자가 받침을 가지는지 확인
36 + string = string.charCodeAt(string.length - 1);
37 + return (string - 0xac00) % 28 > 0;
38 + }
39 +
40 + var josa = {
41 + c: function(word, format){
42 + if (typeof _formats[format] === 'undefined') throw 'Invalid format!';
43 + return _formats[format](word);
44 + },
45 + r: function(word, format) {
46 + return word + josa.c(word, format);
47 + }
48 + };