Dieses Repository enthält Python-Dateien die im Rahmen des Wahlpflichtmoduls "Informationssysteme in der Medizintechnik" (Dozent: Prof. Dr. Oliver Hofmann) erstellt wurden und verwaltet deren Versionskontrolle.
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.

mbcssm.py 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. ######################## BEGIN LICENSE BLOCK ########################
  2. # The Original Code is mozilla.org code.
  3. #
  4. # The Initial Developer of the Original Code is
  5. # Netscape Communications Corporation.
  6. # Portions created by the Initial Developer are Copyright (C) 1998
  7. # the Initial Developer. All Rights Reserved.
  8. #
  9. # Contributor(s):
  10. # Mark Pilgrim - port to Python
  11. #
  12. # This library is free software; you can redistribute it and/or
  13. # modify it under the terms of the GNU Lesser General Public
  14. # License as published by the Free Software Foundation; either
  15. # version 2.1 of the License, or (at your option) any later version.
  16. #
  17. # This library is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. # Lesser General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU Lesser General Public
  23. # License along with this library; if not, write to the Free Software
  24. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  25. # 02110-1301 USA
  26. ######################### END LICENSE BLOCK #########################
  27. from .enums import MachineState
  28. # BIG5
  29. BIG5_CLS = (
  30. 1,1,1,1,1,1,1,1, # 00 - 07 #allow 0x00 as legal value
  31. 1,1,1,1,1,1,0,0, # 08 - 0f
  32. 1,1,1,1,1,1,1,1, # 10 - 17
  33. 1,1,1,0,1,1,1,1, # 18 - 1f
  34. 1,1,1,1,1,1,1,1, # 20 - 27
  35. 1,1,1,1,1,1,1,1, # 28 - 2f
  36. 1,1,1,1,1,1,1,1, # 30 - 37
  37. 1,1,1,1,1,1,1,1, # 38 - 3f
  38. 2,2,2,2,2,2,2,2, # 40 - 47
  39. 2,2,2,2,2,2,2,2, # 48 - 4f
  40. 2,2,2,2,2,2,2,2, # 50 - 57
  41. 2,2,2,2,2,2,2,2, # 58 - 5f
  42. 2,2,2,2,2,2,2,2, # 60 - 67
  43. 2,2,2,2,2,2,2,2, # 68 - 6f
  44. 2,2,2,2,2,2,2,2, # 70 - 77
  45. 2,2,2,2,2,2,2,1, # 78 - 7f
  46. 4,4,4,4,4,4,4,4, # 80 - 87
  47. 4,4,4,4,4,4,4,4, # 88 - 8f
  48. 4,4,4,4,4,4,4,4, # 90 - 97
  49. 4,4,4,4,4,4,4,4, # 98 - 9f
  50. 4,3,3,3,3,3,3,3, # a0 - a7
  51. 3,3,3,3,3,3,3,3, # a8 - af
  52. 3,3,3,3,3,3,3,3, # b0 - b7
  53. 3,3,3,3,3,3,3,3, # b8 - bf
  54. 3,3,3,3,3,3,3,3, # c0 - c7
  55. 3,3,3,3,3,3,3,3, # c8 - cf
  56. 3,3,3,3,3,3,3,3, # d0 - d7
  57. 3,3,3,3,3,3,3,3, # d8 - df
  58. 3,3,3,3,3,3,3,3, # e0 - e7
  59. 3,3,3,3,3,3,3,3, # e8 - ef
  60. 3,3,3,3,3,3,3,3, # f0 - f7
  61. 3,3,3,3,3,3,3,0 # f8 - ff
  62. )
  63. BIG5_ST = (
  64. MachineState.ERROR,MachineState.START,MachineState.START, 3,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#00-07
  65. MachineState.ERROR,MachineState.ERROR,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ERROR,#08-0f
  66. MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START#10-17
  67. )
  68. BIG5_CHAR_LEN_TABLE = (0, 1, 1, 2, 0)
  69. BIG5_SM_MODEL = {'class_table': BIG5_CLS,
  70. 'class_factor': 5,
  71. 'state_table': BIG5_ST,
  72. 'char_len_table': BIG5_CHAR_LEN_TABLE,
  73. 'name': 'Big5'}
  74. # CP949
  75. CP949_CLS = (
  76. 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,0,0, # 00 - 0f
  77. 1,1,1,1,1,1,1,1, 1,1,1,0,1,1,1,1, # 10 - 1f
  78. 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, # 20 - 2f
  79. 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, # 30 - 3f
  80. 1,4,4,4,4,4,4,4, 4,4,4,4,4,4,4,4, # 40 - 4f
  81. 4,4,5,5,5,5,5,5, 5,5,5,1,1,1,1,1, # 50 - 5f
  82. 1,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5, # 60 - 6f
  83. 5,5,5,5,5,5,5,5, 5,5,5,1,1,1,1,1, # 70 - 7f
  84. 0,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6, # 80 - 8f
  85. 6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6, # 90 - 9f
  86. 6,7,7,7,7,7,7,7, 7,7,7,7,7,8,8,8, # a0 - af
  87. 7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7, # b0 - bf
  88. 7,7,7,7,7,7,9,2, 2,3,2,2,2,2,2,2, # c0 - cf
  89. 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, # d0 - df
  90. 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, # e0 - ef
  91. 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,0, # f0 - ff
  92. )
  93. CP949_ST = (
  94. #cls= 0 1 2 3 4 5 6 7 8 9 # previous state =
  95. MachineState.ERROR,MachineState.START, 3,MachineState.ERROR,MachineState.START,MachineState.START, 4, 5,MachineState.ERROR, 6, # MachineState.START
  96. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR, # MachineState.ERROR
  97. MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME, # MachineState.ITS_ME
  98. MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.START,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START, # 3
  99. MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START, # 4
  100. MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START, # 5
  101. MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START, # 6
  102. )
  103. CP949_CHAR_LEN_TABLE = (0, 1, 2, 0, 1, 1, 2, 2, 0, 2)
  104. CP949_SM_MODEL = {'class_table': CP949_CLS,
  105. 'class_factor': 10,
  106. 'state_table': CP949_ST,
  107. 'char_len_table': CP949_CHAR_LEN_TABLE,
  108. 'name': 'CP949'}
  109. # EUC-JP
  110. EUCJP_CLS = (
  111. 4,4,4,4,4,4,4,4, # 00 - 07
  112. 4,4,4,4,4,4,5,5, # 08 - 0f
  113. 4,4,4,4,4,4,4,4, # 10 - 17
  114. 4,4,4,5,4,4,4,4, # 18 - 1f
  115. 4,4,4,4,4,4,4,4, # 20 - 27
  116. 4,4,4,4,4,4,4,4, # 28 - 2f
  117. 4,4,4,4,4,4,4,4, # 30 - 37
  118. 4,4,4,4,4,4,4,4, # 38 - 3f
  119. 4,4,4,4,4,4,4,4, # 40 - 47
  120. 4,4,4,4,4,4,4,4, # 48 - 4f
  121. 4,4,4,4,4,4,4,4, # 50 - 57
  122. 4,4,4,4,4,4,4,4, # 58 - 5f
  123. 4,4,4,4,4,4,4,4, # 60 - 67
  124. 4,4,4,4,4,4,4,4, # 68 - 6f
  125. 4,4,4,4,4,4,4,4, # 70 - 77
  126. 4,4,4,4,4,4,4,4, # 78 - 7f
  127. 5,5,5,5,5,5,5,5, # 80 - 87
  128. 5,5,5,5,5,5,1,3, # 88 - 8f
  129. 5,5,5,5,5,5,5,5, # 90 - 97
  130. 5,5,5,5,5,5,5,5, # 98 - 9f
  131. 5,2,2,2,2,2,2,2, # a0 - a7
  132. 2,2,2,2,2,2,2,2, # a8 - af
  133. 2,2,2,2,2,2,2,2, # b0 - b7
  134. 2,2,2,2,2,2,2,2, # b8 - bf
  135. 2,2,2,2,2,2,2,2, # c0 - c7
  136. 2,2,2,2,2,2,2,2, # c8 - cf
  137. 2,2,2,2,2,2,2,2, # d0 - d7
  138. 2,2,2,2,2,2,2,2, # d8 - df
  139. 0,0,0,0,0,0,0,0, # e0 - e7
  140. 0,0,0,0,0,0,0,0, # e8 - ef
  141. 0,0,0,0,0,0,0,0, # f0 - f7
  142. 0,0,0,0,0,0,0,5 # f8 - ff
  143. )
  144. EUCJP_ST = (
  145. 3, 4, 3, 5,MachineState.START,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#00-07
  146. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,#08-0f
  147. MachineState.ITS_ME,MachineState.ITS_ME,MachineState.START,MachineState.ERROR,MachineState.START,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#10-17
  148. MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR, 3,MachineState.ERROR,#18-1f
  149. 3,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START,MachineState.START#20-27
  150. )
  151. EUCJP_CHAR_LEN_TABLE = (2, 2, 2, 3, 1, 0)
  152. EUCJP_SM_MODEL = {'class_table': EUCJP_CLS,
  153. 'class_factor': 6,
  154. 'state_table': EUCJP_ST,
  155. 'char_len_table': EUCJP_CHAR_LEN_TABLE,
  156. 'name': 'EUC-JP'}
  157. # EUC-KR
  158. EUCKR_CLS = (
  159. 1,1,1,1,1,1,1,1, # 00 - 07
  160. 1,1,1,1,1,1,0,0, # 08 - 0f
  161. 1,1,1,1,1,1,1,1, # 10 - 17
  162. 1,1,1,0,1,1,1,1, # 18 - 1f
  163. 1,1,1,1,1,1,1,1, # 20 - 27
  164. 1,1,1,1,1,1,1,1, # 28 - 2f
  165. 1,1,1,1,1,1,1,1, # 30 - 37
  166. 1,1,1,1,1,1,1,1, # 38 - 3f
  167. 1,1,1,1,1,1,1,1, # 40 - 47
  168. 1,1,1,1,1,1,1,1, # 48 - 4f
  169. 1,1,1,1,1,1,1,1, # 50 - 57
  170. 1,1,1,1,1,1,1,1, # 58 - 5f
  171. 1,1,1,1,1,1,1,1, # 60 - 67
  172. 1,1,1,1,1,1,1,1, # 68 - 6f
  173. 1,1,1,1,1,1,1,1, # 70 - 77
  174. 1,1,1,1,1,1,1,1, # 78 - 7f
  175. 0,0,0,0,0,0,0,0, # 80 - 87
  176. 0,0,0,0,0,0,0,0, # 88 - 8f
  177. 0,0,0,0,0,0,0,0, # 90 - 97
  178. 0,0,0,0,0,0,0,0, # 98 - 9f
  179. 0,2,2,2,2,2,2,2, # a0 - a7
  180. 2,2,2,2,2,3,3,3, # a8 - af
  181. 2,2,2,2,2,2,2,2, # b0 - b7
  182. 2,2,2,2,2,2,2,2, # b8 - bf
  183. 2,2,2,2,2,2,2,2, # c0 - c7
  184. 2,3,2,2,2,2,2,2, # c8 - cf
  185. 2,2,2,2,2,2,2,2, # d0 - d7
  186. 2,2,2,2,2,2,2,2, # d8 - df
  187. 2,2,2,2,2,2,2,2, # e0 - e7
  188. 2,2,2,2,2,2,2,2, # e8 - ef
  189. 2,2,2,2,2,2,2,2, # f0 - f7
  190. 2,2,2,2,2,2,2,0 # f8 - ff
  191. )
  192. EUCKR_ST = (
  193. MachineState.ERROR,MachineState.START, 3,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#00-07
  194. MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.START #08-0f
  195. )
  196. EUCKR_CHAR_LEN_TABLE = (0, 1, 2, 0)
  197. EUCKR_SM_MODEL = {'class_table': EUCKR_CLS,
  198. 'class_factor': 4,
  199. 'state_table': EUCKR_ST,
  200. 'char_len_table': EUCKR_CHAR_LEN_TABLE,
  201. 'name': 'EUC-KR'}
  202. # EUC-TW
  203. EUCTW_CLS = (
  204. 2,2,2,2,2,2,2,2, # 00 - 07
  205. 2,2,2,2,2,2,0,0, # 08 - 0f
  206. 2,2,2,2,2,2,2,2, # 10 - 17
  207. 2,2,2,0,2,2,2,2, # 18 - 1f
  208. 2,2,2,2,2,2,2,2, # 20 - 27
  209. 2,2,2,2,2,2,2,2, # 28 - 2f
  210. 2,2,2,2,2,2,2,2, # 30 - 37
  211. 2,2,2,2,2,2,2,2, # 38 - 3f
  212. 2,2,2,2,2,2,2,2, # 40 - 47
  213. 2,2,2,2,2,2,2,2, # 48 - 4f
  214. 2,2,2,2,2,2,2,2, # 50 - 57
  215. 2,2,2,2,2,2,2,2, # 58 - 5f
  216. 2,2,2,2,2,2,2,2, # 60 - 67
  217. 2,2,2,2,2,2,2,2, # 68 - 6f
  218. 2,2,2,2,2,2,2,2, # 70 - 77
  219. 2,2,2,2,2,2,2,2, # 78 - 7f
  220. 0,0,0,0,0,0,0,0, # 80 - 87
  221. 0,0,0,0,0,0,6,0, # 88 - 8f
  222. 0,0,0,0,0,0,0,0, # 90 - 97
  223. 0,0,0,0,0,0,0,0, # 98 - 9f
  224. 0,3,4,4,4,4,4,4, # a0 - a7
  225. 5,5,1,1,1,1,1,1, # a8 - af
  226. 1,1,1,1,1,1,1,1, # b0 - b7
  227. 1,1,1,1,1,1,1,1, # b8 - bf
  228. 1,1,3,1,3,3,3,3, # c0 - c7
  229. 3,3,3,3,3,3,3,3, # c8 - cf
  230. 3,3,3,3,3,3,3,3, # d0 - d7
  231. 3,3,3,3,3,3,3,3, # d8 - df
  232. 3,3,3,3,3,3,3,3, # e0 - e7
  233. 3,3,3,3,3,3,3,3, # e8 - ef
  234. 3,3,3,3,3,3,3,3, # f0 - f7
  235. 3,3,3,3,3,3,3,0 # f8 - ff
  236. )
  237. EUCTW_ST = (
  238. MachineState.ERROR,MachineState.ERROR,MachineState.START, 3, 3, 3, 4,MachineState.ERROR,#00-07
  239. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ITS_ME,MachineState.ITS_ME,#08-0f
  240. MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ERROR,MachineState.START,MachineState.ERROR,#10-17
  241. MachineState.START,MachineState.START,MachineState.START,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#18-1f
  242. 5,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.ERROR,MachineState.START,MachineState.START,#20-27
  243. MachineState.START,MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START #28-2f
  244. )
  245. EUCTW_CHAR_LEN_TABLE = (0, 0, 1, 2, 2, 2, 3)
  246. EUCTW_SM_MODEL = {'class_table': EUCTW_CLS,
  247. 'class_factor': 7,
  248. 'state_table': EUCTW_ST,
  249. 'char_len_table': EUCTW_CHAR_LEN_TABLE,
  250. 'name': 'x-euc-tw'}
  251. # GB2312
  252. GB2312_CLS = (
  253. 1,1,1,1,1,1,1,1, # 00 - 07
  254. 1,1,1,1,1,1,0,0, # 08 - 0f
  255. 1,1,1,1,1,1,1,1, # 10 - 17
  256. 1,1,1,0,1,1,1,1, # 18 - 1f
  257. 1,1,1,1,1,1,1,1, # 20 - 27
  258. 1,1,1,1,1,1,1,1, # 28 - 2f
  259. 3,3,3,3,3,3,3,3, # 30 - 37
  260. 3,3,1,1,1,1,1,1, # 38 - 3f
  261. 2,2,2,2,2,2,2,2, # 40 - 47
  262. 2,2,2,2,2,2,2,2, # 48 - 4f
  263. 2,2,2,2,2,2,2,2, # 50 - 57
  264. 2,2,2,2,2,2,2,2, # 58 - 5f
  265. 2,2,2,2,2,2,2,2, # 60 - 67
  266. 2,2,2,2,2,2,2,2, # 68 - 6f
  267. 2,2,2,2,2,2,2,2, # 70 - 77
  268. 2,2,2,2,2,2,2,4, # 78 - 7f
  269. 5,6,6,6,6,6,6,6, # 80 - 87
  270. 6,6,6,6,6,6,6,6, # 88 - 8f
  271. 6,6,6,6,6,6,6,6, # 90 - 97
  272. 6,6,6,6,6,6,6,6, # 98 - 9f
  273. 6,6,6,6,6,6,6,6, # a0 - a7
  274. 6,6,6,6,6,6,6,6, # a8 - af
  275. 6,6,6,6,6,6,6,6, # b0 - b7
  276. 6,6,6,6,6,6,6,6, # b8 - bf
  277. 6,6,6,6,6,6,6,6, # c0 - c7
  278. 6,6,6,6,6,6,6,6, # c8 - cf
  279. 6,6,6,6,6,6,6,6, # d0 - d7
  280. 6,6,6,6,6,6,6,6, # d8 - df
  281. 6,6,6,6,6,6,6,6, # e0 - e7
  282. 6,6,6,6,6,6,6,6, # e8 - ef
  283. 6,6,6,6,6,6,6,6, # f0 - f7
  284. 6,6,6,6,6,6,6,0 # f8 - ff
  285. )
  286. GB2312_ST = (
  287. MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START, 3,MachineState.ERROR,#00-07
  288. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ITS_ME,MachineState.ITS_ME,#08-0f
  289. MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ERROR,MachineState.ERROR,MachineState.START,#10-17
  290. 4,MachineState.ERROR,MachineState.START,MachineState.START,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#18-1f
  291. MachineState.ERROR,MachineState.ERROR, 5,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ITS_ME,MachineState.ERROR,#20-27
  292. MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.START #28-2f
  293. )
  294. # To be accurate, the length of class 6 can be either 2 or 4.
  295. # But it is not necessary to discriminate between the two since
  296. # it is used for frequency analysis only, and we are validating
  297. # each code range there as well. So it is safe to set it to be
  298. # 2 here.
  299. GB2312_CHAR_LEN_TABLE = (0, 1, 1, 1, 1, 1, 2)
  300. GB2312_SM_MODEL = {'class_table': GB2312_CLS,
  301. 'class_factor': 7,
  302. 'state_table': GB2312_ST,
  303. 'char_len_table': GB2312_CHAR_LEN_TABLE,
  304. 'name': 'GB2312'}
  305. # Shift_JIS
  306. SJIS_CLS = (
  307. 1,1,1,1,1,1,1,1, # 00 - 07
  308. 1,1,1,1,1,1,0,0, # 08 - 0f
  309. 1,1,1,1,1,1,1,1, # 10 - 17
  310. 1,1,1,0,1,1,1,1, # 18 - 1f
  311. 1,1,1,1,1,1,1,1, # 20 - 27
  312. 1,1,1,1,1,1,1,1, # 28 - 2f
  313. 1,1,1,1,1,1,1,1, # 30 - 37
  314. 1,1,1,1,1,1,1,1, # 38 - 3f
  315. 2,2,2,2,2,2,2,2, # 40 - 47
  316. 2,2,2,2,2,2,2,2, # 48 - 4f
  317. 2,2,2,2,2,2,2,2, # 50 - 57
  318. 2,2,2,2,2,2,2,2, # 58 - 5f
  319. 2,2,2,2,2,2,2,2, # 60 - 67
  320. 2,2,2,2,2,2,2,2, # 68 - 6f
  321. 2,2,2,2,2,2,2,2, # 70 - 77
  322. 2,2,2,2,2,2,2,1, # 78 - 7f
  323. 3,3,3,3,3,2,2,3, # 80 - 87
  324. 3,3,3,3,3,3,3,3, # 88 - 8f
  325. 3,3,3,3,3,3,3,3, # 90 - 97
  326. 3,3,3,3,3,3,3,3, # 98 - 9f
  327. #0xa0 is illegal in sjis encoding, but some pages does
  328. #contain such byte. We need to be more error forgiven.
  329. 2,2,2,2,2,2,2,2, # a0 - a7
  330. 2,2,2,2,2,2,2,2, # a8 - af
  331. 2,2,2,2,2,2,2,2, # b0 - b7
  332. 2,2,2,2,2,2,2,2, # b8 - bf
  333. 2,2,2,2,2,2,2,2, # c0 - c7
  334. 2,2,2,2,2,2,2,2, # c8 - cf
  335. 2,2,2,2,2,2,2,2, # d0 - d7
  336. 2,2,2,2,2,2,2,2, # d8 - df
  337. 3,3,3,3,3,3,3,3, # e0 - e7
  338. 3,3,3,3,3,4,4,4, # e8 - ef
  339. 3,3,3,3,3,3,3,3, # f0 - f7
  340. 3,3,3,3,3,0,0,0) # f8 - ff
  341. SJIS_ST = (
  342. MachineState.ERROR,MachineState.START,MachineState.START, 3,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#00-07
  343. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,#08-0f
  344. MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START,MachineState.START #10-17
  345. )
  346. SJIS_CHAR_LEN_TABLE = (0, 1, 1, 2, 0, 0)
  347. SJIS_SM_MODEL = {'class_table': SJIS_CLS,
  348. 'class_factor': 6,
  349. 'state_table': SJIS_ST,
  350. 'char_len_table': SJIS_CHAR_LEN_TABLE,
  351. 'name': 'Shift_JIS'}
  352. # UCS2-BE
  353. UCS2BE_CLS = (
  354. 0,0,0,0,0,0,0,0, # 00 - 07
  355. 0,0,1,0,0,2,0,0, # 08 - 0f
  356. 0,0,0,0,0,0,0,0, # 10 - 17
  357. 0,0,0,3,0,0,0,0, # 18 - 1f
  358. 0,0,0,0,0,0,0,0, # 20 - 27
  359. 0,3,3,3,3,3,0,0, # 28 - 2f
  360. 0,0,0,0,0,0,0,0, # 30 - 37
  361. 0,0,0,0,0,0,0,0, # 38 - 3f
  362. 0,0,0,0,0,0,0,0, # 40 - 47
  363. 0,0,0,0,0,0,0,0, # 48 - 4f
  364. 0,0,0,0,0,0,0,0, # 50 - 57
  365. 0,0,0,0,0,0,0,0, # 58 - 5f
  366. 0,0,0,0,0,0,0,0, # 60 - 67
  367. 0,0,0,0,0,0,0,0, # 68 - 6f
  368. 0,0,0,0,0,0,0,0, # 70 - 77
  369. 0,0,0,0,0,0,0,0, # 78 - 7f
  370. 0,0,0,0,0,0,0,0, # 80 - 87
  371. 0,0,0,0,0,0,0,0, # 88 - 8f
  372. 0,0,0,0,0,0,0,0, # 90 - 97
  373. 0,0,0,0,0,0,0,0, # 98 - 9f
  374. 0,0,0,0,0,0,0,0, # a0 - a7
  375. 0,0,0,0,0,0,0,0, # a8 - af
  376. 0,0,0,0,0,0,0,0, # b0 - b7
  377. 0,0,0,0,0,0,0,0, # b8 - bf
  378. 0,0,0,0,0,0,0,0, # c0 - c7
  379. 0,0,0,0,0,0,0,0, # c8 - cf
  380. 0,0,0,0,0,0,0,0, # d0 - d7
  381. 0,0,0,0,0,0,0,0, # d8 - df
  382. 0,0,0,0,0,0,0,0, # e0 - e7
  383. 0,0,0,0,0,0,0,0, # e8 - ef
  384. 0,0,0,0,0,0,0,0, # f0 - f7
  385. 0,0,0,0,0,0,4,5 # f8 - ff
  386. )
  387. UCS2BE_ST = (
  388. 5, 7, 7,MachineState.ERROR, 4, 3,MachineState.ERROR,MachineState.ERROR,#00-07
  389. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,#08-0f
  390. MachineState.ITS_ME,MachineState.ITS_ME, 6, 6, 6, 6,MachineState.ERROR,MachineState.ERROR,#10-17
  391. 6, 6, 6, 6, 6,MachineState.ITS_ME, 6, 6,#18-1f
  392. 6, 6, 6, 6, 5, 7, 7,MachineState.ERROR,#20-27
  393. 5, 8, 6, 6,MachineState.ERROR, 6, 6, 6,#28-2f
  394. 6, 6, 6, 6,MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.START #30-37
  395. )
  396. UCS2BE_CHAR_LEN_TABLE = (2, 2, 2, 0, 2, 2)
  397. UCS2BE_SM_MODEL = {'class_table': UCS2BE_CLS,
  398. 'class_factor': 6,
  399. 'state_table': UCS2BE_ST,
  400. 'char_len_table': UCS2BE_CHAR_LEN_TABLE,
  401. 'name': 'UTF-16BE'}
  402. # UCS2-LE
  403. UCS2LE_CLS = (
  404. 0,0,0,0,0,0,0,0, # 00 - 07
  405. 0,0,1,0,0,2,0,0, # 08 - 0f
  406. 0,0,0,0,0,0,0,0, # 10 - 17
  407. 0,0,0,3,0,0,0,0, # 18 - 1f
  408. 0,0,0,0,0,0,0,0, # 20 - 27
  409. 0,3,3,3,3,3,0,0, # 28 - 2f
  410. 0,0,0,0,0,0,0,0, # 30 - 37
  411. 0,0,0,0,0,0,0,0, # 38 - 3f
  412. 0,0,0,0,0,0,0,0, # 40 - 47
  413. 0,0,0,0,0,0,0,0, # 48 - 4f
  414. 0,0,0,0,0,0,0,0, # 50 - 57
  415. 0,0,0,0,0,0,0,0, # 58 - 5f
  416. 0,0,0,0,0,0,0,0, # 60 - 67
  417. 0,0,0,0,0,0,0,0, # 68 - 6f
  418. 0,0,0,0,0,0,0,0, # 70 - 77
  419. 0,0,0,0,0,0,0,0, # 78 - 7f
  420. 0,0,0,0,0,0,0,0, # 80 - 87
  421. 0,0,0,0,0,0,0,0, # 88 - 8f
  422. 0,0,0,0,0,0,0,0, # 90 - 97
  423. 0,0,0,0,0,0,0,0, # 98 - 9f
  424. 0,0,0,0,0,0,0,0, # a0 - a7
  425. 0,0,0,0,0,0,0,0, # a8 - af
  426. 0,0,0,0,0,0,0,0, # b0 - b7
  427. 0,0,0,0,0,0,0,0, # b8 - bf
  428. 0,0,0,0,0,0,0,0, # c0 - c7
  429. 0,0,0,0,0,0,0,0, # c8 - cf
  430. 0,0,0,0,0,0,0,0, # d0 - d7
  431. 0,0,0,0,0,0,0,0, # d8 - df
  432. 0,0,0,0,0,0,0,0, # e0 - e7
  433. 0,0,0,0,0,0,0,0, # e8 - ef
  434. 0,0,0,0,0,0,0,0, # f0 - f7
  435. 0,0,0,0,0,0,4,5 # f8 - ff
  436. )
  437. UCS2LE_ST = (
  438. 6, 6, 7, 6, 4, 3,MachineState.ERROR,MachineState.ERROR,#00-07
  439. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,#08-0f
  440. MachineState.ITS_ME,MachineState.ITS_ME, 5, 5, 5,MachineState.ERROR,MachineState.ITS_ME,MachineState.ERROR,#10-17
  441. 5, 5, 5,MachineState.ERROR, 5,MachineState.ERROR, 6, 6,#18-1f
  442. 7, 6, 8, 8, 5, 5, 5,MachineState.ERROR,#20-27
  443. 5, 5, 5,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR, 5, 5,#28-2f
  444. 5, 5, 5,MachineState.ERROR, 5,MachineState.ERROR,MachineState.START,MachineState.START #30-37
  445. )
  446. UCS2LE_CHAR_LEN_TABLE = (2, 2, 2, 2, 2, 2)
  447. UCS2LE_SM_MODEL = {'class_table': UCS2LE_CLS,
  448. 'class_factor': 6,
  449. 'state_table': UCS2LE_ST,
  450. 'char_len_table': UCS2LE_CHAR_LEN_TABLE,
  451. 'name': 'UTF-16LE'}
  452. # UTF-8
  453. UTF8_CLS = (
  454. 1,1,1,1,1,1,1,1, # 00 - 07 #allow 0x00 as a legal value
  455. 1,1,1,1,1,1,0,0, # 08 - 0f
  456. 1,1,1,1,1,1,1,1, # 10 - 17
  457. 1,1,1,0,1,1,1,1, # 18 - 1f
  458. 1,1,1,1,1,1,1,1, # 20 - 27
  459. 1,1,1,1,1,1,1,1, # 28 - 2f
  460. 1,1,1,1,1,1,1,1, # 30 - 37
  461. 1,1,1,1,1,1,1,1, # 38 - 3f
  462. 1,1,1,1,1,1,1,1, # 40 - 47
  463. 1,1,1,1,1,1,1,1, # 48 - 4f
  464. 1,1,1,1,1,1,1,1, # 50 - 57
  465. 1,1,1,1,1,1,1,1, # 58 - 5f
  466. 1,1,1,1,1,1,1,1, # 60 - 67
  467. 1,1,1,1,1,1,1,1, # 68 - 6f
  468. 1,1,1,1,1,1,1,1, # 70 - 77
  469. 1,1,1,1,1,1,1,1, # 78 - 7f
  470. 2,2,2,2,3,3,3,3, # 80 - 87
  471. 4,4,4,4,4,4,4,4, # 88 - 8f
  472. 4,4,4,4,4,4,4,4, # 90 - 97
  473. 4,4,4,4,4,4,4,4, # 98 - 9f
  474. 5,5,5,5,5,5,5,5, # a0 - a7
  475. 5,5,5,5,5,5,5,5, # a8 - af
  476. 5,5,5,5,5,5,5,5, # b0 - b7
  477. 5,5,5,5,5,5,5,5, # b8 - bf
  478. 0,0,6,6,6,6,6,6, # c0 - c7
  479. 6,6,6,6,6,6,6,6, # c8 - cf
  480. 6,6,6,6,6,6,6,6, # d0 - d7
  481. 6,6,6,6,6,6,6,6, # d8 - df
  482. 7,8,8,8,8,8,8,8, # e0 - e7
  483. 8,8,8,8,8,9,8,8, # e8 - ef
  484. 10,11,11,11,11,11,11,11, # f0 - f7
  485. 12,13,13,13,14,15,0,0 # f8 - ff
  486. )
  487. UTF8_ST = (
  488. MachineState.ERROR,MachineState.START,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR, 12, 10,#00-07
  489. 9, 11, 8, 7, 6, 5, 4, 3,#08-0f
  490. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#10-17
  491. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#18-1f
  492. MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,#20-27
  493. MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,MachineState.ITS_ME,#28-2f
  494. MachineState.ERROR,MachineState.ERROR, 5, 5, 5, 5,MachineState.ERROR,MachineState.ERROR,#30-37
  495. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#38-3f
  496. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR, 5, 5, 5,MachineState.ERROR,MachineState.ERROR,#40-47
  497. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#48-4f
  498. MachineState.ERROR,MachineState.ERROR, 7, 7, 7, 7,MachineState.ERROR,MachineState.ERROR,#50-57
  499. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#58-5f
  500. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR, 7, 7,MachineState.ERROR,MachineState.ERROR,#60-67
  501. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#68-6f
  502. MachineState.ERROR,MachineState.ERROR, 9, 9, 9, 9,MachineState.ERROR,MachineState.ERROR,#70-77
  503. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#78-7f
  504. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR, 9,MachineState.ERROR,MachineState.ERROR,#80-87
  505. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#88-8f
  506. MachineState.ERROR,MachineState.ERROR, 12, 12, 12, 12,MachineState.ERROR,MachineState.ERROR,#90-97
  507. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#98-9f
  508. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR, 12,MachineState.ERROR,MachineState.ERROR,#a0-a7
  509. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#a8-af
  510. MachineState.ERROR,MachineState.ERROR, 12, 12, 12,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#b0-b7
  511. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,#b8-bf
  512. MachineState.ERROR,MachineState.ERROR,MachineState.START,MachineState.START,MachineState.START,MachineState.START,MachineState.ERROR,MachineState.ERROR,#c0-c7
  513. MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR,MachineState.ERROR #c8-cf
  514. )
  515. UTF8_CHAR_LEN_TABLE = (0, 1, 0, 0, 0, 0, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6)
  516. UTF8_SM_MODEL = {'class_table': UTF8_CLS,
  517. 'class_factor': 16,
  518. 'state_table': UTF8_ST,
  519. 'char_len_table': UTF8_CHAR_LEN_TABLE,
  520. 'name': 'UTF-8'}