nsMBCSSM.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is mozilla.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #include "nsCodingStateMachine.h"
  38. /*
  39. Modification from frank tang's original work:
  40. . 0x00 is allowed as a legal character. Since some web pages contains this char in
  41. text stream.
  42. */
  43. // BIG5
  44. static const PRUint32 BIG5_cls [ 256 / 8 ] = {
  45. //PCK4BITS(0,1,1,1,1,1,1,1), // 00 - 07
  46. PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07 //allow 0x00 as legal value
  47. PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f
  48. PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17
  49. PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f
  50. PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27
  51. PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f
  52. PCK4BITS(1,1,1,1,1,1,1,1), // 30 - 37
  53. PCK4BITS(1,1,1,1,1,1,1,1), // 38 - 3f
  54. PCK4BITS(2,2,2,2,2,2,2,2), // 40 - 47
  55. PCK4BITS(2,2,2,2,2,2,2,2), // 48 - 4f
  56. PCK4BITS(2,2,2,2,2,2,2,2), // 50 - 57
  57. PCK4BITS(2,2,2,2,2,2,2,2), // 58 - 5f
  58. PCK4BITS(2,2,2,2,2,2,2,2), // 60 - 67
  59. PCK4BITS(2,2,2,2,2,2,2,2), // 68 - 6f
  60. PCK4BITS(2,2,2,2,2,2,2,2), // 70 - 77
  61. PCK4BITS(2,2,2,2,2,2,2,1), // 78 - 7f
  62. PCK4BITS(4,4,4,4,4,4,4,4), // 80 - 87
  63. PCK4BITS(4,4,4,4,4,4,4,4), // 88 - 8f
  64. PCK4BITS(4,4,4,4,4,4,4,4), // 90 - 97
  65. PCK4BITS(4,4,4,4,4,4,4,4), // 98 - 9f
  66. PCK4BITS(4,3,3,3,3,3,3,3), // a0 - a7
  67. PCK4BITS(3,3,3,3,3,3,3,3), // a8 - af
  68. PCK4BITS(3,3,3,3,3,3,3,3), // b0 - b7
  69. PCK4BITS(3,3,3,3,3,3,3,3), // b8 - bf
  70. PCK4BITS(3,3,3,3,3,3,3,3), // c0 - c7
  71. PCK4BITS(3,3,3,3,3,3,3,3), // c8 - cf
  72. PCK4BITS(3,3,3,3,3,3,3,3), // d0 - d7
  73. PCK4BITS(3,3,3,3,3,3,3,3), // d8 - df
  74. PCK4BITS(3,3,3,3,3,3,3,3), // e0 - e7
  75. PCK4BITS(3,3,3,3,3,3,3,3), // e8 - ef
  76. PCK4BITS(3,3,3,3,3,3,3,3), // f0 - f7
  77. PCK4BITS(3,3,3,3,3,3,3,0) // f8 - ff
  78. };
  79. static const PRUint32 BIG5_st [ 3] = {
  80. PCK4BITS(eError,eStart,eStart, 3,eError,eError,eError,eError),//00-07
  81. PCK4BITS(eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError),//08-0f
  82. PCK4BITS(eError,eStart,eStart,eStart,eStart,eStart,eStart,eStart) //10-17
  83. };
  84. static const PRUint32 Big5CharLenTable[] = {0, 1, 1, 2, 0};
  85. SMModel const Big5SMModel = {
  86. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, BIG5_cls },
  87. 5,
  88. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, BIG5_st },
  89. Big5CharLenTable,
  90. "BIG5",
  91. };
  92. static const PRUint32 EUCJP_cls [ 256 / 8 ] = {
  93. //PCK4BITS(5,4,4,4,4,4,4,4), // 00 - 07
  94. PCK4BITS(4,4,4,4,4,4,4,4), // 00 - 07
  95. PCK4BITS(4,4,4,4,4,4,5,5), // 08 - 0f
  96. PCK4BITS(4,4,4,4,4,4,4,4), // 10 - 17
  97. PCK4BITS(4,4,4,5,4,4,4,4), // 18 - 1f
  98. PCK4BITS(4,4,4,4,4,4,4,4), // 20 - 27
  99. PCK4BITS(4,4,4,4,4,4,4,4), // 28 - 2f
  100. PCK4BITS(4,4,4,4,4,4,4,4), // 30 - 37
  101. PCK4BITS(4,4,4,4,4,4,4,4), // 38 - 3f
  102. PCK4BITS(4,4,4,4,4,4,4,4), // 40 - 47
  103. PCK4BITS(4,4,4,4,4,4,4,4), // 48 - 4f
  104. PCK4BITS(4,4,4,4,4,4,4,4), // 50 - 57
  105. PCK4BITS(4,4,4,4,4,4,4,4), // 58 - 5f
  106. PCK4BITS(4,4,4,4,4,4,4,4), // 60 - 67
  107. PCK4BITS(4,4,4,4,4,4,4,4), // 68 - 6f
  108. PCK4BITS(4,4,4,4,4,4,4,4), // 70 - 77
  109. PCK4BITS(4,4,4,4,4,4,4,4), // 78 - 7f
  110. PCK4BITS(5,5,5,5,5,5,5,5), // 80 - 87
  111. PCK4BITS(5,5,5,5,5,5,1,3), // 88 - 8f
  112. PCK4BITS(5,5,5,5,5,5,5,5), // 90 - 97
  113. PCK4BITS(5,5,5,5,5,5,5,5), // 98 - 9f
  114. PCK4BITS(5,2,2,2,2,2,2,2), // a0 - a7
  115. PCK4BITS(2,2,2,2,2,2,2,2), // a8 - af
  116. PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7
  117. PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf
  118. PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7
  119. PCK4BITS(2,2,2,2,2,2,2,2), // c8 - cf
  120. PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7
  121. PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df
  122. PCK4BITS(0,0,0,0,0,0,0,0), // e0 - e7
  123. PCK4BITS(0,0,0,0,0,0,0,0), // e8 - ef
  124. PCK4BITS(0,0,0,0,0,0,0,0), // f0 - f7
  125. PCK4BITS(0,0,0,0,0,0,0,5) // f8 - ff
  126. };
  127. static const PRUint32 EUCJP_st [ 5] = {
  128. PCK4BITS( 3, 4, 3, 5,eStart,eError,eError,eError),//00-07
  129. PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f
  130. PCK4BITS(eItsMe,eItsMe,eStart,eError,eStart,eError,eError,eError),//10-17
  131. PCK4BITS(eError,eError,eStart,eError,eError,eError, 3,eError),//18-1f
  132. PCK4BITS( 3,eError,eError,eError,eStart,eStart,eStart,eStart) //20-27
  133. };
  134. static const PRUint32 EUCJPCharLenTable[] = {2, 2, 2, 3, 1, 0};
  135. const SMModel EUCJPSMModel = {
  136. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCJP_cls },
  137. 6,
  138. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCJP_st },
  139. EUCJPCharLenTable,
  140. "EUC-JP",
  141. };
  142. static const PRUint32 EUCKR_cls [ 256 / 8 ] = {
  143. //PCK4BITS(0,1,1,1,1,1,1,1), // 00 - 07
  144. PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07
  145. PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f
  146. PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17
  147. PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f
  148. PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27
  149. PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f
  150. PCK4BITS(1,1,1,1,1,1,1,1), // 30 - 37
  151. PCK4BITS(1,1,1,1,1,1,1,1), // 38 - 3f
  152. PCK4BITS(1,1,1,1,1,1,1,1), // 40 - 47
  153. PCK4BITS(1,1,1,1,1,1,1,1), // 48 - 4f
  154. PCK4BITS(1,1,1,1,1,1,1,1), // 50 - 57
  155. PCK4BITS(1,1,1,1,1,1,1,1), // 58 - 5f
  156. PCK4BITS(1,1,1,1,1,1,1,1), // 60 - 67
  157. PCK4BITS(1,1,1,1,1,1,1,1), // 68 - 6f
  158. PCK4BITS(1,1,1,1,1,1,1,1), // 70 - 77
  159. PCK4BITS(1,1,1,1,1,1,1,1), // 78 - 7f
  160. PCK4BITS(0,0,0,0,0,0,0,0), // 80 - 87
  161. PCK4BITS(0,0,0,0,0,0,0,0), // 88 - 8f
  162. PCK4BITS(0,0,0,0,0,0,0,0), // 90 - 97
  163. PCK4BITS(0,0,0,0,0,0,0,0), // 98 - 9f
  164. PCK4BITS(0,2,2,2,2,2,2,2), // a0 - a7
  165. PCK4BITS(2,2,2,2,2,3,3,3), // a8 - af
  166. PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7
  167. PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf
  168. PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7
  169. PCK4BITS(2,3,2,2,2,2,2,2), // c8 - cf
  170. PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7
  171. PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df
  172. PCK4BITS(2,2,2,2,2,2,2,2), // e0 - e7
  173. PCK4BITS(2,2,2,2,2,2,2,2), // e8 - ef
  174. PCK4BITS(2,2,2,2,2,2,2,2), // f0 - f7
  175. PCK4BITS(2,2,2,2,2,2,2,0) // f8 - ff
  176. };
  177. static const PRUint32 EUCKR_st [ 2] = {
  178. PCK4BITS(eError,eStart, 3,eError,eError,eError,eError,eError),//00-07
  179. PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart,eStart) //08-0f
  180. };
  181. static const PRUint32 EUCKRCharLenTable[] = {0, 1, 2, 0};
  182. const SMModel EUCKRSMModel = {
  183. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCKR_cls },
  184. 4,
  185. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCKR_st },
  186. EUCKRCharLenTable,
  187. "EUC-KR",
  188. };
  189. static const PRUint32 EUCTW_cls [ 256 / 8 ] = {
  190. //PCK4BITS(0,2,2,2,2,2,2,2), // 00 - 07
  191. PCK4BITS(2,2,2,2,2,2,2,2), // 00 - 07
  192. PCK4BITS(2,2,2,2,2,2,0,0), // 08 - 0f
  193. PCK4BITS(2,2,2,2,2,2,2,2), // 10 - 17
  194. PCK4BITS(2,2,2,0,2,2,2,2), // 18 - 1f
  195. PCK4BITS(2,2,2,2,2,2,2,2), // 20 - 27
  196. PCK4BITS(2,2,2,2,2,2,2,2), // 28 - 2f
  197. PCK4BITS(2,2,2,2,2,2,2,2), // 30 - 37
  198. PCK4BITS(2,2,2,2,2,2,2,2), // 38 - 3f
  199. PCK4BITS(2,2,2,2,2,2,2,2), // 40 - 47
  200. PCK4BITS(2,2,2,2,2,2,2,2), // 48 - 4f
  201. PCK4BITS(2,2,2,2,2,2,2,2), // 50 - 57
  202. PCK4BITS(2,2,2,2,2,2,2,2), // 58 - 5f
  203. PCK4BITS(2,2,2,2,2,2,2,2), // 60 - 67
  204. PCK4BITS(2,2,2,2,2,2,2,2), // 68 - 6f
  205. PCK4BITS(2,2,2,2,2,2,2,2), // 70 - 77
  206. PCK4BITS(2,2,2,2,2,2,2,2), // 78 - 7f
  207. PCK4BITS(0,0,0,0,0,0,0,0), // 80 - 87
  208. PCK4BITS(0,0,0,0,0,0,6,0), // 88 - 8f
  209. PCK4BITS(0,0,0,0,0,0,0,0), // 90 - 97
  210. PCK4BITS(0,0,0,0,0,0,0,0), // 98 - 9f
  211. PCK4BITS(0,3,4,4,4,4,4,4), // a0 - a7
  212. PCK4BITS(5,5,1,1,1,1,1,1), // a8 - af
  213. PCK4BITS(1,1,1,1,1,1,1,1), // b0 - b7
  214. PCK4BITS(1,1,1,1,1,1,1,1), // b8 - bf
  215. PCK4BITS(1,1,3,1,3,3,3,3), // c0 - c7
  216. PCK4BITS(3,3,3,3,3,3,3,3), // c8 - cf
  217. PCK4BITS(3,3,3,3,3,3,3,3), // d0 - d7
  218. PCK4BITS(3,3,3,3,3,3,3,3), // d8 - df
  219. PCK4BITS(3,3,3,3,3,3,3,3), // e0 - e7
  220. PCK4BITS(3,3,3,3,3,3,3,3), // e8 - ef
  221. PCK4BITS(3,3,3,3,3,3,3,3), // f0 - f7
  222. PCK4BITS(3,3,3,3,3,3,3,0) // f8 - ff
  223. };
  224. static const PRUint32 EUCTW_st [ 6] = {
  225. PCK4BITS(eError,eError,eStart, 3, 3, 3, 4,eError),//00-07
  226. PCK4BITS(eError,eError,eError,eError,eError,eError,eItsMe,eItsMe),//08-0f
  227. PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eStart,eError),//10-17
  228. PCK4BITS(eStart,eStart,eStart,eError,eError,eError,eError,eError),//18-1f
  229. PCK4BITS( 5,eError,eError,eError,eStart,eError,eStart,eStart),//20-27
  230. PCK4BITS(eStart,eError,eStart,eStart,eStart,eStart,eStart,eStart) //28-2f
  231. };
  232. static const PRUint32 EUCTWCharLenTable[] = {0, 0, 1, 2, 2, 2, 3};
  233. const SMModel EUCTWSMModel = {
  234. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCTW_cls },
  235. 7,
  236. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCTW_st },
  237. EUCTWCharLenTable,
  238. "EUC-TW",
  239. };
  240. /* obsolete GB2312 by GB18030
  241. static PRUint32 GB2312_cls [ 256 / 8 ] = {
  242. //PCK4BITS(0,1,1,1,1,1,1,1), // 00 - 07
  243. PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07
  244. PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f
  245. PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17
  246. PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f
  247. PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27
  248. PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f
  249. PCK4BITS(1,1,1,1,1,1,1,1), // 30 - 37
  250. PCK4BITS(1,1,1,1,1,1,1,1), // 38 - 3f
  251. PCK4BITS(1,1,1,1,1,1,1,1), // 40 - 47
  252. PCK4BITS(1,1,1,1,1,1,1,1), // 48 - 4f
  253. PCK4BITS(1,1,1,1,1,1,1,1), // 50 - 57
  254. PCK4BITS(1,1,1,1,1,1,1,1), // 58 - 5f
  255. PCK4BITS(1,1,1,1,1,1,1,1), // 60 - 67
  256. PCK4BITS(1,1,1,1,1,1,1,1), // 68 - 6f
  257. PCK4BITS(1,1,1,1,1,1,1,1), // 70 - 77
  258. PCK4BITS(1,1,1,1,1,1,1,1), // 78 - 7f
  259. PCK4BITS(1,0,0,0,0,0,0,0), // 80 - 87
  260. PCK4BITS(0,0,0,0,0,0,0,0), // 88 - 8f
  261. PCK4BITS(0,0,0,0,0,0,0,0), // 90 - 97
  262. PCK4BITS(0,0,0,0,0,0,0,0), // 98 - 9f
  263. PCK4BITS(0,2,2,2,2,2,2,2), // a0 - a7
  264. PCK4BITS(2,2,3,3,3,3,3,3), // a8 - af
  265. PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7
  266. PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf
  267. PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7
  268. PCK4BITS(2,2,2,2,2,2,2,2), // c8 - cf
  269. PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7
  270. PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df
  271. PCK4BITS(2,2,2,2,2,2,2,2), // e0 - e7
  272. PCK4BITS(2,2,2,2,2,2,2,2), // e8 - ef
  273. PCK4BITS(2,2,2,2,2,2,2,2), // f0 - f7
  274. PCK4BITS(2,2,2,2,2,2,2,0) // f8 - ff
  275. };
  276. static PRUint32 GB2312_st [ 2] = {
  277. PCK4BITS(eError,eStart, 3,eError,eError,eError,eError,eError),//00-07
  278. PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart,eStart) //08-0f
  279. };
  280. static const PRUint32 GB2312CharLenTable[] = {0, 1, 2, 0};
  281. SMModel GB2312SMModel = {
  282. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB2312_cls },
  283. 4,
  284. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB2312_st },
  285. GB2312CharLenTable,
  286. "GB2312",
  287. };
  288. */
  289. // the following state machine data was created by perl script in
  290. // intl/chardet/tools. It should be the same as in PSM detector.
  291. static const PRUint32 GB18030_cls [ 256 / 8 ] = {
  292. PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07
  293. PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f
  294. PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17
  295. PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f
  296. PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27
  297. PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f
  298. PCK4BITS(3,3,3,3,3,3,3,3), // 30 - 37
  299. PCK4BITS(3,3,1,1,1,1,1,1), // 38 - 3f
  300. PCK4BITS(2,2,2,2,2,2,2,2), // 40 - 47
  301. PCK4BITS(2,2,2,2,2,2,2,2), // 48 - 4f
  302. PCK4BITS(2,2,2,2,2,2,2,2), // 50 - 57
  303. PCK4BITS(2,2,2,2,2,2,2,2), // 58 - 5f
  304. PCK4BITS(2,2,2,2,2,2,2,2), // 60 - 67
  305. PCK4BITS(2,2,2,2,2,2,2,2), // 68 - 6f
  306. PCK4BITS(2,2,2,2,2,2,2,2), // 70 - 77
  307. PCK4BITS(2,2,2,2,2,2,2,4), // 78 - 7f
  308. PCK4BITS(5,6,6,6,6,6,6,6), // 80 - 87
  309. PCK4BITS(6,6,6,6,6,6,6,6), // 88 - 8f
  310. PCK4BITS(6,6,6,6,6,6,6,6), // 90 - 97
  311. PCK4BITS(6,6,6,6,6,6,6,6), // 98 - 9f
  312. PCK4BITS(6,6,6,6,6,6,6,6), // a0 - a7
  313. PCK4BITS(6,6,6,6,6,6,6,6), // a8 - af
  314. PCK4BITS(6,6,6,6,6,6,6,6), // b0 - b7
  315. PCK4BITS(6,6,6,6,6,6,6,6), // b8 - bf
  316. PCK4BITS(6,6,6,6,6,6,6,6), // c0 - c7
  317. PCK4BITS(6,6,6,6,6,6,6,6), // c8 - cf
  318. PCK4BITS(6,6,6,6,6,6,6,6), // d0 - d7
  319. PCK4BITS(6,6,6,6,6,6,6,6), // d8 - df
  320. PCK4BITS(6,6,6,6,6,6,6,6), // e0 - e7
  321. PCK4BITS(6,6,6,6,6,6,6,6), // e8 - ef
  322. PCK4BITS(6,6,6,6,6,6,6,6), // f0 - f7
  323. PCK4BITS(6,6,6,6,6,6,6,0) // f8 - ff
  324. };
  325. static const PRUint32 GB18030_st [ 6] = {
  326. PCK4BITS(eError,eStart,eStart,eStart,eStart,eStart, 3,eError),//00-07
  327. PCK4BITS(eError,eError,eError,eError,eError,eError,eItsMe,eItsMe),//08-0f
  328. PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart),//10-17
  329. PCK4BITS( 4,eError,eStart,eStart,eError,eError,eError,eError),//18-1f
  330. PCK4BITS(eError,eError, 5,eError,eError,eError,eItsMe,eError),//20-27
  331. PCK4BITS(eError,eError,eStart,eStart,eStart,eStart,eStart,eStart) //28-2f
  332. };
  333. // To be accurate, the length of class 6 can be either 2 or 4.
  334. // But it is not necessary to discriminate between the two since
  335. // it is used for frequency analysis only, and we are validing
  336. // each code range there as well. So it is safe to set it to be
  337. // 2 here.
  338. static const PRUint32 GB18030CharLenTable[] = {0, 1, 1, 1, 1, 1, 2};
  339. const SMModel GB18030SMModel = {
  340. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB18030_cls },
  341. 7,
  342. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB18030_st },
  343. GB18030CharLenTable,
  344. "GB18030",
  345. };
  346. // sjis
  347. static const PRUint32 SJIS_cls [ 256 / 8 ] = {
  348. //PCK4BITS(0,1,1,1,1,1,1,1), // 00 - 07
  349. PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07
  350. PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f
  351. PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17
  352. PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f
  353. PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27
  354. PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f
  355. PCK4BITS(1,1,1,1,1,1,1,1), // 30 - 37
  356. PCK4BITS(1,1,1,1,1,1,1,1), // 38 - 3f
  357. PCK4BITS(2,2,2,2,2,2,2,2), // 40 - 47
  358. PCK4BITS(2,2,2,2,2,2,2,2), // 48 - 4f
  359. PCK4BITS(2,2,2,2,2,2,2,2), // 50 - 57
  360. PCK4BITS(2,2,2,2,2,2,2,2), // 58 - 5f
  361. PCK4BITS(2,2,2,2,2,2,2,2), // 60 - 67
  362. PCK4BITS(2,2,2,2,2,2,2,2), // 68 - 6f
  363. PCK4BITS(2,2,2,2,2,2,2,2), // 70 - 77
  364. PCK4BITS(2,2,2,2,2,2,2,1), // 78 - 7f
  365. PCK4BITS(3,3,3,3,3,3,3,3), // 80 - 87
  366. PCK4BITS(3,3,3,3,3,3,3,3), // 88 - 8f
  367. PCK4BITS(3,3,3,3,3,3,3,3), // 90 - 97
  368. PCK4BITS(3,3,3,3,3,3,3,3), // 98 - 9f
  369. //0xa0 is illegal in sjis encoding, but some pages does
  370. //contain such byte. We need to be more error forgiven.
  371. PCK4BITS(2,2,2,2,2,2,2,2), // a0 - a7
  372. PCK4BITS(2,2,2,2,2,2,2,2), // a8 - af
  373. PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7
  374. PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf
  375. PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7
  376. PCK4BITS(2,2,2,2,2,2,2,2), // c8 - cf
  377. PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7
  378. PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df
  379. PCK4BITS(3,3,3,3,3,3,3,3), // e0 - e7
  380. PCK4BITS(3,3,3,3,3,4,4,4), // e8 - ef
  381. PCK4BITS(4,4,4,4,4,4,4,4), // f0 - f7
  382. PCK4BITS(4,4,4,4,4,0,0,0) // f8 - ff
  383. };
  384. static const PRUint32 SJIS_st [ 3] = {
  385. PCK4BITS(eError,eStart,eStart, 3,eError,eError,eError,eError),//00-07
  386. PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f
  387. PCK4BITS(eItsMe,eItsMe,eError,eError,eStart,eStart,eStart,eStart) //10-17
  388. };
  389. static const PRUint32 SJISCharLenTable[] = {0, 1, 1, 2, 0, 0};
  390. const SMModel SJISSMModel = {
  391. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, SJIS_cls },
  392. 6,
  393. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, SJIS_st },
  394. SJISCharLenTable,
  395. "SHIFT_JIS",
  396. };
  397. static const PRUint32 UTF8_cls [ 256 / 8 ] = {
  398. //PCK4BITS(0,1,1,1,1,1,1,1), // 00 - 07
  399. PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07 //allow 0x00 as a legal value
  400. PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f
  401. PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17
  402. PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f
  403. PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27
  404. PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f
  405. PCK4BITS(1,1,1,1,1,1,1,1), // 30 - 37
  406. PCK4BITS(1,1,1,1,1,1,1,1), // 38 - 3f
  407. PCK4BITS(1,1,1,1,1,1,1,1), // 40 - 47
  408. PCK4BITS(1,1,1,1,1,1,1,1), // 48 - 4f
  409. PCK4BITS(1,1,1,1,1,1,1,1), // 50 - 57
  410. PCK4BITS(1,1,1,1,1,1,1,1), // 58 - 5f
  411. PCK4BITS(1,1,1,1,1,1,1,1), // 60 - 67
  412. PCK4BITS(1,1,1,1,1,1,1,1), // 68 - 6f
  413. PCK4BITS(1,1,1,1,1,1,1,1), // 70 - 77
  414. PCK4BITS(1,1,1,1,1,1,1,1), // 78 - 7f
  415. PCK4BITS(2,2,2,2,3,3,3,3), // 80 - 87
  416. PCK4BITS(4,4,4,4,4,4,4,4), // 88 - 8f
  417. PCK4BITS(4,4,4,4,4,4,4,4), // 90 - 97
  418. PCK4BITS(4,4,4,4,4,4,4,4), // 98 - 9f
  419. PCK4BITS(5,5,5,5,5,5,5,5), // a0 - a7
  420. PCK4BITS(5,5,5,5,5,5,5,5), // a8 - af
  421. PCK4BITS(5,5,5,5,5,5,5,5), // b0 - b7
  422. PCK4BITS(5,5,5,5,5,5,5,5), // b8 - bf
  423. PCK4BITS(0,0,6,6,6,6,6,6), // c0 - c7
  424. PCK4BITS(6,6,6,6,6,6,6,6), // c8 - cf
  425. PCK4BITS(6,6,6,6,6,6,6,6), // d0 - d7
  426. PCK4BITS(6,6,6,6,6,6,6,6), // d8 - df
  427. PCK4BITS(7,8,8,8,8,8,8,8), // e0 - e7
  428. PCK4BITS(8,8,8,8,8,9,8,8), // e8 - ef
  429. PCK4BITS(10,11,11,11,11,11,11,11), // f0 - f7
  430. PCK4BITS(12,13,13,13,14,15,0,0) // f8 - ff
  431. };
  432. static const PRUint32 UTF8_st [ 26] = {
  433. PCK4BITS(eError,eStart,eError,eError,eError,eError, 12, 10),//00-07
  434. PCK4BITS( 9, 11, 8, 7, 6, 5, 4, 3),//08-0f
  435. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//10-17
  436. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//18-1f
  437. PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe),//20-27
  438. PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe),//28-2f
  439. PCK4BITS(eError,eError, 5, 5, 5, 5,eError,eError),//30-37
  440. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//38-3f
  441. PCK4BITS(eError,eError,eError, 5, 5, 5,eError,eError),//40-47
  442. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//48-4f
  443. PCK4BITS(eError,eError, 7, 7, 7, 7,eError,eError),//50-57
  444. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//58-5f
  445. PCK4BITS(eError,eError,eError,eError, 7, 7,eError,eError),//60-67
  446. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//68-6f
  447. PCK4BITS(eError,eError, 9, 9, 9, 9,eError,eError),//70-77
  448. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//78-7f
  449. PCK4BITS(eError,eError,eError,eError,eError, 9,eError,eError),//80-87
  450. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//88-8f
  451. PCK4BITS(eError,eError, 12, 12, 12, 12,eError,eError),//90-97
  452. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//98-9f
  453. PCK4BITS(eError,eError,eError,eError,eError, 12,eError,eError),//a0-a7
  454. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//a8-af
  455. PCK4BITS(eError,eError, 12, 12, 12,eError,eError,eError),//b0-b7
  456. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//b8-bf
  457. PCK4BITS(eError,eError,eStart,eStart,eStart,eStart,eError,eError),//c0-c7
  458. PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError) //c8-cf
  459. };
  460. static const PRUint32 UTF8CharLenTable[] = {0, 1, 0, 0, 0, 0, 2, 3,
  461. 3, 3, 4, 4, 5, 5, 6, 6 };
  462. const SMModel UTF8SMModel = {
  463. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UTF8_cls },
  464. 16,
  465. {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UTF8_st },
  466. UTF8CharLenTable,
  467. "UTF-8",
  468. };