towlower.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /* Copyright (c) 2002 Red Hat Incorporated.
  2. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. Redistributions of source code must retain the above copyright
  6. notice, this list of conditions and the following disclaimer.
  7. Redistributions in binary form must reproduce the above copyright
  8. notice, this list of conditions and the following disclaimer in the
  9. documentation and/or other materials provided with the distribution.
  10. The name of Red Hat Incorporated may not be used to endorse
  11. or promote products derived from this software without specific
  12. prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  14. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
  17. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  20. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. int qspToWLower(int c)
  25. {
  26. if (c < 0x100)
  27. {
  28. if ( (c >= 0x0041 && c <= 0x005a) ||
  29. (c >= 0x00c0 && c <= 0x00de))
  30. return (c + 0x20);
  31. if (c == 0x00b5)
  32. return 0x03bc;
  33. return c;
  34. }
  35. else if (c < 0x300)
  36. {
  37. if ( (c >= 0x0100 && c <= 0x012e) ||
  38. (c >= 0x0132 && c <= 0x0136) ||
  39. (c >= 0x014a && c <= 0x0176) ||
  40. (c >= 0x01de && c <= 0x01ee) ||
  41. (c >= 0x01f8 && c <= 0x021e) ||
  42. (c >= 0x0222 && c <= 0x0232))
  43. {
  44. if (! (c & 0x01))
  45. return (c + 1);
  46. return c;
  47. }
  48. if ( (c >= 0x0139 && c <= 0x0147) ||
  49. (c >= 0x01cd && c <= 0x91db))
  50. {
  51. if (c & 0x01)
  52. return (c + 1);
  53. return c;
  54. }
  55. if (c >= 0x178 && c <= 0x01f7)
  56. {
  57. int k;
  58. switch (c)
  59. {
  60. case 0x0178:
  61. k = 0x00ff;
  62. break;
  63. case 0x0179:
  64. case 0x017b:
  65. case 0x017d:
  66. case 0x0182:
  67. case 0x0184:
  68. case 0x0187:
  69. case 0x018b:
  70. case 0x0191:
  71. case 0x0198:
  72. case 0x01a0:
  73. case 0x01a2:
  74. case 0x01a4:
  75. case 0x01a7:
  76. case 0x01ac:
  77. case 0x01af:
  78. case 0x01b3:
  79. case 0x01b5:
  80. case 0x01b8:
  81. case 0x01bc:
  82. case 0x01c5:
  83. case 0x01c8:
  84. case 0x01cb:
  85. case 0x01cd:
  86. case 0x01cf:
  87. case 0x01d1:
  88. case 0x01d3:
  89. case 0x01d5:
  90. case 0x01d7:
  91. case 0x01d9:
  92. case 0x01db:
  93. case 0x01f2:
  94. case 0x01f4:
  95. k = c + 1;
  96. break;
  97. case 0x017f:
  98. k = 0x0073;
  99. break;
  100. case 0x0181:
  101. k = 0x0253;
  102. break;
  103. case 0x0186:
  104. k = 0x0254;
  105. break;
  106. case 0x0189:
  107. k = 0x0256;
  108. break;
  109. case 0x018a:
  110. k = 0x0257;
  111. break;
  112. case 0x018e:
  113. k = 0x01dd;
  114. break;
  115. case 0x018f:
  116. k = 0x0259;
  117. break;
  118. case 0x0190:
  119. k = 0x025b;
  120. break;
  121. case 0x0193:
  122. k = 0x0260;
  123. break;
  124. case 0x0194:
  125. k = 0x0263;
  126. break;
  127. case 0x0196:
  128. k = 0x0269;
  129. break;
  130. case 0x0197:
  131. k = 0x0268;
  132. break;
  133. case 0x019c:
  134. k = 0x026f;
  135. break;
  136. case 0x019d:
  137. k = 0x0272;
  138. break;
  139. case 0x019f:
  140. k = 0x0275;
  141. break;
  142. case 0x01a6:
  143. k = 0x0280;
  144. break;
  145. case 0x01a9:
  146. k = 0x0283;
  147. break;
  148. case 0x01ae:
  149. k = 0x0288;
  150. break;
  151. case 0x01b1:
  152. k = 0x028a;
  153. break;
  154. case 0x01b2:
  155. k = 0x028b;
  156. break;
  157. case 0x01b7:
  158. k = 0x0292;
  159. break;
  160. case 0x01c4:
  161. case 0x01c7:
  162. case 0x01ca:
  163. case 0x01f1:
  164. k = c + 2;
  165. break;
  166. case 0x01f6:
  167. k = 0x0195;
  168. break;
  169. case 0x01f7:
  170. k = 0x01bf;
  171. break;
  172. default:
  173. k = 0;
  174. }
  175. if (k != 0)
  176. return k;
  177. }
  178. if (c == 0x0220)
  179. return 0x019e;
  180. }
  181. else if (c < 0x0400)
  182. {
  183. if (c >= 0x0391 && c <= 0x03ab && c != 0x03a2)
  184. return (c + 0x20);
  185. if (c >= 0x03d8 && c <= 0x03ee && ! (c & 0x01))
  186. return (c + 1);
  187. if (c >= 0x0386 && c <= 0x03f5)
  188. {
  189. int k;
  190. switch (c)
  191. {
  192. case 0x0386:
  193. k = 0x03ac;
  194. break;
  195. case 0x0388:
  196. k = 0x03ad;
  197. break;
  198. case 0x0389:
  199. k = 0x03ae;
  200. break;
  201. case 0x038a:
  202. k = 0x03af;
  203. break;
  204. case 0x038c:
  205. k = 0x03cc;
  206. break;
  207. case 0x038e:
  208. k = 0x03cd;
  209. break;
  210. case 0x038f:
  211. k = 0x038f;
  212. break;
  213. case 0x03c2:
  214. k = 0x03c3;
  215. break;
  216. case 0x03d0:
  217. k = 0x03b2;
  218. break;
  219. case 0x03d1:
  220. k = 0x03b8;
  221. break;
  222. case 0x03d5:
  223. k = 0x03c6;
  224. break;
  225. case 0x03d6:
  226. k = 0x03c0;
  227. break;
  228. case 0x03f0:
  229. k = 0x03ba;
  230. break;
  231. case 0x03f1:
  232. k = 0x03c1;
  233. break;
  234. case 0x03f2:
  235. k = 0x03c3;
  236. break;
  237. case 0x03f4:
  238. k = 0x03b8;
  239. break;
  240. case 0x03f5:
  241. k = 0x03b5;
  242. break;
  243. default:
  244. k = 0;
  245. }
  246. if (k != 0)
  247. return k;
  248. }
  249. if (c == 0x0345)
  250. return 0x03b9;
  251. }
  252. else if (c < 0x500)
  253. {
  254. if (c >= 0x0400 && c <= 0x040f)
  255. return (c + 0x50);
  256. if (c >= 0x0410 && c <= 0x042f)
  257. return (c + 0x20);
  258. if ( (c >= 0x0460 && c <= 0x0480) ||
  259. (c >= 0x048a && c <= 0x04be) ||
  260. (c >= 0x04d0 && c <= 0x04f4) ||
  261. (c == 0x04f8))
  262. {
  263. if (! (c & 0x01))
  264. return (c + 1);
  265. return c;
  266. }
  267. if (c >= 0x04c1 && c <= 0x04cd)
  268. {
  269. if (c & 0x01)
  270. return (c + 1);
  271. return c;
  272. }
  273. }
  274. else if (c < 0x1f00)
  275. {
  276. if ( (c >= 0x0500 && c <= 0x050e) ||
  277. (c >= 0x1e00 && c <= 0x1e94) ||
  278. (c >= 0x1ea0 && c <= 0x1ef8))
  279. {
  280. if (! (c & 0x01))
  281. return (c + 1);
  282. return c;
  283. }
  284. if (c >= 0x0531 && c <= 0x0556)
  285. return (c + 0x30);
  286. if (c == 0x1e9b)
  287. return 0x1e61;
  288. }
  289. else if (c < 0x2000)
  290. {
  291. if ( (c >= 0x1f08 && c <= 0x1f0f) ||
  292. (c >= 0x1f18 && c <= 0x1f1d) ||
  293. (c >= 0x1f28 && c <= 0x1f2f) ||
  294. (c >= 0x1f38 && c <= 0x1f3f) ||
  295. (c >= 0x1f48 && c <= 0x1f4d) ||
  296. (c >= 0x1f68 && c <= 0x1f6f) ||
  297. (c >= 0x1f88 && c <= 0x1f8f) ||
  298. (c >= 0x1f98 && c <= 0x1f9f) ||
  299. (c >= 0x1fa8 && c <= 0x1faf))
  300. return (c - 0x08);
  301. if (c >= 0x1f59 && c <= 0x1f5f)
  302. {
  303. if (c & 0x01)
  304. return (c - 0x08);
  305. return c;
  306. }
  307. if (c >= 0x1fb8 && c <= 0x1ffc)
  308. {
  309. int k;
  310. switch (c)
  311. {
  312. case 0x1fb8:
  313. case 0x1fb9:
  314. case 0x1fd8:
  315. case 0x1fd9:
  316. case 0x1fe8:
  317. case 0x1fe9:
  318. k = c - 0x08;
  319. break;
  320. case 0x1fba:
  321. case 0x1fbb:
  322. k = c - 0x4a;
  323. break;
  324. case 0x1fbc:
  325. k = 0x1fb3;
  326. break;
  327. case 0x1fbe:
  328. k = 0x03b9;
  329. break;
  330. case 0x1fc8:
  331. case 0x1fc9:
  332. case 0x1fca:
  333. case 0x1fcb:
  334. k = c - 0x56;
  335. break;
  336. case 0x1fcc:
  337. k = 0x1fc3;
  338. break;
  339. case 0x1fda:
  340. case 0x1fdb:
  341. k = c - 0x64;
  342. break;
  343. case 0x1fea:
  344. case 0x1feb:
  345. k = c - 0x70;
  346. break;
  347. case 0x1fec:
  348. k = 0x1fe5;
  349. break;
  350. case 0x1ffa:
  351. case 0x1ffb:
  352. k = c - 0x7e;
  353. break;
  354. case 0x1ffc:
  355. k = 0x1ff3;
  356. break;
  357. default:
  358. k = 0;
  359. }
  360. if (k != 0)
  361. return k;
  362. }
  363. }
  364. else
  365. {
  366. if (c >= 0x2160 && c <= 0x216f)
  367. return (c + 0x10);
  368. if (c >= 0x24b6 && c <= 0x24cf)
  369. return (c + 0x1a);
  370. if (c >= 0xff21 && c <= 0xff3a)
  371. return (c + 0x20);
  372. if (c >= 0x10400 && c <= 0x10425)
  373. return (c + 0x28);
  374. if (c == 0x2126)
  375. return 0x03c9;
  376. if (c == 0x212a)
  377. return 0x006b;
  378. if (c == 0x212b)
  379. return 0x00e5;
  380. }
  381. return c;
  382. }