Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

343 lines
11 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 1997, Microsoft Corporation. All Rights Reserved.
  4. //
  5. /////////////////////////////////////////////////////////////////////////////
  6. //#include "stdafx.h"
  7. #include "pch.cxx"
  8. #include "UniToInt.h"
  9. #define NUMBER_OF_CHOSUNG 19
  10. #define NUMBER_OF_JUNGSUNG 21
  11. #define NUMBER_OF_JONGSUNG 28 // include fill code
  12. #define HANGUL_COMP_JAMO_START 0x3131
  13. #define HANGUL_COMP_JAMO_END 0x3163
  14. #define HANGUL_COMP_JAMO_START_FILL 0x3130
  15. #define HANGUL_COMP_JAMO_SIOT 0x3145
  16. #define HANGUL_START 0xAC00
  17. #define HANGUL_END 0xD7A3
  18. ///////////////////////////////////////////
  19. // HANGUL Jaso difinitions
  20. // ChoSung
  21. #define KIYEOK 1
  22. #define SSANGKIYEOK 2
  23. #define NIEUN 3
  24. #define SSANGNIEUN 4 // not used
  25. #define TIKEUT 5
  26. #define SSANGTIKEUT 6
  27. #define RIEUL 7
  28. #define SSANGRIEUL 8 // not used
  29. #define MIEUM 10
  30. #define PIEUP 11
  31. #define SSANGPIEUP 12
  32. #define SIOS 13
  33. #define SSANGSIOS 14
  34. #define IEUNG 15
  35. #define CIEUC 16
  36. #define SSANGCIEUC 17
  37. #define CHIEUCH 18
  38. #define KHIEUKH 19
  39. #define THIEUTH 20
  40. #define PHIEUPH 21
  41. #define HIEUH 22
  42. // JungSung
  43. #define A 23
  44. #define AE 24
  45. #define YA 25
  46. #define YAE 26
  47. #define EO 27
  48. #define E 28
  49. #define YEO 29
  50. #define YE 30
  51. #define O 31
  52. #define WA 33
  53. #define WAE 34
  54. #define OE 35
  55. #define YO 36
  56. #define U 37
  57. #define WEO 38
  58. #define WE 39
  59. #define WI 40
  60. #define YU 41
  61. #define EU 42
  62. #define YI 43
  63. #define I 44
  64. ////////////////////////////////////////
  65. // Cho sung mapping table
  66. static
  67. BYTE ChoSungMapTable[19] =
  68. {
  69. KIYEOK, SSANGKIYEOK,
  70. NIEUN,
  71. TIKEUT, SSANGTIKEUT,
  72. RIEUL,
  73. MIEUM,
  74. PIEUP, SSANGPIEUP,
  75. SIOS, SSANGSIOS,
  76. IEUNG,
  77. CIEUC, SSANGCIEUC,
  78. CHIEUCH,
  79. KHIEUKH,
  80. THIEUTH,
  81. PHIEUPH,
  82. HIEUH,
  83. };
  84. // Jung sung mapping table
  85. static
  86. BYTE JungSungMapTable[21] =
  87. {
  88. A, AE, YA, YAE, EO, E, YEO, YE, O, WA, WAE, OE, YO, U, WEO, WE, WI, YU, EU, YI, I,
  89. };
  90. // Jong sung mapping table
  91. static
  92. BYTE JongSungMapTable[28][2] =
  93. {
  94. { 0, 0 }, // Fill
  95. { KIYEOK, 0 },
  96. { SSANGKIYEOK, 0 },
  97. { KIYEOK, SIOS },
  98. { NIEUN, 0 },
  99. { NIEUN, CIEUC },
  100. { NIEUN, HIEUH },
  101. { TIKEUT, 0 },
  102. { RIEUL, 0 },
  103. { RIEUL, KIYEOK },
  104. { RIEUL, MIEUM },
  105. { RIEUL, PIEUP },
  106. { RIEUL, SIOS },
  107. { RIEUL, THIEUTH },
  108. { RIEUL, PHIEUPH },
  109. { RIEUL, HIEUH },
  110. { MIEUM, 0 },
  111. { PIEUP, 0 },
  112. { PIEUP, SIOS },
  113. { SIOS, 0 },
  114. { SSANGSIOS, 0 },
  115. { IEUNG, 0 },
  116. { CIEUC, 0 },
  117. { CHIEUCH, 0 },
  118. { KHIEUKH, 0 },
  119. { THIEUTH, 0 },
  120. { PHIEUPH, 0 },
  121. { HIEUH, 0 }
  122. };
  123. static
  124. BYTE JamoMapTable[51][2] =
  125. {
  126. { KIYEOK, 0 },
  127. { SSANGKIYEOK, 0 },
  128. { KIYEOK, SIOS },
  129. { NIEUN, 0 },
  130. { NIEUN, CIEUC },
  131. { NIEUN, HIEUH },
  132. { TIKEUT, 0 },
  133. { SSANGTIKEUT, 0 },
  134. { RIEUL, 0 },
  135. { RIEUL, KIYEOK },
  136. { RIEUL, MIEUM },
  137. { RIEUL, PIEUP },
  138. { RIEUL, SIOS },
  139. { RIEUL, THIEUTH },
  140. { RIEUL, PHIEUPH },
  141. { RIEUL, HIEUH },
  142. { MIEUM, 0 },
  143. { PIEUP, 0 },
  144. { SSANGPIEUP, 0 },
  145. { PIEUP, SIOS },
  146. { SIOS, 0 },
  147. { SSANGSIOS, 0 },
  148. { IEUNG, 0 },
  149. { CIEUC, 0 },
  150. { SSANGCIEUC, 0 },
  151. { CHIEUCH, 0 },
  152. { KHIEUKH, 0 },
  153. { THIEUTH, 0 },
  154. { PHIEUPH, 0 },
  155. { HIEUH, 0 },
  156. //
  157. { A, 0 },
  158. { AE, 0 },
  159. { YA, 0 },
  160. { YAE, 0 },
  161. { EO, 0 },
  162. { E, 0 },
  163. { YEO, 0 },
  164. { YE, 0 },
  165. { O, 0 },
  166. { WA, 0 },
  167. { WAE, 0 },
  168. { OE, 0 },
  169. { YO, 0 },
  170. { U, 0 },
  171. { WEO, 0 },
  172. { WE, 0 },
  173. { WI, 0 },
  174. { YU, 0 },
  175. { EU, 0 },
  176. { YI, 0 },
  177. { I, 0 }
  178. };
  179. inline static
  180. void ChosungToInternal(BYTE jamo, LPSTR lpIntStr, int &idx)
  181. {
  182. lpIntStr[idx++] = ChoSungMapTable[jamo];
  183. }
  184. inline static
  185. void JungsungToInternal(BYTE jamo, LPSTR lpIntStr, int &idx)
  186. {
  187. lpIntStr[idx++] = JungSungMapTable[jamo];
  188. }
  189. inline static
  190. void JongsungToInternal(BYTE jamo, LPSTR lpIntStr, int &idx)
  191. {
  192. if (jamo) {
  193. lpIntStr[idx++] = JongSungMapTable[jamo][0];
  194. if (JongSungMapTable[jamo][1])
  195. lpIntStr[idx++] = JongSungMapTable[jamo][1];
  196. }
  197. }
  198. inline static
  199. void JamoToInternal(BYTE jamo, LPSTR lpIntStr, int &idx)
  200. {
  201. lpIntStr[idx++] = JamoMapTable[jamo][0];
  202. if (JamoMapTable[jamo][1])
  203. lpIntStr[idx++] = JamoMapTable[jamo][1];
  204. }
  205. ///////////////////////////////////////////////////////////////////////
  206. BOOL UniToInvInternal(LPCWSTR lpUniStr, LPSTR _lpIntStr, int strLength)
  207. {
  208. int i, j, idx=0;
  209. char lpIntStr[256]; // buffer is fixed (dangerous but quick and dirty method)
  210. for (i=0; i<strLength; i++)
  211. {
  212. if (lpUniStr[i] <= HANGUL_COMP_JAMO_END && lpUniStr[i] >= HANGUL_COMP_JAMO_START)
  213. {
  214. JamoToInternal(BYTE(lpUniStr[i]-HANGUL_COMP_JAMO_START), lpIntStr, idx);
  215. continue;
  216. }
  217. ChosungToInternal(BYTE( (WORD)(lpUniStr[i]-HANGUL_START) /
  218. (NUMBER_OF_JONGSUNG*NUMBER_OF_JUNGSUNG) ),
  219. lpIntStr, idx );
  220. JungsungToInternal(BYTE( (WORD)(lpUniStr[i]-HANGUL_START) / NUMBER_OF_JONGSUNG
  221. % NUMBER_OF_JUNGSUNG ),
  222. lpIntStr, idx );
  223. JongsungToInternal(BYTE( (WORD)(lpUniStr[i]-HANGUL_START) % NUMBER_OF_JONGSUNG ),
  224. //+ NUMBER_OF_CHOSUNG + NUMBER_OF_JUNGSUNG),
  225. lpIntStr, idx ); //jongsung
  226. }
  227. // inverse processing
  228. for (i=0, j=idx-1; i<idx; i++, j--)
  229. _lpIntStr[j] = lpIntStr[i];
  230. _lpIntStr[idx] = 0;
  231. return TRUE;
  232. }
  233. BOOL UniToInternal(LPCWSTR lpUniStr, LPSTR lpIntStr, int strLength)
  234. {
  235. int i, idx=0;
  236. // char lpIntStr[256]; // buffer is fixed (dangerous but quick and dirty method)
  237. for (i=0; i<strLength; i++)
  238. {
  239. if (lpUniStr[i] <= HANGUL_COMP_JAMO_END && lpUniStr[i] >= HANGUL_COMP_JAMO_START)
  240. {
  241. JamoToInternal(BYTE(lpUniStr[i]-HANGUL_COMP_JAMO_START), lpIntStr, idx);
  242. continue;
  243. }
  244. ChosungToInternal(BYTE( (WORD)(lpUniStr[i]-HANGUL_START) /
  245. (NUMBER_OF_JONGSUNG*NUMBER_OF_JUNGSUNG) ),
  246. lpIntStr, idx );
  247. JungsungToInternal(BYTE( (WORD)(lpUniStr[i]-HANGUL_START) / NUMBER_OF_JONGSUNG
  248. % NUMBER_OF_JUNGSUNG),
  249. lpIntStr, idx );
  250. JongsungToInternal(BYTE( (WORD)(lpUniStr[i]-HANGUL_START) % NUMBER_OF_JONGSUNG ),
  251. //+ NUMBER_OF_CHOSUNG + NUMBER_OF_JUNGSUNG),
  252. lpIntStr, idx ); //jongsung
  253. }
  254. lpIntStr[idx] = 0;
  255. return TRUE;
  256. }
  257. /*
  258. BOOL UniToInvInternal(LPCWSTR lpUniStr, LPSTR _lpIntStr, int strLength)
  259. {
  260. int i, j, idx=0;
  261. char lpIntStr[256]; // buffer is fixed (dangerous but quick and dirty method)
  262. for (i=0; i<strLength; i++)
  263. {
  264. if (lpUniStr[i] <= HANGUL_COMP_JAMO_END && lpUniStr[i] >= HANGUL_COMP_JAMO_START)
  265. {
  266. if (lpUniStr[i] <= HANGUL_COMP_JAMO_SIOT)
  267. JamoToInternal(lpUniStr[i], lpIntStr, idx);
  268. else lpIntStr[idx++] = BYTE(lpUniStr[i] - HANGUL_COMP_JAMO_SIOT + 10);
  269. continue;
  270. }
  271. lpIntStr[idx++] = BYTE( (WORD)(lpUniStr[i]-HANGUL_START) /
  272. (NUMBER_OF_JONGSUNG*NUMBER_OF_JUNGSUNG) ) + 1;//chosung
  273. lpIntStr[idx++] = BYTE( (WORD)(lpUniStr[i]-HANGUL_START) / NUMBER_OF_JONGSUNG
  274. % NUMBER_OF_JUNGSUNG + NUMBER_OF_CHOSUNG ) + 1; //jungsung
  275. JongsungToInternal(BYTE( (WORD)(lpUniStr[i]-HANGUL_START) % NUMBER_OF_JONGSUNG ),
  276. //+ NUMBER_OF_CHOSUNG + NUMBER_OF_JUNGSUNG),
  277. lpIntStr, idx ); //jongsung
  278. }
  279. // inverse processing
  280. for (i=0, j=idx-1; i<idx; i++, j--)
  281. _lpIntStr[j] = lpIntStr[i];
  282. _lpIntStr[idx] = 0;
  283. return TRUE;
  284. }
  285. BOOL UniToInternal(LPCWSTR lpUniStr, LPSTR lpIntStr, int strLength)
  286. {
  287. int i, idx=0;
  288. // char lpIntStr[256]; // buffer is fixed (dangerous but quick and dirty method)
  289. for (i=0; i<strLength; i++)
  290. {
  291. if (lpUniStr[i] <= HANGUL_COMP_JAMO_END && lpUniStr[i] >= HANGUL_COMP_JAMO_START)
  292. {
  293. if (lpUniStr[i] <= HANGUL_COMP_JAMO_SIOT)
  294. JamoToInternal(lpUniStr[i], lpIntStr, idx);
  295. else lpIntStr[idx++] = BYTE(lpUniStr[i] - HANGUL_COMP_JAMO_SIOT + 10);
  296. continue;
  297. }
  298. lpIntStr[idx++] = BYTE( (WORD)(lpUniStr[i]-HANGUL_START) /
  299. (NUMBER_OF_JONGSUNG*NUMBER_OF_JUNGSUNG) ) + 1;//chosung
  300. lpIntStr[idx++] = BYTE( (WORD)(lpUniStr[i]-HANGUL_START) / NUMBER_OF_JONGSUNG
  301. % NUMBER_OF_JUNGSUNG + NUMBER_OF_CHOSUNG ) + 1; //jungsung
  302. JongsungToInternal(BYTE( (WORD)(lpUniStr[i]-HANGUL_START) % NUMBER_OF_JONGSUNG ),
  303. //+ NUMBER_OF_CHOSUNG + NUMBER_OF_JUNGSUNG),
  304. lpIntStr, idx ); //jongsung
  305. }
  306. lpIntStr[idx] = 0;
  307. return TRUE;
  308. }
  309. */