가상 키보드를 만들다가 만든건데... 클라이언트가 2.0을 원해서 2.0으로 만들었습니다.
테스트는 좀 더 충분히 해봐야 하지만... 뭐, 그야 각자에 맡기고....
class com.minarto.text.CreateKorean { function CreateKorean() { }
/* _last_str : 마지막 글자 _new_str : 합쳐질 글자 */ static function join(_last_str:String, _new_str:String):String { var lastCode:Number = _last_str.charCodeAt(0); // 마지막 글자의 문자코드 var newCode:Number = _new_str.charCodeAt(0); // 합쳐질 글자의 문자코드
if(lastCode >= 12593 && lastCode <= 12622) // 이전 글자가 초성일 때 { _last_str = join1(_last_str, _new_str); } else if(lastCode >= 12623 && lastCode <= 12643) // 이전 글자가 중성일 때 { _last_str = join2(_last_str, _new_str); } else if((lastCode - 44032) % 28 == 0 && (lastCode >= 44032 && lastCode <= 55176)) // 이전 글자가 중성인 글자일 때 { _last_str = join3(_last_str, _new_str); } else if((lastCode - 44032) % 28 >= 1 && (lastCode >= 44033 && lastCode <= 55203)) // 이전 글자가 종성인 글자일 때 { _last_str = join4(_last_str, _new_str); } else { _last_str += _new_str; } return _last_str; }
// 이전 글자가 초성일 때 static function join1(_last_str:String, _new_str:String):String { var lastCode:Number = _last_str.charCodeAt(0); // 마지막 글자의 문자코드 var newCode:Number = _new_str.charCodeAt(0); // 합쳐질 글자의 문자코드
if(newCode >= 12593 && newCode <= 12622) // 뒤에 초성이 붙을 때 { if(_last_str == "ㄱ") // ㄱ 뒤에 초성이 붙을 때 { switch(_new_str) { case "ㅅ" : _last_str = "ㄳ"; break;
default : _last_str += _new_str; } } else if(_last_str == "ㄴ") // ㄴ 뒤에 초성이 붙을 때 { switch(_new_str) { case "ㅈ" : _last_str = "ㄵ"; break; case "ㅎ" : _last_str = "ㄶ"; break;
default : _last_str += _new_str; } } else if(_last_str == "ㄹ") // ㄹ 뒤에 초성이 붙을 때 { switch(_new_str) { case "ㄱ" : _last_str = "ㄺ"; break; case "ㅁ" : _last_str = "ㄻ"; break; case "ㅂ" : _last_str = "ㄼ"; break; case "ㅅ" : _last_str = "ㄽ"; break; case "ㅌ" : _last_str = "ㄾ"; break; case "ㅍ" : _last_str = "ㄿ"; break; case "ㅎ" : _last_str = "ㅀ"; break;
default : _last_str += _new_str; } } else if(_last_str == "ㅂ") // ㄹ 뒤에 초성이 붙을 때 { switch(_new_str) { case "ㅅ" : _last_str = "ㅄ"; break;
// 이전 글자가 중성일 때 static function join2(_last_str:String, _new_str:String):String { var lastCode:Number = _last_str.charCodeAt(0); // 마지막 글자의 문자코드 var newCode:Number = _new_str.charCodeAt(0); // 합쳐질 글자의 문자코드
if(newCode >= 12623 && newCode <= 12643) // 뒤에 중성이 붙을 때 { if(_last_str == "ㅗ") { switch(_new_str) // 초성 뒤에 중성이 붙을 때 { case "ㅏ" : _last_str = "ㅘ"; break; case "ㅐ" : _last_str = "ㅙ"; break; case "ㅣ" : _last_str = "ㅚ"; break;
default : _last_str += _new_str; } } else if(_last_str == "ㅜ") { switch(_new_str) // 초성 뒤에 중성이 붙을 때 { case "ㅓ" : _last_str = "ㅝ"; break; case "ㅔ" : _last_str = "ㅞ"; break; case "ㅣ" : _last_str = "ㅟ"; break;
// 이전 글자가 중성인 글자일 때 static function join3(_last_str:String, _new_str:String):String { var lastCode:Number = _last_str.charCodeAt(0); // 마지막 글자의 문자코드 var newCode:Number = _new_str.charCodeAt(0); // 합쳐질 글자의 문자코드
if(newCode >= 12623 && newCode <= 12643) // 뒤에 모음이 붙을 때 { // 모음이 ㅗ 로 끝나고 모음이 붙을 때 if((lastCode - 44256) % 588 == 0 && (_new_str == "ㅏ" || _new_str == "ㅐ" || _new_str == "ㅣ")) { switch(_new_str) // 초성 뒤에 중성이 붙을 때 { case "ㅏ" : _last_str = String.fromCharCode(lastCode + 28); break; case "ㅐ" : _last_str = String.fromCharCode(lastCode + 28 * 2); break; case "ㅣ" : _last_str = String.fromCharCode(lastCode + 28 * 3); break;
default : _last_str += _new_str; } } // 모음이 ㅜ 로 끝나고 모음이 붙을 때 else if((lastCode - 44396) % 588 == 0 && (_new_str == "ㅓ" || _new_str == "ㅔ" || _new_str == "ㅣ")) { switch(_new_str) // 초성 뒤에 중성이 붙을 때 { case "ㅓ" : _last_str = String.fromCharCode(lastCode + 28); break; case "ㅔ" : _last_str = String.fromCharCode(lastCode + 28 * 2); break; case "ㅣ" : _last_str = String.fromCharCode(lastCode + 28 * 3); break;
default : _last_str += _new_str; } } // 모음이 ㅡ 로 끝나고 모음이 붙을 때 else if((lastCode - 44536) % 588 == 0 && (_new_str == "ㅣ")) { switch(_new_str) // 초성 뒤에 중성이 붙을 때 { case "ㅣ" : _last_str = String.fromCharCode(lastCode + 28); break;
// 이전 글자가 종성인 글자일 때 static function join4(_last_str:String, _new_str:String):String { var lastCode:Number = _last_str.charCodeAt(0); // 마지막 글자의 문자코드 var newCode:Number = _new_str.charCodeAt(0); // 합쳐질 글자의 문자코드
if(newCode >= 12623 && newCode <= 12643) // 뒤에 모음이 붙을 때 { switch((lastCode - 44032) % 28) { case 1 : // ㄱ 종성일 때 _last_str = String.fromCharCode(lastCode - 1) + join("ㄱ", _new_str); break; case 2 : // ㄲ 종성일 때 _last_str = String.fromCharCode(lastCode - 2) + join("ㄲ", _new_str); join() break; case 3 : // ㄳ 종성일 때 _last_str = String.fromCharCode(lastCode - 2) + join("ㅅ", _new_str); break; case 4 : // ㄴ 종성일 때 _last_str = String.fromCharCode(lastCode - 4) + join("ㄴ", _new_str); break; case 5 : // ㄵ 종성일 때 _last_str = String.fromCharCode(lastCode - 1) + join("ㅈ", _new_str); break; case 6 : // ㄶ 종성일 때 _last_str = String.fromCharCode(lastCode - 2) + join("ㅎ", _new_str); break; case 7 : // ㄷ 종성일 때 _last_str = String.fromCharCode(lastCode - 7) + join("ㄷ", _new_str); break; case 8 : // ㄹ 종성일 때 _last_str = String.fromCharCode(lastCode - 8) + join("ㄹ", _new_str); break; case 9 : // ㄺ 종성일 때 _last_str = String.fromCharCode(lastCode - 1) + join("ㄱ", _new_str); break; case 10 : // ㄻ 종성일 때 _last_str = String.fromCharCode(lastCode - 2) + join("ㅁ", _new_str); break; case 11 : // ㄼ 종성일 때 _last_str = String.fromCharCode(lastCode - 3) + join("ㅂ", _new_str); break; case 12 : // ㄽ 종성일 때 _last_str = String.fromCharCode(lastCode - 4) + join("ㅅ", _new_str); break; case 13 : // ㄾ 종성일 때 _last_str = String.fromCharCode(lastCode - 5) + join("ㅌ", _new_str); break; case 14 : // ㄿ 종성일 때 _last_str = String.fromCharCode(lastCode - 6) + join("ㅍ", _new_str); break; case 15 : // ㅀ 종성일 때 _last_str = String.fromCharCode(lastCode - 7) + join("ㅎ", _new_str); break; case 16 : // ㅁ 종성일 때 _last_str = String.fromCharCode(lastCode - 16) + join("ㅁ", _new_str); break; case 17 : // ㅂ 종성일 때 _last_str = String.fromCharCode(lastCode - 17) + join("ㅂ", _new_str); break; case 18 : // ㅄ 종성일 때 _last_str = String.fromCharCode(lastCode - 1) + join("ㅅ", _new_str); break; case 19 : // ㅅ 종성일 때 _last_str = String.fromCharCode(lastCode - 19) + join("ㅅ", _new_str); break; case 20 : // ㅆ 종성일 때 _last_str = String.fromCharCode(lastCode - 20) + join("ㅆ", _new_str); break; case 21 : // ㅇ 종성일 때 _last_str = String.fromCharCode(lastCode - 21) + join("ㅇ", _new_str); break; case 22 : // ㅈ 종성일 때 _last_str = String.fromCharCode(lastCode - 22) + join("ㅈ", _new_str); break; case 23 : // ㅊ 종성일 때 _last_str = String.fromCharCode(lastCode - 23) + join("ㅊ", _new_str); break; case 24 : // ㅋ 종성일 때 _last_str = String.fromCharCode(lastCode - 24) + join("ㅋ", _new_str); break; case 25 : // ㅌ 종성일 때 _last_str = String.fromCharCode(lastCode - 25) + join("ㅌ", _new_str); break; case 26 : // ㅍ 종성일 때 _last_str = String.fromCharCode(lastCode - 26) + join("ㅍ", _new_str); break; case 27 : // ㅎ 종성일 때 _last_str = String.fromCharCode(lastCode - 27) + join("ㅎ", _new_str); break;
default : _last_str += _new_str; } } else if(newCode >= 12593 && newCode <= 12622) // 뒤에 자음이 붙을 때 { if((lastCode - 44033) % 28 == 0) // ㄱ 종성일 때 { switch(_new_str) { case "ㅅ" : // 종성일 때 _last_str = String.fromCharCode(lastCode + 2); break;
default : _last_str += _new_str; } } else if((lastCode - 44036) % 28 == 0) // ㄴ 종성일 때 { switch(_new_str) { case "ㅈ" : // 종성일 때 _last_str = String.fromCharCode(lastCode + 1); break; case "ㅎ" : // 종성일 때 _last_str = String.fromCharCode(lastCode + 2); break;
default : _last_str += _new_str; } } else if((lastCode - 44040) % 28 == 0) // ㄹ 종성일 때 { switch(_new_str) { case "ㄱ" : // 종성일 때 _last_str = String.fromCharCode(lastCode + 1); break; case "ㅁ" : // 종성일 때 _last_str = String.fromCharCode(lastCode + 2); break; case "ㅂ" : // 종성일 때 _last_str = String.fromCharCode(lastCode + 3); break; case "ㅅ" : // 종성일 때 _last_str = String.fromCharCode(lastCode + 4); break; case "ㅌ" : // 종성일 때 _last_str = String.fromCharCode(lastCode + 5); break; case "ㅍ" : // 종성일 때 _last_str = String.fromCharCode(lastCode + 6); break; case "ㅎ" : // 종성일 때 _last_str = String.fromCharCode(lastCode + 7); break;