cchardet 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (317) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.gitmodules +3 -0
  4. data/.rubocop.yml +11 -0
  5. data/CHANGELOG.md +5 -0
  6. data/Gemfile +10 -0
  7. data/README.md +35 -0
  8. data/Rakefile +15 -0
  9. data/cchardet.gemspec +30 -0
  10. data/ext/cchardet/extconf.rb +26 -0
  11. data/ext/uchardet/.gitignore +1 -0
  12. data/ext/uchardet/.gitlab-ci.yml +106 -0
  13. data/ext/uchardet/AUTHORS +16 -0
  14. data/ext/uchardet/CMakeLists.txt +74 -0
  15. data/ext/uchardet/COPYING +1316 -0
  16. data/ext/uchardet/INSTALL +26 -0
  17. data/ext/uchardet/README.md +295 -0
  18. data/ext/uchardet/build-mac/uchardet.cpp +7 -0
  19. data/ext/uchardet/build-mac/uchardet.xcodeproj/project.pbxproj +543 -0
  20. data/ext/uchardet/build-mac/uchardet.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  21. data/ext/uchardet/build-mac/uchardet.xcodeproj/project.xcworkspace/xcshareddata/uchardet.xccheckout +41 -0
  22. data/ext/uchardet/build-mac/uchardet.xcodeproj/xcshareddata/xcschemes/uchardet-ios.xcscheme +77 -0
  23. data/ext/uchardet/build-mac/uchardet.xcodeproj/xcshareddata/xcschemes/uchardet.xcscheme +77 -0
  24. data/ext/uchardet/doc/CMakeLists.txt +6 -0
  25. data/ext/uchardet/doc/README.maintainer +59 -0
  26. data/ext/uchardet/doc/uchardet.1 +18 -0
  27. data/ext/uchardet/script/BuildLangModel.py +533 -0
  28. data/ext/uchardet/script/BuildLangModelLogs/LangArabicModel.log +142 -0
  29. data/ext/uchardet/script/BuildLangModelLogs/LangCroatianModel.log +157 -0
  30. data/ext/uchardet/script/BuildLangModelLogs/LangCzechModel.log +161 -0
  31. data/ext/uchardet/script/BuildLangModelLogs/LangDanishModel.log +158 -0
  32. data/ext/uchardet/script/BuildLangModelLogs/LangEsperantoModel.log +110 -0
  33. data/ext/uchardet/script/BuildLangModelLogs/LangEstonianModel.log +159 -0
  34. data/ext/uchardet/script/BuildLangModelLogs/LangFinnishModel.log +156 -0
  35. data/ext/uchardet/script/BuildLangModelLogs/LangFrenchModel.log +116 -0
  36. data/ext/uchardet/script/BuildLangModelLogs/LangGermanModel.log +159 -0
  37. data/ext/uchardet/script/BuildLangModelLogs/LangGreekModel.log +272 -0
  38. data/ext/uchardet/script/BuildLangModelLogs/LangHungarianModel.log +109 -0
  39. data/ext/uchardet/script/BuildLangModelLogs/LangIrishModel.log +156 -0
  40. data/ext/uchardet/script/BuildLangModelLogs/LangItalianModel.log +162 -0
  41. data/ext/uchardet/script/BuildLangModelLogs/LangLatvianModel.log +162 -0
  42. data/ext/uchardet/script/BuildLangModelLogs/LangLithuanianModel.log +162 -0
  43. data/ext/uchardet/script/BuildLangModelLogs/LangMalteseModel.log +147 -0
  44. data/ext/uchardet/script/BuildLangModelLogs/LangPolishModel.log +154 -0
  45. data/ext/uchardet/script/BuildLangModelLogs/LangPortugueseModel.log +166 -0
  46. data/ext/uchardet/script/BuildLangModelLogs/LangRomanianModel.log +153 -0
  47. data/ext/uchardet/script/BuildLangModelLogs/LangSlovakModel.log +158 -0
  48. data/ext/uchardet/script/BuildLangModelLogs/LangSloveneModel.log +148 -0
  49. data/ext/uchardet/script/BuildLangModelLogs/LangSpanishModel.log +109 -0
  50. data/ext/uchardet/script/BuildLangModelLogs/LangSwedishModel.log +151 -0
  51. data/ext/uchardet/script/BuildLangModelLogs/LangThaiModel.log +141 -0
  52. data/ext/uchardet/script/BuildLangModelLogs/LangTurkishModel.log +113 -0
  53. data/ext/uchardet/script/BuildLangModelLogs/LangVietnameseModel.log +121 -0
  54. data/ext/uchardet/script/README +63 -0
  55. data/ext/uchardet/script/charsets/codepoints.py +53 -0
  56. data/ext/uchardet/script/charsets/db.py +73 -0
  57. data/ext/uchardet/script/charsets/ibm852.py +72 -0
  58. data/ext/uchardet/script/charsets/iso-8859-1.py +85 -0
  59. data/ext/uchardet/script/charsets/iso-8859-10.py +73 -0
  60. data/ext/uchardet/script/charsets/iso-8859-11.py +77 -0
  61. data/ext/uchardet/script/charsets/iso-8859-13.py +72 -0
  62. data/ext/uchardet/script/charsets/iso-8859-15.py +80 -0
  63. data/ext/uchardet/script/charsets/iso-8859-16.py +83 -0
  64. data/ext/uchardet/script/charsets/iso-8859-2.py +73 -0
  65. data/ext/uchardet/script/charsets/iso-8859-3.py +75 -0
  66. data/ext/uchardet/script/charsets/iso-8859-4.py +73 -0
  67. data/ext/uchardet/script/charsets/iso-8859-6.py +73 -0
  68. data/ext/uchardet/script/charsets/iso-8859-7.py +73 -0
  69. data/ext/uchardet/script/charsets/iso-8859-9.py +76 -0
  70. data/ext/uchardet/script/charsets/mac-centraleurope.py +72 -0
  71. data/ext/uchardet/script/charsets/tis-620.py +77 -0
  72. data/ext/uchardet/script/charsets/viscii.py +72 -0
  73. data/ext/uchardet/script/charsets/windows-1250.py +75 -0
  74. data/ext/uchardet/script/charsets/windows-1252.py +76 -0
  75. data/ext/uchardet/script/charsets/windows-1253.py +72 -0
  76. data/ext/uchardet/script/charsets/windows-1256.py +75 -0
  77. data/ext/uchardet/script/charsets/windows-1257.py +72 -0
  78. data/ext/uchardet/script/charsets/windows-1258.py +72 -0
  79. data/ext/uchardet/script/debug.sh +9 -0
  80. data/ext/uchardet/script/header-template.cpp +38 -0
  81. data/ext/uchardet/script/langs/ar.py +59 -0
  82. data/ext/uchardet/script/langs/cs.py +80 -0
  83. data/ext/uchardet/script/langs/da.py +69 -0
  84. data/ext/uchardet/script/langs/de.py +69 -0
  85. data/ext/uchardet/script/langs/el.py +55 -0
  86. data/ext/uchardet/script/langs/eo.py +67 -0
  87. data/ext/uchardet/script/langs/es.py +69 -0
  88. data/ext/uchardet/script/langs/et.py +57 -0
  89. data/ext/uchardet/script/langs/fi.py +60 -0
  90. data/ext/uchardet/script/langs/fr.py +79 -0
  91. data/ext/uchardet/script/langs/ga.py +60 -0
  92. data/ext/uchardet/script/langs/hr.py +59 -0
  93. data/ext/uchardet/script/langs/hu.py +66 -0
  94. data/ext/uchardet/script/langs/it.py +56 -0
  95. data/ext/uchardet/script/langs/lt.py +70 -0
  96. data/ext/uchardet/script/langs/lv.py +69 -0
  97. data/ext/uchardet/script/langs/mt.py +80 -0
  98. data/ext/uchardet/script/langs/pl.py +81 -0
  99. data/ext/uchardet/script/langs/pt.py +80 -0
  100. data/ext/uchardet/script/langs/ro.py +65 -0
  101. data/ext/uchardet/script/langs/sk.py +80 -0
  102. data/ext/uchardet/script/langs/sl.py +59 -0
  103. data/ext/uchardet/script/langs/sv.py +56 -0
  104. data/ext/uchardet/script/langs/th.py +55 -0
  105. data/ext/uchardet/script/langs/tr.py +67 -0
  106. data/ext/uchardet/script/langs/vi.py +64 -0
  107. data/ext/uchardet/script/release.sh +8 -0
  108. data/ext/uchardet/script/win32.sh +7 -0
  109. data/ext/uchardet/src/Big5Freq.tab +943 -0
  110. data/ext/uchardet/src/CMakeLists.txt +160 -0
  111. data/ext/uchardet/src/CharDistribution.cpp +109 -0
  112. data/ext/uchardet/src/CharDistribution.h +242 -0
  113. data/ext/uchardet/src/EUCKRFreq.tab +614 -0
  114. data/ext/uchardet/src/EUCTWFreq.tab +447 -0
  115. data/ext/uchardet/src/GB2312Freq.tab +491 -0
  116. data/ext/uchardet/src/JISFreq.tab +589 -0
  117. data/ext/uchardet/src/JpCntx.cpp +230 -0
  118. data/ext/uchardet/src/JpCntx.h +140 -0
  119. data/ext/uchardet/src/LangModels/LangArabicModel.cpp +267 -0
  120. data/ext/uchardet/src/LangModels/LangBulgarianModel.cpp +249 -0
  121. data/ext/uchardet/src/LangModels/LangCroatianModel.cpp +298 -0
  122. data/ext/uchardet/src/LangModels/LangCzechModel.cpp +285 -0
  123. data/ext/uchardet/src/LangModels/LangDanishModel.cpp +201 -0
  124. data/ext/uchardet/src/LangModels/LangEsperantoModel.cpp +142 -0
  125. data/ext/uchardet/src/LangModels/LangEstonianModel.cpp +268 -0
  126. data/ext/uchardet/src/LangModels/LangFinnishModel.cpp +297 -0
  127. data/ext/uchardet/src/LangModels/LangFrenchModel.cpp +209 -0
  128. data/ext/uchardet/src/LangModels/LangGermanModel.cpp +170 -0
  129. data/ext/uchardet/src/LangModels/LangGreekModel.cpp +231 -0
  130. data/ext/uchardet/src/LangModels/LangHebrewModel.cpp +220 -0
  131. data/ext/uchardet/src/LangModels/LangHungarianModel.cpp +171 -0
  132. data/ext/uchardet/src/LangModels/LangIrishModel.cpp +234 -0
  133. data/ext/uchardet/src/LangModels/LangItalianModel.cpp +269 -0
  134. data/ext/uchardet/src/LangModels/LangLatvianModel.cpp +210 -0
  135. data/ext/uchardet/src/LangModels/LangLithuanianModel.cpp +209 -0
  136. data/ext/uchardet/src/LangModels/LangMalteseModel.cpp +138 -0
  137. data/ext/uchardet/src/LangModels/LangPolishModel.cpp +304 -0
  138. data/ext/uchardet/src/LangModels/LangPortugueseModel.cpp +241 -0
  139. data/ext/uchardet/src/LangModels/LangRomanianModel.cpp +236 -0
  140. data/ext/uchardet/src/LangModels/LangRussianModel.cpp +367 -0
  141. data/ext/uchardet/src/LangModels/LangSlovakModel.cpp +293 -0
  142. data/ext/uchardet/src/LangModels/LangSloveneModel.cpp +264 -0
  143. data/ext/uchardet/src/LangModels/LangSpanishModel.cpp +204 -0
  144. data/ext/uchardet/src/LangModels/LangSwedishModel.cpp +266 -0
  145. data/ext/uchardet/src/LangModels/LangThaiModel.cpp +267 -0
  146. data/ext/uchardet/src/LangModels/LangTurkishModel.cpp +175 -0
  147. data/ext/uchardet/src/LangModels/LangVietnameseModel.cpp +249 -0
  148. data/ext/uchardet/src/nsBig5Prober.cpp +88 -0
  149. data/ext/uchardet/src/nsBig5Prober.h +75 -0
  150. data/ext/uchardet/src/nsCharSetProber.cpp +125 -0
  151. data/ext/uchardet/src/nsCharSetProber.h +77 -0
  152. data/ext/uchardet/src/nsCodingStateMachine.h +105 -0
  153. data/ext/uchardet/src/nsEUCJPProber.cpp +99 -0
  154. data/ext/uchardet/src/nsEUCJPProber.h +79 -0
  155. data/ext/uchardet/src/nsEUCKRProber.cpp +91 -0
  156. data/ext/uchardet/src/nsEUCKRProber.h +81 -0
  157. data/ext/uchardet/src/nsEUCTWProber.cpp +91 -0
  158. data/ext/uchardet/src/nsEUCTWProber.h +75 -0
  159. data/ext/uchardet/src/nsEscCharsetProber.cpp +101 -0
  160. data/ext/uchardet/src/nsEscCharsetProber.h +70 -0
  161. data/ext/uchardet/src/nsEscSM.cpp +267 -0
  162. data/ext/uchardet/src/nsGB2312Prober.cpp +96 -0
  163. data/ext/uchardet/src/nsGB2312Prober.h +77 -0
  164. data/ext/uchardet/src/nsHebrewProber.cpp +194 -0
  165. data/ext/uchardet/src/nsHebrewProber.h +177 -0
  166. data/ext/uchardet/src/nsLatin1Prober.cpp +182 -0
  167. data/ext/uchardet/src/nsLatin1Prober.h +73 -0
  168. data/ext/uchardet/src/nsMBCSGroupProber.cpp +242 -0
  169. data/ext/uchardet/src/nsMBCSGroupProber.h +81 -0
  170. data/ext/uchardet/src/nsMBCSSM.cpp +513 -0
  171. data/ext/uchardet/src/nsPkgInt.h +89 -0
  172. data/ext/uchardet/src/nsSBCSGroupProber.cpp +343 -0
  173. data/ext/uchardet/src/nsSBCSGroupProber.h +71 -0
  174. data/ext/uchardet/src/nsSBCharSetProber.cpp +160 -0
  175. data/ext/uchardet/src/nsSBCharSetProber.h +258 -0
  176. data/ext/uchardet/src/nsSJISProber.cpp +98 -0
  177. data/ext/uchardet/src/nsSJISProber.h +81 -0
  178. data/ext/uchardet/src/nsUTF8Prober.cpp +87 -0
  179. data/ext/uchardet/src/nsUTF8Prober.h +66 -0
  180. data/ext/uchardet/src/nsUniversalDetector.cpp +339 -0
  181. data/ext/uchardet/src/nsUniversalDetector.h +91 -0
  182. data/ext/uchardet/src/nscore.h +59 -0
  183. data/ext/uchardet/src/prmem.h +49 -0
  184. data/ext/uchardet/src/symbols.cmake +41 -0
  185. data/ext/uchardet/src/tools/CMakeLists.txt +23 -0
  186. data/ext/uchardet/src/tools/uchardet.cpp +254 -0
  187. data/ext/uchardet/src/uchardet.cpp +274 -0
  188. data/ext/uchardet/src/uchardet.h +136 -0
  189. data/ext/uchardet/test/CMakeLists.txt +47 -0
  190. data/ext/uchardet/test/ar/iso-8859-6.txt +3 -0
  191. data/ext/uchardet/test/ar/utf-8.txt +3 -0
  192. data/ext/uchardet/test/ar/windows-1256.txt +3 -0
  193. data/ext/uchardet/test/bg/windows-1251.txt +3 -0
  194. data/ext/uchardet/test/cs/ibm852.txt +4 -0
  195. data/ext/uchardet/test/cs/iso-8859-2.txt +4 -0
  196. data/ext/uchardet/test/cs/mac-centraleurope.txt +4 -0
  197. data/ext/uchardet/test/cs/utf-8.txt +4 -0
  198. data/ext/uchardet/test/cs/windows-1250.txt +4 -0
  199. data/ext/uchardet/test/da/iso-8859-1.txt +7 -0
  200. data/ext/uchardet/test/da/iso-8859-15.txt +10 -0
  201. data/ext/uchardet/test/da/utf-8.txt +10 -0
  202. data/ext/uchardet/test/da/windows-1252.txt +10 -0
  203. data/ext/uchardet/test/de/iso-8859-1.txt +11 -0
  204. data/ext/uchardet/test/de/windows-1252.txt +11 -0
  205. data/ext/uchardet/test/el/iso-8859-7.txt +3 -0
  206. data/ext/uchardet/test/el/utf-8.txt +3 -0
  207. data/ext/uchardet/test/el/windows-1253.txt +5 -0
  208. data/ext/uchardet/test/en/ascii.txt +4 -0
  209. data/ext/uchardet/test/eo/iso-8859-3.txt +7 -0
  210. data/ext/uchardet/test/es/iso-8859-1.txt +5 -0
  211. data/ext/uchardet/test/es/iso-8859-15.txt +5 -0
  212. data/ext/uchardet/test/es/utf-8.txt +5 -0
  213. data/ext/uchardet/test/es/windows-1252.txt +5 -0
  214. data/ext/uchardet/test/et/iso-8859-13.txt +6 -0
  215. data/ext/uchardet/test/et/iso-8859-15.txt +6 -0
  216. data/ext/uchardet/test/et/iso-8859-4.txt +6 -0
  217. data/ext/uchardet/test/et/utf-8.txt +6 -0
  218. data/ext/uchardet/test/et/windows-1252.txt +6 -0
  219. data/ext/uchardet/test/et/windows-1257.txt +6 -0
  220. data/ext/uchardet/test/fi/iso-8859-1.txt +8 -0
  221. data/ext/uchardet/test/fi/utf-8.txt +8 -0
  222. data/ext/uchardet/test/fr/iso-8859-1.txt +5 -0
  223. data/ext/uchardet/test/fr/iso-8859-15.txt +16 -0
  224. data/ext/uchardet/test/fr/utf-16.be +0 -0
  225. data/ext/uchardet/test/fr/utf-32.le +0 -0
  226. data/ext/uchardet/test/fr/utf-8.txt +14 -0
  227. data/ext/uchardet/test/fr/windows-1252.txt +3 -0
  228. data/ext/uchardet/test/ga/iso-8859-1.txt +6 -0
  229. data/ext/uchardet/test/ga/utf-8.txt +6 -0
  230. data/ext/uchardet/test/ga/windows-1252.txt +6 -0
  231. data/ext/uchardet/test/he/iso-8859-8.txt +2 -0
  232. data/ext/uchardet/test/he/utf-8.txt +3 -0
  233. data/ext/uchardet/test/he/windows-1255.txt +1 -0
  234. data/ext/uchardet/test/hr/ibm852.txt +4 -0
  235. data/ext/uchardet/test/hr/iso-8859-13.txt +4 -0
  236. data/ext/uchardet/test/hr/iso-8859-16.txt +4 -0
  237. data/ext/uchardet/test/hr/iso-8859-2.txt +4 -0
  238. data/ext/uchardet/test/hr/mac-centraleurope.txt +4 -0
  239. data/ext/uchardet/test/hr/utf-8.txt +4 -0
  240. data/ext/uchardet/test/hr/windows-1250.txt +4 -0
  241. data/ext/uchardet/test/hu/iso-8859-2.txt +3 -0
  242. data/ext/uchardet/test/hu/windows-1250.txt +1 -0
  243. data/ext/uchardet/test/it/iso-8859-1.txt +18 -0
  244. data/ext/uchardet/test/it/utf-8.txt +18 -0
  245. data/ext/uchardet/test/ja/euc-jp.txt +10 -0
  246. data/ext/uchardet/test/ja/iso-2022-jp.txt +8 -0
  247. data/ext/uchardet/test/ja/shift_jis.txt +1 -0
  248. data/ext/uchardet/test/ja/utf-16be.txt +0 -0
  249. data/ext/uchardet/test/ja/utf-16le.txt +0 -0
  250. data/ext/uchardet/test/ja/utf-8.txt +9 -0
  251. data/ext/uchardet/test/ko/iso-2022-kr.txt +8 -0
  252. data/ext/uchardet/test/ko/uhc.smi +16 -0
  253. data/ext/uchardet/test/ko/utf-16.le +0 -0
  254. data/ext/uchardet/test/ko/utf-32.be +0 -0
  255. data/ext/uchardet/test/ko/utf-8.txt +3 -0
  256. data/ext/uchardet/test/lt/iso-8859-10.txt +3 -0
  257. data/ext/uchardet/test/lt/iso-8859-13.txt +3 -0
  258. data/ext/uchardet/test/lt/iso-8859-4.txt +3 -0
  259. data/ext/uchardet/test/lt/utf-8.txt +3 -0
  260. data/ext/uchardet/test/lv/iso-8859-10.txt +6 -0
  261. data/ext/uchardet/test/lv/iso-8859-13.txt +6 -0
  262. data/ext/uchardet/test/lv/iso-8859-4.txt +6 -0
  263. data/ext/uchardet/test/lv/utf-8.txt +6 -0
  264. data/ext/uchardet/test/mt/iso-8859-3.txt +4 -0
  265. data/ext/uchardet/test/mt/utf-8.txt +4 -0
  266. data/ext/uchardet/test/pl/ibm852.txt +3 -0
  267. data/ext/uchardet/test/pl/iso-8859-13.txt +3 -0
  268. data/ext/uchardet/test/pl/iso-8859-16.txt +3 -0
  269. data/ext/uchardet/test/pl/iso-8859-2.txt +3 -0
  270. data/ext/uchardet/test/pl/mac-centraleurope.txt +3 -0
  271. data/ext/uchardet/test/pl/utf-8.txt +3 -0
  272. data/ext/uchardet/test/pl/windows-1250.txt +3 -0
  273. data/ext/uchardet/test/pt/iso-8859-1.txt +6 -0
  274. data/ext/uchardet/test/pt/utf-8.txt +6 -0
  275. data/ext/uchardet/test/ro/ibm852.txt +9 -0
  276. data/ext/uchardet/test/ro/iso-8859-16.txt +9 -0
  277. data/ext/uchardet/test/ro/utf-8.txt +9 -0
  278. data/ext/uchardet/test/ro/windows-1250.txt +9 -0
  279. data/ext/uchardet/test/ru/ibm855.txt +5 -0
  280. data/ext/uchardet/test/ru/ibm866.txt +11 -0
  281. data/ext/uchardet/test/ru/iso-8859-5.txt +3 -0
  282. data/ext/uchardet/test/ru/koi8-r.txt +1 -0
  283. data/ext/uchardet/test/ru/mac-cyrillic.txt +9 -0
  284. data/ext/uchardet/test/ru/windows-1251.txt +4 -0
  285. data/ext/uchardet/test/sk/ibm852.txt +3 -0
  286. data/ext/uchardet/test/sk/iso-8859-2.txt +3 -0
  287. data/ext/uchardet/test/sk/mac-centraleurope.txt +3 -0
  288. data/ext/uchardet/test/sk/utf-8.txt +3 -0
  289. data/ext/uchardet/test/sk/windows-1250.txt +3 -0
  290. data/ext/uchardet/test/sl/ibm852.txt +9 -0
  291. data/ext/uchardet/test/sl/iso-8859-16.txt +9 -0
  292. data/ext/uchardet/test/sl/iso-8859-2.txt +9 -0
  293. data/ext/uchardet/test/sl/mac-centraleurope.txt +9 -0
  294. data/ext/uchardet/test/sl/utf-8.txt +9 -0
  295. data/ext/uchardet/test/sl/windows-1250.txt +9 -0
  296. data/ext/uchardet/test/sv/iso-8859-1.txt +10 -0
  297. data/ext/uchardet/test/sv/utf-8.txt +10 -0
  298. data/ext/uchardet/test/sv/windows-1252.txt +10 -0
  299. data/ext/uchardet/test/th/iso-8859-11.txt +5 -0
  300. data/ext/uchardet/test/th/tis-620.txt +5 -0
  301. data/ext/uchardet/test/th/utf-8.txt +1 -0
  302. data/ext/uchardet/test/tr/iso-8859-3.txt +13 -0
  303. data/ext/uchardet/test/tr/iso-8859-9.txt +13 -0
  304. data/ext/uchardet/test/uchardet-tests.c +130 -0
  305. data/ext/uchardet/test/vi/utf-8.txt +4 -0
  306. data/ext/uchardet/test/vi/viscii.txt +4 -0
  307. data/ext/uchardet/test/vi/windows-1258.txt +4 -0
  308. data/ext/uchardet/test/zh/big5.txt +1 -0
  309. data/ext/uchardet/test/zh/euc-tw.txt +1 -0
  310. data/ext/uchardet/test/zh/gb18030.txt +1 -0
  311. data/ext/uchardet/test/zh/utf-8.txt +1 -0
  312. data/ext/uchardet/uchardet.doap +51 -0
  313. data/ext/uchardet/uchardet.pc.in +10 -0
  314. data/lib/cchardet.rb +56 -0
  315. data/lib/cchardet/lib_finder.rb +32 -0
  316. data/lib/cchardet/version.rb +5 -0
  317. metadata +362 -0
@@ -0,0 +1,81 @@
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
+
38
+ // for S-JIS encoding, obeserve characteristic:
39
+ // 1, kana character (or hankaku?) often have hight frequency of appereance
40
+ // 2, kana character often exist in group
41
+ // 3, certain combination of kana is never used in japanese language
42
+
43
+ #ifndef nsSJISProber_h__
44
+ #define nsSJISProber_h__
45
+
46
+ #include "nsCharSetProber.h"
47
+ #include "nsCodingStateMachine.h"
48
+ #include "JpCntx.h"
49
+ #include "CharDistribution.h"
50
+
51
+
52
+ class nsSJISProber: public nsCharSetProber {
53
+ public:
54
+ nsSJISProber(PRBool aIsPreferredLanguage)
55
+ :mIsPreferredLanguage(aIsPreferredLanguage)
56
+ {mCodingSM = new nsCodingStateMachine(&SJISSMModel);
57
+ Reset();}
58
+ virtual ~nsSJISProber(void){delete mCodingSM;}
59
+ nsProbingState HandleData(const char* aBuf, PRUint32 aLen);
60
+ const char* GetCharSetName() {return "SHIFT_JIS";}
61
+ const char* GetLanguage() {return "ja";}
62
+ nsProbingState GetState(void) {return mState;}
63
+ void Reset(void);
64
+ float GetConfidence(void);
65
+ void SetOpion() {}
66
+
67
+ protected:
68
+ nsCodingStateMachine* mCodingSM;
69
+ nsProbingState mState;
70
+
71
+ SJISContextAnalysis mContextAnalyser;
72
+ SJISDistributionAnalysis mDistributionAnalyser;
73
+
74
+ char mLastChar[2];
75
+ PRBool mIsPreferredLanguage;
76
+
77
+ };
78
+
79
+
80
+ #endif /* nsSJISProber_h__ */
81
+
@@ -0,0 +1,87 @@
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
+
38
+ #include "nsUTF8Prober.h"
39
+
40
+ void nsUTF8Prober::Reset(void)
41
+ {
42
+ mCodingSM->Reset();
43
+ mNumOfMBChar = 0;
44
+ mState = eDetecting;
45
+ }
46
+
47
+ nsProbingState nsUTF8Prober::HandleData(const char* aBuf, PRUint32 aLen)
48
+ {
49
+ PRUint32 codingState;
50
+
51
+ for (PRUint32 i = 0; i < aLen; i++)
52
+ {
53
+ codingState = mCodingSM->NextState(aBuf[i]);
54
+ if (codingState == eItsMe)
55
+ {
56
+ mState = eFoundIt;
57
+ break;
58
+ }
59
+ if (codingState == eStart)
60
+ {
61
+ if (mCodingSM->GetCurrentCharLen() >= 2)
62
+ mNumOfMBChar++;
63
+ }
64
+ }
65
+
66
+ if (mState == eDetecting)
67
+ if (GetConfidence() > SHORTCUT_THRESHOLD)
68
+ mState = eFoundIt;
69
+ return mState;
70
+ }
71
+
72
+ #define ONE_CHAR_PROB (float)0.50
73
+
74
+ float nsUTF8Prober::GetConfidence(void)
75
+ {
76
+ float unlike = (float)0.99;
77
+
78
+ if (mNumOfMBChar < 6)
79
+ {
80
+ for (PRUint32 i = 0; i < mNumOfMBChar; i++)
81
+ unlike *= ONE_CHAR_PROB;
82
+ return (float)1.0 - unlike;
83
+ }
84
+ else
85
+ return (float)0.99;
86
+ }
87
+
@@ -0,0 +1,66 @@
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
+
38
+ #ifndef nsUTF8Prober_h__
39
+ #define nsUTF8Prober_h__
40
+
41
+ #include <cstddef>
42
+ #include "nsCharSetProber.h"
43
+ #include "nsCodingStateMachine.h"
44
+
45
+ class nsUTF8Prober: public nsCharSetProber {
46
+ public:
47
+ nsUTF8Prober(){mNumOfMBChar = 0;
48
+ mCodingSM = new nsCodingStateMachine(&UTF8SMModel);
49
+ Reset(); }
50
+ virtual ~nsUTF8Prober(){delete mCodingSM;}
51
+ nsProbingState HandleData(const char* aBuf, PRUint32 aLen);
52
+ const char* GetCharSetName() {return "UTF-8";}
53
+ const char* GetLanguage() {return NULL;}
54
+ nsProbingState GetState(void) {return mState;}
55
+ void Reset(void);
56
+ float GetConfidence(void);
57
+ void SetOpion() {}
58
+
59
+ protected:
60
+ nsCodingStateMachine* mCodingSM;
61
+ nsProbingState mState;
62
+ PRUint32 mNumOfMBChar;
63
+ };
64
+
65
+ #endif /* nsUTF8Prober_h__ */
66
+
@@ -0,0 +1,339 @@
1
+ /* -*- Mode: C++; tab-width: 2; 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 Universal charset detector 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) 2001
20
+ * the Initial Developer. All Rights Reserved.
21
+ *
22
+ * Contributor(s):
23
+ * Shy Shalom <shooshX@gmail.com>
24
+ *
25
+ * Alternatively, the contents of this file may be used under the terms of
26
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
27
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
+ * in which case the provisions of the GPL or the LGPL are applicable instead
29
+ * of those above. If you wish to allow use of your version of this file only
30
+ * under the terms of either the GPL or the LGPL, and not to allow others to
31
+ * use your version of this file under the terms of the MPL, indicate your
32
+ * decision by deleting the provisions above and replace them with the notice
33
+ * and other provisions required by the GPL or the LGPL. If you do not delete
34
+ * the provisions above, a recipient may use your version of this file under
35
+ * the terms of any one of the MPL, the GPL or the LGPL.
36
+ *
37
+ * ***** END LICENSE BLOCK ***** */
38
+
39
+ #include "nscore.h"
40
+
41
+ #include "nsUniversalDetector.h"
42
+
43
+ #include "nsMBCSGroupProber.h"
44
+ #include "nsSBCSGroupProber.h"
45
+ #include "nsEscCharsetProber.h"
46
+ #include "nsLatin1Prober.h"
47
+
48
+ nsUniversalDetector::nsUniversalDetector(PRUint32 aLanguageFilter)
49
+ {
50
+ mNbspFound = PR_FALSE;
51
+ mDone = PR_FALSE;
52
+ mBestGuess = -1; //illegal value as signal
53
+ mInTag = PR_FALSE;
54
+ mEscCharSetProber = nsnull;
55
+
56
+ mStart = PR_TRUE;
57
+ mDetectedCharset = nsnull;
58
+ mGotData = PR_FALSE;
59
+ mInputState = ePureAscii;
60
+ mLastChar = '\0';
61
+ mLanguageFilter = aLanguageFilter;
62
+
63
+ PRUint32 i;
64
+ for (i = 0; i < NUM_OF_CHARSET_PROBERS; i++)
65
+ mCharSetProbers[i] = nsnull;
66
+ }
67
+
68
+ nsUniversalDetector::~nsUniversalDetector()
69
+ {
70
+ for (PRInt32 i = 0; i < NUM_OF_CHARSET_PROBERS; i++)
71
+ delete mCharSetProbers[i];
72
+
73
+ delete mEscCharSetProber;
74
+ }
75
+
76
+ void
77
+ nsUniversalDetector::Reset()
78
+ {
79
+ mNbspFound = PR_FALSE;
80
+ mDone = PR_FALSE;
81
+ mBestGuess = -1; //illegal value as signal
82
+ mInTag = PR_FALSE;
83
+
84
+ mStart = PR_TRUE;
85
+ mDetectedCharset = nsnull;
86
+ mGotData = PR_FALSE;
87
+ mInputState = ePureAscii;
88
+ mLastChar = '\0';
89
+
90
+ if (mEscCharSetProber)
91
+ mEscCharSetProber->Reset();
92
+
93
+ PRUint32 i;
94
+ for (i = 0; i < NUM_OF_CHARSET_PROBERS; i++)
95
+ if (mCharSetProbers[i])
96
+ mCharSetProbers[i]->Reset();
97
+ }
98
+
99
+ //---------------------------------------------------------------------
100
+ #define SHORTCUT_THRESHOLD (float)0.95
101
+ #define MINIMUM_THRESHOLD (float)0.20
102
+
103
+ nsresult nsUniversalDetector::HandleData(const char* aBuf, PRUint32 aLen)
104
+ {
105
+ if(mDone)
106
+ return NS_OK;
107
+
108
+ if (aLen > 0)
109
+ mGotData = PR_TRUE;
110
+
111
+ /* If the data starts with BOM, we know it is UTF. */
112
+ if (mStart)
113
+ {
114
+ mStart = PR_FALSE;
115
+ if (aLen > 2)
116
+ {
117
+ switch (aBuf[0])
118
+ {
119
+ case '\xEF':
120
+ if (('\xBB' == aBuf[1]) && ('\xBF' == aBuf[2]))
121
+ /* EF BB BF: UTF-8 encoded BOM. */
122
+ mDetectedCharset = "UTF-8";
123
+ break;
124
+ case '\xFE':
125
+ if ('\xFF' == aBuf[1])
126
+ /* FE FF: UTF-16, big endian BOM. */
127
+ mDetectedCharset = "UTF-16";
128
+ break;
129
+ case '\xFF':
130
+ if ('\xFE' == aBuf[1])
131
+ {
132
+ if (aLen > 3 &&
133
+ aBuf[2] == '\x00' &&
134
+ aBuf[3] == '\x00')
135
+ {
136
+ /* FF FE 00 00: UTF-32 (LE). */
137
+ mDetectedCharset = "UTF-32";
138
+ }
139
+ else
140
+ {
141
+ /* FF FE: UTF-16, little endian BOM. */
142
+ mDetectedCharset = "UTF-16";
143
+ }
144
+ }
145
+ break;
146
+ case '\x00':
147
+ if (aLen > 3 &&
148
+ aBuf[1] == '\x00' &&
149
+ aBuf[2] == '\xFE' &&
150
+ aBuf[3] == '\xFF')
151
+ {
152
+ /* 00 00 FE FF: UTF-32 (BE). */
153
+ mDetectedCharset = "UTF-32";
154
+ }
155
+ break;
156
+ }
157
+ }
158
+
159
+ if (mDetectedCharset)
160
+ {
161
+ mDone = PR_TRUE;
162
+ return NS_OK;
163
+ }
164
+ }
165
+
166
+ PRUint32 i;
167
+ for (i = 0; i < aLen; i++)
168
+ {
169
+ /* If every other character is ASCII or 0xA0, we don't run charset
170
+ * probers.
171
+ * 0xA0 (NBSP in a few charset) is apparently a rare exception
172
+ * of non-ASCII character often contained in nearly-ASCII text. */
173
+ if (aBuf[i] & '\x80' && aBuf[i] != '\xA0')
174
+ {
175
+ /* We got a non-ASCII byte (high-byte) */
176
+ if (mInputState != eHighbyte)
177
+ {
178
+ //adjust state
179
+ mInputState = eHighbyte;
180
+
181
+ //kill mEscCharSetProber if it is active
182
+ if (mEscCharSetProber) {
183
+ delete mEscCharSetProber;
184
+ mEscCharSetProber = nsnull;
185
+ }
186
+
187
+ //start multibyte and singlebyte charset prober
188
+ if (nsnull == mCharSetProbers[0])
189
+ {
190
+ mCharSetProbers[0] = new nsMBCSGroupProber(mLanguageFilter);
191
+ if (nsnull == mCharSetProbers[0])
192
+ return NS_ERROR_OUT_OF_MEMORY;
193
+ }
194
+ if (nsnull == mCharSetProbers[1] &&
195
+ (mLanguageFilter & NS_FILTER_NON_CJK))
196
+ {
197
+ mCharSetProbers[1] = new nsSBCSGroupProber;
198
+ if (nsnull == mCharSetProbers[1])
199
+ return NS_ERROR_OUT_OF_MEMORY;
200
+ }
201
+ if (nsnull == mCharSetProbers[2])
202
+ {
203
+ mCharSetProbers[2] = new nsLatin1Prober;
204
+ if (nsnull == mCharSetProbers[2])
205
+ return NS_ERROR_OUT_OF_MEMORY;
206
+ }
207
+ }
208
+ }
209
+ else
210
+ {
211
+ /* Just pure ASCII or NBSP so far. */
212
+ if (aBuf[i] == '\xA0')
213
+ {
214
+ /* ASCII with the only exception of NBSP seems quite common.
215
+ * I doubt it is really necessary to train a model here, so let's
216
+ * just make an exception.
217
+ */
218
+ mNbspFound = PR_TRUE;
219
+ }
220
+ else if (mInputState == ePureAscii &&
221
+ (aBuf[i] == '\033' || (aBuf[i] == '{' && mLastChar == '~')))
222
+ {
223
+ /* We found an escape character or HZ "~{". */
224
+ mInputState = eEscAscii;
225
+ }
226
+ mLastChar = aBuf[i];
227
+ }
228
+ }
229
+
230
+ nsProbingState st;
231
+ switch (mInputState)
232
+ {
233
+ case eEscAscii:
234
+ if (nsnull == mEscCharSetProber) {
235
+ mEscCharSetProber = new nsEscCharSetProber(mLanguageFilter);
236
+ if (nsnull == mEscCharSetProber)
237
+ return NS_ERROR_OUT_OF_MEMORY;
238
+ }
239
+ st = mEscCharSetProber->HandleData(aBuf, aLen);
240
+ if (st == eFoundIt)
241
+ {
242
+ mDone = PR_TRUE;
243
+ mDetectedCharset = mEscCharSetProber->GetCharSetName();
244
+ }
245
+ break;
246
+ case eHighbyte:
247
+ for (i = 0; i < NUM_OF_CHARSET_PROBERS; i++)
248
+ {
249
+ if (mCharSetProbers[i])
250
+ {
251
+ st = mCharSetProbers[i]->HandleData(aBuf, aLen);
252
+ if (st == eFoundIt)
253
+ {
254
+ mDone = PR_TRUE;
255
+ mDetectedCharset = mCharSetProbers[i]->GetCharSetName();
256
+ return NS_OK;
257
+ }
258
+ }
259
+ }
260
+ break;
261
+
262
+ default:
263
+ break;
264
+ }
265
+ return NS_OK;
266
+ }
267
+
268
+
269
+ //---------------------------------------------------------------------
270
+ void nsUniversalDetector::DataEnd()
271
+ {
272
+ if (!mGotData)
273
+ {
274
+ // we haven't got any data yet, return immediately
275
+ // caller program sometimes call DataEnd before anything has been sent to detector
276
+ return;
277
+ }
278
+
279
+ if (! mDetectedCharset)
280
+ {
281
+ switch (mInputState)
282
+ {
283
+ case eEscAscii:
284
+ case ePureAscii:
285
+ if (mNbspFound)
286
+ {
287
+ /* ISO-8859-1 is a good result candidate for ASCII + NBSP.
288
+ * (though it could have been any ISO-8859 encoding). */
289
+ mDetectedCharset = "ISO-8859-1";
290
+ }
291
+ else
292
+ {
293
+ /* ASCII with the ESC character (or the sequence "~{") is still
294
+ * ASCII until proven otherwise. */
295
+ mDetectedCharset = "ASCII";
296
+ }
297
+ default:
298
+ break;
299
+ }
300
+ }
301
+
302
+ if (mDetectedCharset)
303
+ {
304
+ /* These cases are limited enough that we are always confident
305
+ * when finding them.
306
+ */
307
+ mDone = PR_TRUE;
308
+ Report(mDetectedCharset, NULL, 1.0);
309
+ return;
310
+ }
311
+
312
+ switch (mInputState)
313
+ {
314
+ case eHighbyte:
315
+ {
316
+ float proberConfidence;
317
+
318
+ for (PRInt32 i = 0; i < NUM_OF_CHARSET_PROBERS; i++)
319
+ {
320
+ if (mCharSetProbers[i])
321
+ {
322
+ proberConfidence = mCharSetProbers[i]->GetConfidence();
323
+
324
+ if (proberConfidence > MINIMUM_THRESHOLD)
325
+ /* Only report what we are confident in. */
326
+ Report(mCharSetProbers[i]->GetCharSetName(),
327
+ mCharSetProbers[i]->GetLanguage(),
328
+ proberConfidence);
329
+ }
330
+ }
331
+ }
332
+ break;
333
+ case eEscAscii:
334
+ break;
335
+ default:
336
+ ;
337
+ }
338
+ return;
339
+ }