| 1 | {{{#!table align=right |
| 2 | ||04/01/21|| |
| 3 | }}} |
| 4 | = Lab <028> - 한/영타 변환기 = |
| 5 | |
| 6 | 글을 입력하면 자동으로 변환된다. |
| 7 | {{{#!html |
| 8 | <input type="text" id="txtSource" size=50><br> |
| 9 | <input type="radio" id="optEtoH" name="Mode" checked><label for="optEtoH">영타 → 한글</label> |
| 10 | <input type="radio" id="optHtoE" name="Mode"><label for="optHtoE">한타 → 영어</label><br> |
| 11 | <input type="text" id="txtConv" size=50> |
| 12 | |
| 13 | <script language="VBScript"> |
| 14 | <!-- |
| 15 | Const EngDat = "rRseEfaqQtTdwWczxvgkoiOjpuPhynbml" |
| 16 | Const HanDat = "ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎㅏㅐㅑㅒㅓㅔㅕㅖㅗㅛㅜㅠㅡㅣ" |
| 17 | Const ChoDat = "ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ" |
| 18 | Const JungDat = "ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ" |
| 19 | Const JongDat = "ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ" |
| 20 | |
| 21 | Private Sub optEtoH_OnClick() |
| 22 | txtSource_OnKeyUp |
| 23 | End Sub |
| 24 | |
| 25 | Private Sub optHtoE_OnClick() |
| 26 | txtSource_OnKeyUp |
| 27 | End Sub |
| 28 | |
| 29 | Private Sub txtSource_OnKeyUp() |
| 30 | If optEtoH.Checked Then |
| 31 | txtConv.Value = EngTypeToHan(txtSource.Value) |
| 32 | Else |
| 33 | txtConv.Value = HanTypeToEng(txtSource.Value) |
| 34 | End If |
| 35 | End Sub |
| 36 | |
| 37 | Function EngTypeToHan(Source) |
| 38 | Dim ConvText, tChr |
| 39 | Dim Cho, Jung, Jong, tVal '초성, 중성, 종성, (임시용) 초성 |
| 40 | Dim i, p |
| 41 | |
| 42 | If Len(Source) = 0 Then Exit Function |
| 43 | For i = 1 To Len(Source) |
| 44 | tChr = Mid(Source, i, 1) |
| 45 | p = InStr(EngDat, tChr) |
| 46 | If p = 0 Then '영자판이 아님 |
| 47 | If Cho Then |
| 48 | If Jung Then '초성+중성+(종성) |
| 49 | ConvText = ConvText + MakeHan(Cho - 1, Jung - 1, Jong) |
| 50 | Else '초성만 |
| 51 | ConvText = ConvText + Mid(ChoDat, Cho, 1) |
| 52 | End If |
| 53 | Else |
| 54 | If Jung Then '중성만 |
| 55 | ConvText = ConvText + Mid(JungDat, Jung, 1) |
| 56 | Else '복자음 |
| 57 | If Jong Then ConvText = ConvText + Mid(JongDat, Jong, 1) |
| 58 | End If |
| 59 | End If |
| 60 | Cho = 0: Jung = 0: Jong = 0 |
| 61 | ConvText = ConvText + tChr |
| 62 | ElseIf p < 20 Then '자음 |
| 63 | If Jung Then |
| 64 | If Cho = 0 Then '중성만 입력됨, 초성으로 |
| 65 | ConvText = ConvText + Mid(JungDat, Jung, 1) |
| 66 | Jung = 0 |
| 67 | Cho = InStr(ChoDat, Mid(HanDat, p, 1)) |
| 68 | Else '종성이다 |
| 69 | If Jong = 0 Then '종성 입력 중 |
| 70 | Jong = InStr(JongDat, Mid(HanDat, p, 1)) |
| 71 | If Jong = 0 Then '종성이 아니라 초성이다 |
| 72 | ConvText = ConvText + MakeHan(Cho - 1, Jung - 1, Jong) |
| 73 | Cho = InStr(ChoDat, Mid(HanDat, p, 1)): Jung = 0 |
| 74 | End If |
| 75 | ElseIf Jong = 1 And p = 10 Then 'ㄳ |
| 76 | Jong = 3 |
| 77 | ElseIf Jong = 4 And p = 13 Then 'ㄵ |
| 78 | Jong = 5 |
| 79 | ElseIf Jong = 4 And p = 19 Then 'ㄶ |
| 80 | Jong = 6 |
| 81 | ElseIf Jong = 8 And p = 1 Then 'ㄺ |
| 82 | Jong = 9 |
| 83 | ElseIf Jong = 8 And p = 7 Then 'ㄻ |
| 84 | Jong = 10 |
| 85 | ElseIf Jong = 8 And p = 8 Then 'ㄼ |
| 86 | Jong = 11 |
| 87 | ElseIf Jong = 8 And p = 10 Then 'ㄽ |
| 88 | Jong = 12 |
| 89 | ElseIf Jong = 8 And p = 17 Then 'ㄾ |
| 90 | Jong = 13 |
| 91 | ElseIf Jong = 8 And p = 18 Then 'ㄿ |
| 92 | Jong = 14 |
| 93 | ElseIf Jong = 8 And p = 19 Then 'ㅀ |
| 94 | Jong = 15 |
| 95 | ElseIf Jong = 17 And p = 10 Then 'ㅄ |
| 96 | Jong = 18 |
| 97 | Else '종성 입력 끝, 초성으로 |
| 98 | ConvText = ConvText + MakeHan(Cho - 1, Jung - 1, Jong) |
| 99 | Cho = InStr(ChoDat, Mid(HanDat, p, 1)) |
| 100 | Jung = 0: Jong = 0 |
| 101 | End If |
| 102 | End If |
| 103 | Else '초성 또는 (단/복)자음이다 |
| 104 | If Cho = 0 Then '초성 입력 시작 |
| 105 | If Jong Then '복자음 후 초성 |
| 106 | ConvText = ConvText + Mid(JongDat, Jong, 1) |
| 107 | Jong = 0 |
| 108 | End If |
| 109 | Cho = InStr(ChoDat, Mid(HanDat, p, 1)) |
| 110 | ElseIf Cho = 1 And p = 10 Then 'ㄳ |
| 111 | Cho = 0: Jong = 3 |
| 112 | ElseIf Cho = 3 And p = 13 Then 'ㄵ |
| 113 | Cho = 0: Jong = 5 |
| 114 | ElseIf Cho = 3 And p = 19 Then 'ㄶ |
| 115 | Cho = 0: Jong = 6 |
| 116 | ElseIf Cho = 6 And p = 1 Then 'ㄺ |
| 117 | Cho = 0: Jong = 9 |
| 118 | ElseIf Cho = 6 And p = 7 Then 'ㄻ |
| 119 | Cho = 0: Jong = 10 |
| 120 | ElseIf Cho = 6 And p = 8 Then 'ㄼ |
| 121 | Cho = 0: Jong = 11 |
| 122 | ElseIf Cho = 6 And p = 10 Then 'ㄽ |
| 123 | Cho = 0: Jong = 12 |
| 124 | ElseIf Cho = 6 And p = 17 Then 'ㄾ |
| 125 | Cho = 0: Jong = 13 |
| 126 | ElseIf Cho = 6 And p = 18 Then 'ㄿ |
| 127 | Cho = 0: Jong = 14 |
| 128 | ElseIf Cho = 6 And p = 19 Then 'ㅀ |
| 129 | Cho = 0: Jong = 15 |
| 130 | ElseIf Cho = 8 And p = 10 Then 'ㅄ |
| 131 | Cho = 0: Jong = 18 |
| 132 | Else '단자음을 연타 |
| 133 | ConvText = ConvText + Mid(ChoDat, Cho, 1) |
| 134 | Cho = InStr(ChoDat, Mid(HanDat, p, 1)) |
| 135 | End If |
| 136 | End If |
| 137 | Else '중성 |
| 138 | If Jong Then '(앞글자 종성), 초성+중성 |
| 139 | Select Case Jong '복자음 다시 분해 |
| 140 | Case 3: Jong = 1: tVal = 10 'ㄱ, ㅅ |
| 141 | Case 5: Jong = 4: tVal = 13 'ㄴ, ㅈ |
| 142 | Case 6: Jong = 4: tVal = 19 'ㄴ, ㅎ |
| 143 | Case 9: Jong = 8: tVal = 1 'ㄹ, ㄱ |
| 144 | Case 10: Jong = 8: tVal = 7 'ㄹ, ㅁ |
| 145 | Case 11: Jong = 8: tVal = 8 'ㄹ, ㅂ |
| 146 | Case 12: Jong = 8: tVal = 10 'ㄹ, ㅅ |
| 147 | Case 13: Jong = 8: tVal = 17 'ㄹ, ㅌ |
| 148 | Case 14: Jong = 8: tVal = 18 'ㄹ, ㅍ |
| 149 | Case 15: Jong = 8: tVal = 19 'ㄹ, ㅎ |
| 150 | Case 18: Jong = 17: tVal = 10 'ㅂ, ㅅ |
| 151 | Case Else '복자음 아님 |
| 152 | tVal = InStr(ChoDat, Mid(JongDat, Jong, 1)) |
| 153 | Jong = 0 |
| 154 | End Select |
| 155 | If Cho Then '앞글자가 초성+중성+(종성) |
| 156 | ConvText = ConvText + MakeHan(Cho - 1, Jung - 1, Jong) |
| 157 | Else '복자음만 있음 |
| 158 | ConvText = ConvText + Mid(JongDat, Jong, 1) |
| 159 | End If |
| 160 | Cho = tVal: Jung = 0: Jong = 0 |
| 161 | End If |
| 162 | If Jung = 0 Then '중성 입력 중 |
| 163 | Jung = InStr(JungDat, Mid(HanDat, p, 1)) |
| 164 | ElseIf Jung = 9 And p = 20 Then 'ㅘ |
| 165 | Jung = 10 |
| 166 | ElseIf Jung = 9 And p = 21 Then 'ㅙ |
| 167 | Jung = 11 |
| 168 | ElseIf Jung = 9 And p = 33 Then 'ㅚ |
| 169 | Jung = 12 |
| 170 | ElseIf Jung = 14 And p = 24 Then 'ㅝ |
| 171 | Jung = 15 |
| 172 | ElseIf Jung = 14 And p = 25 Then 'ㅞ |
| 173 | Jung = 16 |
| 174 | ElseIf Jung = 14 And p = 33 Then 'ㅟ |
| 175 | Jung = 17 |
| 176 | ElseIf Jung = 19 And p = 33 Then 'ㅢ |
| 177 | Jung = 20 |
| 178 | Else '조합 안되는 모음 입력 |
| 179 | If Cho Then '초성+중성 후 중성 |
| 180 | ConvText = ConvText + MakeHan(Cho - 1, Jung - 1, Jong) |
| 181 | Cho = 0 |
| 182 | Else '중성 후 중성 |
| 183 | ConvText = ConvText + Mid(JungDat, Jung, 1) |
| 184 | End If |
| 185 | Jung = 0 |
| 186 | ConvText = ConvText + Mid(HanDat, p, 1) |
| 187 | End If |
| 188 | End If |
| 189 | Next |
| 190 | If Cho Then '마지막 한글이 있으면 처리 |
| 191 | If Jung Then '초성+중성+(종성) |
| 192 | ConvText = ConvText + MakeHan(Cho - 1, Jung - 1, Jong) |
| 193 | Else '초성만 |
| 194 | ConvText = ConvText + Mid(ChoDat, Cho, 1) |
| 195 | End If |
| 196 | Else |
| 197 | If Jung Then '중성만 |
| 198 | ConvText = ConvText + Mid(JungDat, Jung, 1) |
| 199 | Else '복자음 |
| 200 | If Jong Then ConvText = ConvText + Mid(JongDat, Jong, 1) |
| 201 | End If |
| 202 | End If |
| 203 | |
| 204 | EngTypeToHan = ConvText |
| 205 | End Function |
| 206 | |
| 207 | Function MakeHan(nChoSung, nJungSung, nJongSung) |
| 208 | MakeHan = ChrW(&HAC00 + nChoSung * 21 * 28 + nJungSung * 28 + nJongSung) |
| 209 | End Function |
| 210 | |
| 211 | Function HanTypeToEng(Source) |
| 212 | Dim ConvText, tChr, tAsc |
| 213 | Dim Jung, Cho, Jong, tVal(5) |
| 214 | Dim i |
| 215 | |
| 216 | If Len(Source) = 0 Then Exit Function |
| 217 | For i = 1 To Len(Source) |
| 218 | tChr = Mid(Source, i, 1) |
| 219 | tAsc = AscW(tChr) |
| 220 | Cho = InStr(ChoDat, tChr) |
| 221 | Jung = InStr(JungDat, tChr) |
| 222 | Jong = InStr(JongDat, tChr) |
| 223 | |
| 224 | If &HAC00 <= tAsc And tAsc <= &HD7A3 Then |
| 225 | tAsc = tAsc - &HAC00 |
| 226 | tVal(1) = 1 + tAsc \ (21 * 28) '초성 |
| 227 | tVal(2) = 1 + (tAsc \ 28) Mod 21 '중성 |
| 228 | tVal(4) = tAsc Mod 28 '종성 |
| 229 | ElseIf Cho Then '초성 자음 |
| 230 | tVal(1) = Cho: tVal(2) = 0: tVal(4) = 0 |
| 231 | ElseIf Jung Then '중성 |
| 232 | tVal(1) = 0: tVal(2) = Jung: tVal(4) = 0 |
| 233 | ElseIf Jong Then '종성 자음 |
| 234 | tVal(1) = 0: tVal(2) = 0: tVal(4) = Jong |
| 235 | Else '한글이 아님 |
| 236 | ConvText = ConvText + tChr |
| 237 | tVal(1) = 0: tVal(2) = 0: tVal(4) = 0 |
| 238 | End If |
| 239 | |
| 240 | If tVal(1) Then ConvText = ConvText + Mid(EngDat, tVal(1), 1) |
| 241 | If tVal(2) Then |
| 242 | Select Case tVal(2) |
| 243 | Case 10: tVal(2) = 9: tVal(3) = 1 'ㅘ |
| 244 | Case 11: tVal(2) = 9: tVal(3) = 2 'ㅙ |
| 245 | Case 12: tVal(2) = 9: tVal(3) = 14 'ㅚ |
| 246 | Case 15: tVal(2) = 11: tVal(3) = 5 'ㅝ |
| 247 | Case 16: tVal(2) = 11: tVal(3) = 6 'ㅞ |
| 248 | Case 17: tVal(2) = 11: tVal(3) = 14 'ㅟ |
| 249 | Case 20: tVal(2) = 13: tVal(3) = 14 'ㅢ |
| 250 | Case Else |
| 251 | tVal(2) = InStr(HanDat, Mid(JungDat, tVal(2), 1)) - 19 |
| 252 | tVal(3) = 0 |
| 253 | End Select |
| 254 | ConvText = ConvText + Mid(EngDat, tVal(2) + 19, 1) |
| 255 | If tVal(3) Then ConvText = ConvText + Mid(EngDat, tVal(3) + 19, 1) |
| 256 | End If |
| 257 | If tVal(4) Then |
| 258 | Select Case tVal(4) |
| 259 | Case 3: tVal(4) = 1: tVal(5) = 10 'ㄳ |
| 260 | Case 5: tVal(4) = 3: tVal(5) = 13 'ㄵ |
| 261 | Case 6: tVal(4) = 3: tVal(5) = 19 'ㄶ |
| 262 | Case 9: tVal(4) = 6: tVal(5) = 1 'ㄺ |
| 263 | Case 10: tVal(4) = 6: tVal(5) = 7 'ㄻ |
| 264 | Case 11: tVal(4) = 6: tVal(5) = 8 'ㄼ |
| 265 | Case 12: tVal(4) = 6: tVal(5) = 10 'ㄽ |
| 266 | Case 13: tVal(4) = 6: tVal(5) = 17 'ㄾ |
| 267 | Case 14: tVal(4) = 6: tVal(5) = 18 'ㄿ |
| 268 | Case 15: tVal(4) = 6: tVal(5) = 19 'ㅀ |
| 269 | Case 18: tVal(4) = 8: tVal(5) = 10 'ㅄ |
| 270 | Case Else |
| 271 | tVal(4) = InStr(HanDat, Mid(JongDat, tVal(4), 1)) |
| 272 | tVal(5) = 0 |
| 273 | End Select |
| 274 | ConvText = ConvText + Mid(EngDat, tVal(4), 1) |
| 275 | If tVal(5) Then ConvText = ConvText + Mid(EngDat, tVal(5), 1) |
| 276 | End If |
| 277 | Next |
| 278 | |
| 279 | HanTypeToEng = ConvText |
| 280 | End Function |
| 281 | --> |
| 282 | </script> |
| 283 | }}} |
| 284 | ---- |
| 285 | [wiki:Lab분류] |