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,194 @@
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 Universal charset detector code.
16
+ *
17
+ * The Initial Developer of the Original Code is
18
+ * Shy Shalom <shooshX@gmail.com>
19
+ * Portions created by the Initial Developer are Copyright (C) 2005
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 "nsHebrewProber.h"
39
+ #include <stdio.h>
40
+
41
+ // windows-1255 / ISO-8859-8 code points of interest
42
+ #define FINAL_KAF ('\xea')
43
+ #define NORMAL_KAF ('\xeb')
44
+ #define FINAL_MEM ('\xed')
45
+ #define NORMAL_MEM ('\xee')
46
+ #define FINAL_NUN ('\xef')
47
+ #define NORMAL_NUN ('\xf0')
48
+ #define FINAL_PE ('\xf3')
49
+ #define NORMAL_PE ('\xf4')
50
+ #define FINAL_TSADI ('\xf5')
51
+ #define NORMAL_TSADI ('\xf6')
52
+
53
+ // Minimum Visual vs Logical final letter score difference.
54
+ // If the difference is below this, don't rely solely on the final letter score distance.
55
+ #define MIN_FINAL_CHAR_DISTANCE (5)
56
+
57
+ // Minimum Visual vs Logical model score difference.
58
+ // If the difference is below this, don't rely at all on the model score distance.
59
+ #define MIN_MODEL_DISTANCE (0.01)
60
+
61
+ #define VISUAL_HEBREW_NAME ("ISO-8859-8")
62
+ #define LOGICAL_HEBREW_NAME ("WINDOWS-1255")
63
+
64
+ PRBool nsHebrewProber::isFinal(char c)
65
+ {
66
+ return ((c == FINAL_KAF) || (c == FINAL_MEM) || (c == FINAL_NUN) || (c == FINAL_PE) || (c == FINAL_TSADI));
67
+ }
68
+
69
+ PRBool nsHebrewProber::isNonFinal(char c)
70
+ {
71
+ return ((c == NORMAL_KAF) || (c == NORMAL_MEM) || (c == NORMAL_NUN) || (c == NORMAL_PE));
72
+ // The normal Tsadi is not a good Non-Final letter due to words like
73
+ // 'lechotet' (to chat) containing an apostrophe after the tsadi. This
74
+ // apostrophe is converted to a space in FilterWithoutEnglishLetters causing
75
+ // the Non-Final tsadi to appear at an end of a word even though this is not
76
+ // the case in the original text.
77
+ // The letters Pe and Kaf rarely display a related behavior of not being a
78
+ // good Non-Final letter. Words like 'Pop', 'Winamp' and 'Mubarak' for
79
+ // example legally end with a Non-Final Pe or Kaf. However, the benefit of
80
+ // these letters as Non-Final letters outweighs the damage since these words
81
+ // are quite rare.
82
+ }
83
+
84
+ /** HandleData
85
+ * Final letter analysis for logical-visual decision.
86
+ * Look for evidence that the received buffer is either logical Hebrew or
87
+ * visual Hebrew.
88
+ * The following cases are checked:
89
+ * 1) A word longer than 1 letter, ending with a final letter. This is an
90
+ * indication that the text is laid out "naturally" since the final letter
91
+ * really appears at the end. +1 for logical score.
92
+ * 2) A word longer than 1 letter, ending with a Non-Final letter. In normal
93
+ * Hebrew, words ending with Kaf, Mem, Nun, Pe or Tsadi, should not end with
94
+ * the Non-Final form of that letter. Exceptions to this rule are mentioned
95
+ * above in isNonFinal(). This is an indication that the text is laid out
96
+ * backwards. +1 for visual score
97
+ * 3) A word longer than 1 letter, starting with a final letter. Final letters
98
+ * should not appear at the beginning of a word. This is an indication that
99
+ * the text is laid out backwards. +1 for visual score.
100
+ *
101
+ * The visual score and logical score are accumulated throughout the text and
102
+ * are finally checked against each other in GetCharSetName().
103
+ * No checking for final letters in the middle of words is done since that case
104
+ * is not an indication for either Logical or Visual text.
105
+ *
106
+ * The input buffer should not contain any white spaces that are not (' ')
107
+ * or any low-ascii punctuation marks.
108
+ */
109
+ nsProbingState nsHebrewProber::HandleData(const char* aBuf, PRUint32 aLen)
110
+ {
111
+ // Both model probers say it's not them. No reason to continue.
112
+ if (GetState() == eNotMe)
113
+ return eNotMe;
114
+
115
+ const char *curPtr, *endPtr = aBuf+aLen;
116
+ char cur;
117
+
118
+ for (curPtr = (char*)aBuf; curPtr < endPtr; ++curPtr)
119
+ {
120
+ cur = *curPtr;
121
+ if (cur == ' ') // We stand on a space - a word just ended
122
+ {
123
+ if (mBeforePrev != ' ') // *(curPtr-2) was not a space so prev is not a 1 letter word
124
+ {
125
+ if (isFinal(mPrev)) // case (1) [-2:not space][-1:final letter][cur:space]
126
+ ++mFinalCharLogicalScore;
127
+ else if (isNonFinal(mPrev)) // case (2) [-2:not space][-1:Non-Final letter][cur:space]
128
+ ++mFinalCharVisualScore;
129
+ }
130
+ }
131
+ else // Not standing on a space
132
+ {
133
+ if ((mBeforePrev == ' ') && (isFinal(mPrev)) && (cur != ' ')) // case (3) [-2:space][-1:final letter][cur:not space]
134
+ ++mFinalCharVisualScore;
135
+ }
136
+ mBeforePrev = mPrev;
137
+ mPrev = cur;
138
+ }
139
+
140
+ // Forever detecting, till the end or until both model probers return eNotMe (handled above).
141
+ return eDetecting;
142
+ }
143
+
144
+ // Make the decision: is it Logical or Visual?
145
+ const char* nsHebrewProber::GetCharSetName()
146
+ {
147
+ // If the final letter score distance is dominant enough, rely on it.
148
+ PRInt32 finalsub = mFinalCharLogicalScore - mFinalCharVisualScore;
149
+ if (finalsub >= MIN_FINAL_CHAR_DISTANCE)
150
+ return LOGICAL_HEBREW_NAME;
151
+ if (finalsub <= -(MIN_FINAL_CHAR_DISTANCE))
152
+ return VISUAL_HEBREW_NAME;
153
+
154
+ // It's not dominant enough, try to rely on the model scores instead.
155
+ float modelsub = mLogicalProb->GetConfidence() - mVisualProb->GetConfidence();
156
+ if (modelsub > MIN_MODEL_DISTANCE)
157
+ return LOGICAL_HEBREW_NAME;
158
+ if (modelsub < -(MIN_MODEL_DISTANCE))
159
+ return VISUAL_HEBREW_NAME;
160
+
161
+ // Still no good, back to final letter distance, maybe it'll save the day.
162
+ if (finalsub < 0)
163
+ return VISUAL_HEBREW_NAME;
164
+
165
+ // (finalsub > 0 - Logical) or (don't know what to do) default to Logical.
166
+ return LOGICAL_HEBREW_NAME;
167
+ }
168
+
169
+
170
+ void nsHebrewProber::Reset(void)
171
+ {
172
+ mFinalCharLogicalScore = 0;
173
+ mFinalCharVisualScore = 0;
174
+
175
+ // mPrev and mBeforePrev are initialized to space in order to simulate a word
176
+ // delimiter at the beginning of the data
177
+ mPrev = ' ';
178
+ mBeforePrev = ' ';
179
+ }
180
+
181
+ nsProbingState nsHebrewProber::GetState(void)
182
+ {
183
+ // Remain active as long as any of the model probers are active.
184
+ if ((mLogicalProb->GetState() == eNotMe) && (mVisualProb->GetState() == eNotMe))
185
+ return eNotMe;
186
+ return eDetecting;
187
+ }
188
+
189
+ #ifdef DEBUG_chardet
190
+ void nsHebrewProber::DumpStatus()
191
+ {
192
+ printf(" HEB: %d - %d [Logical-Visual score]\r\n", mFinalCharLogicalScore, mFinalCharVisualScore);
193
+ }
194
+ #endif
@@ -0,0 +1,177 @@
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 Universal charset detector code.
16
+ *
17
+ * The Initial Developer of the Original Code is
18
+ * Shy Shalom <shooshX@gmail.com>
19
+ * Portions created by the Initial Developer are Copyright (C) 2005
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 nsHebrewProber_h__
39
+ #define nsHebrewProber_h__
40
+
41
+ #include "nsSBCharSetProber.h"
42
+
43
+ // This prober doesn't actually recognize a language or a charset.
44
+ // It is a helper prober for the use of the Hebrew model probers
45
+ class nsHebrewProber: public nsCharSetProber
46
+ {
47
+ public:
48
+ nsHebrewProber(void) :mLogicalProb(0), mVisualProb(0) { Reset(); }
49
+
50
+ virtual ~nsHebrewProber(void) {}
51
+ virtual nsProbingState HandleData(const char* aBuf, PRUint32 aLen);
52
+ virtual const char *GetCharSetName();
53
+ virtual const char *GetLanguage(void) { return "he"; }
54
+ virtual void Reset(void);
55
+
56
+ virtual nsProbingState GetState(void);
57
+
58
+ virtual float GetConfidence(void) { return (float)0.0; }
59
+ virtual void SetOpion() {}
60
+
61
+ void SetModelProbers(nsCharSetProber *logicalPrb, nsCharSetProber *visualPrb)
62
+ { mLogicalProb = logicalPrb; mVisualProb = visualPrb; }
63
+
64
+ #ifdef DEBUG_chardet
65
+ virtual void DumpStatus();
66
+ #endif
67
+
68
+ protected:
69
+ static PRBool isFinal(char c);
70
+ static PRBool isNonFinal(char c);
71
+
72
+ PRInt32 mFinalCharLogicalScore, mFinalCharVisualScore;
73
+
74
+ // The two last characters seen in the previous buffer.
75
+ char mPrev, mBeforePrev;
76
+
77
+ // These probers are owned by the group prober.
78
+ nsCharSetProber *mLogicalProb, *mVisualProb;
79
+ };
80
+
81
+ /**
82
+ * ** General ideas of the Hebrew charset recognition **
83
+ *
84
+ * Four main charsets exist in Hebrew:
85
+ * "ISO-8859-8" - Visual Hebrew
86
+ * "windows-1255" - Logical Hebrew
87
+ * "ISO-8859-8-I" - Logical Hebrew
88
+ * "x-mac-hebrew" - ?? Logical Hebrew ??
89
+ *
90
+ * Both "ISO" charsets use a completely identical set of code points, whereas
91
+ * "windows-1255" and "x-mac-hebrew" are two different proper supersets of
92
+ * these code points. windows-1255 defines additional characters in the range
93
+ * 0x80-0x9F as some misc punctuation marks as well as some Hebrew-specific
94
+ * diacritics and additional 'Yiddish' ligature letters in the range 0xc0-0xd6.
95
+ * x-mac-hebrew defines similar additional code points but with a different
96
+ * mapping.
97
+ *
98
+ * As far as an average Hebrew text with no diacritics is concerned, all four
99
+ * charsets are identical with respect to code points. Meaning that for the
100
+ * main Hebrew alphabet, all four map the same values to all 27 Hebrew letters
101
+ * (including final letters).
102
+ *
103
+ * The dominant difference between these charsets is their directionality.
104
+ * "Visual" directionality means that the text is ordered as if the renderer is
105
+ * not aware of a BIDI rendering algorithm. The renderer sees the text and
106
+ * draws it from left to right. The text itself when ordered naturally is read
107
+ * backwards. A buffer of Visual Hebrew generally looks like so:
108
+ * "[last word of first line spelled backwards] [whole line ordered backwards
109
+ * and spelled backwards] [first word of first line spelled backwards]
110
+ * [end of line] [last word of second line] ... etc' "
111
+ * adding punctuation marks, numbers and English text to visual text is
112
+ * naturally also "visual" and from left to right.
113
+ *
114
+ * "Logical" directionality means the text is ordered "naturally" according to
115
+ * the order it is read. It is the responsibility of the renderer to display
116
+ * the text from right to left. A BIDI algorithm is used to place general
117
+ * punctuation marks, numbers and English text in the text.
118
+ *
119
+ * Texts in x-mac-hebrew are almost impossible to find on the Internet. From
120
+ * what little evidence I could find, it seems that its general directionality
121
+ * is Logical.
122
+ *
123
+ * To sum up all of the above, the Hebrew probing mechanism knows about two
124
+ * charsets:
125
+ * Visual Hebrew - "ISO-8859-8" - backwards text - Words and sentences are
126
+ * backwards while line order is natural. For charset recognition purposes
127
+ * the line order is unimportant (In fact, for this implementation, even
128
+ * word order is unimportant).
129
+ * Logical Hebrew - "windows-1255" - normal, naturally ordered text.
130
+ *
131
+ * "ISO-8859-8-I" is a subset of windows-1255 and doesn't need to be
132
+ * specifically identified.
133
+ * "x-mac-hebrew" is also identified as windows-1255. A text in x-mac-hebrew
134
+ * that contain special punctuation marks or diacritics is displayed with
135
+ * some unconverted characters showing as question marks. This problem might
136
+ * be corrected using another model prober for x-mac-hebrew. Due to the fact
137
+ * that x-mac-hebrew texts are so rare, writing another model prober isn't
138
+ * worth the effort and performance hit.
139
+ *
140
+ * *** The Prober ***
141
+ *
142
+ * The prober is divided between two nsSBCharSetProbers and an nsHebrewProber,
143
+ * all of which are managed, created, fed data, inquired and deleted by the
144
+ * nsSBCSGroupProber. The two nsSBCharSetProbers identify that the text is in
145
+ * fact some kind of Hebrew, Logical or Visual. The final decision about which
146
+ * one is it is made by the nsHebrewProber by combining final-letter scores
147
+ * with the scores of the two nsSBCharSetProbers to produce a final answer.
148
+ *
149
+ * The nsSBCSGroupProber is responsible for stripping the original text of HTML
150
+ * tags, English characters, numbers, low-ASCII punctuation characters, spaces
151
+ * and new lines. It reduces any sequence of such characters to a single space.
152
+ * The buffer fed to each prober in the SBCS group prober is pure text in
153
+ * high-ASCII.
154
+ * The two nsSBCharSetProbers (model probers) share the same language model:
155
+ * Win1255Model.
156
+ * The first nsSBCharSetProber uses the model normally as any other
157
+ * nsSBCharSetProber does, to recognize windows-1255, upon which this model was
158
+ * built. The second nsSBCharSetProber is told to make the pair-of-letter
159
+ * lookup in the language model backwards. This in practice exactly simulates
160
+ * a visual Hebrew model using the windows-1255 logical Hebrew model.
161
+ *
162
+ * The nsHebrewProber is not using any language model. All it does is look for
163
+ * final-letter evidence suggesting the text is either logical Hebrew or visual
164
+ * Hebrew. Disjointed from the model probers, the results of the nsHebrewProber
165
+ * alone are meaningless. nsHebrewProber always returns 0.00 as confidence
166
+ * since it never identifies a charset by itself. Instead, the pointer to the
167
+ * nsHebrewProber is passed to the model probers as a helper "Name Prober".
168
+ * When the Group prober receives a positive identification from any prober,
169
+ * it asks for the name of the charset identified. If the prober queried is a
170
+ * Hebrew model prober, the model prober forwards the call to the
171
+ * nsHebrewProber to make the final decision. In the nsHebrewProber, the
172
+ * decision is made according to the final-letters scores maintained and Both
173
+ * model probers scores. The answer is returned in the form of the name of the
174
+ * charset identified, either "windows-1255" or "ISO-8859-8".
175
+ *
176
+ */
177
+ #endif /* nsHebrewProber_h__ */
@@ -0,0 +1,182 @@
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 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 "nsLatin1Prober.h"
40
+ #include "prmem.h"
41
+ #include <stdio.h>
42
+
43
+ #define UDF 0 // undefined
44
+ #define OTH 1 //other
45
+ #define ASC 2 // ascii capital letter
46
+ #define ASS 3 // ascii small letter
47
+ #define ACV 4 // accent capital vowel
48
+ #define ACO 5 // accent capital other
49
+ #define ASV 6 // accent small vowel
50
+ #define ASO 7 // accent small other
51
+ #define CLASS_NUM 8 // total classes
52
+
53
+ static const unsigned char Latin1_CharToClass[] =
54
+ {
55
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // 00 - 07
56
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // 08 - 0F
57
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // 10 - 17
58
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // 18 - 1F
59
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // 20 - 27
60
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // 28 - 2F
61
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // 30 - 37
62
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // 38 - 3F
63
+ OTH, ASC, ASC, ASC, ASC, ASC, ASC, ASC, // 40 - 47
64
+ ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, // 48 - 4F
65
+ ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, // 50 - 57
66
+ ASC, ASC, ASC, OTH, OTH, OTH, OTH, OTH, // 58 - 5F
67
+ OTH, ASS, ASS, ASS, ASS, ASS, ASS, ASS, // 60 - 67
68
+ ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, // 68 - 6F
69
+ ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, // 70 - 77
70
+ ASS, ASS, ASS, OTH, OTH, OTH, OTH, OTH, // 78 - 7F
71
+ OTH, UDF, OTH, ASO, OTH, OTH, OTH, OTH, // 80 - 87
72
+ OTH, OTH, ACO, OTH, ACO, UDF, ACO, UDF, // 88 - 8F
73
+ UDF, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // 90 - 97
74
+ OTH, OTH, ASO, OTH, ASO, UDF, ASO, ACO, // 98 - 9F
75
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // A0 - A7
76
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // A8 - AF
77
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // B0 - B7
78
+ OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, // B8 - BF
79
+ ACV, ACV, ACV, ACV, ACV, ACV, ACO, ACO, // C0 - C7
80
+ ACV, ACV, ACV, ACV, ACV, ACV, ACV, ACV, // C8 - CF
81
+ ACO, ACO, ACV, ACV, ACV, ACV, ACV, OTH, // D0 - D7
82
+ ACV, ACV, ACV, ACV, ACV, ACO, ACO, ACO, // D8 - DF
83
+ ASV, ASV, ASV, ASV, ASV, ASV, ASO, ASO, // E0 - E7
84
+ ASV, ASV, ASV, ASV, ASV, ASV, ASV, ASV, // E8 - EF
85
+ ASO, ASO, ASV, ASV, ASV, ASV, ASV, OTH, // F0 - F7
86
+ ASV, ASV, ASV, ASV, ASV, ASO, ASO, ASO, // F8 - FF
87
+ };
88
+
89
+
90
+ /* 0 : illegal
91
+ 1 : very unlikely
92
+ 2 : normal
93
+ 3 : very likely
94
+ */
95
+ static const unsigned char Latin1ClassModel[] =
96
+ {
97
+ /* UDF OTH ASC ASS ACV ACO ASV ASO */
98
+ /*UDF*/ 0, 0, 0, 0, 0, 0, 0, 0,
99
+ /*OTH*/ 0, 3, 3, 3, 3, 3, 3, 3,
100
+ /*ASC*/ 0, 3, 3, 3, 3, 3, 3, 3,
101
+ /*ASS*/ 0, 3, 3, 3, 1, 1, 3, 3,
102
+ /*ACV*/ 0, 3, 3, 3, 1, 2, 1, 2,
103
+ /*ACO*/ 0, 3, 3, 3, 3, 3, 3, 3,
104
+ /*ASV*/ 0, 3, 1, 3, 1, 1, 1, 3,
105
+ /*ASO*/ 0, 3, 1, 3, 1, 1, 3, 3,
106
+ };
107
+
108
+ void nsLatin1Prober::Reset(void)
109
+ {
110
+ mState = eDetecting;
111
+ mLastCharClass = OTH;
112
+ for (int i = 0; i < FREQ_CAT_NUM; i++)
113
+ mFreqCounter[i] = 0;
114
+ }
115
+
116
+
117
+ nsProbingState nsLatin1Prober::HandleData(const char* aBuf, PRUint32 aLen)
118
+ {
119
+ char *newBuf1 = 0;
120
+ PRUint32 newLen1 = 0;
121
+
122
+ if (!FilterWithEnglishLetters(aBuf, aLen, &newBuf1, newLen1)) {
123
+ newBuf1 = (char*)aBuf;
124
+ newLen1 = aLen;
125
+ }
126
+
127
+ unsigned char charClass;
128
+ unsigned char freq;
129
+ for (PRUint32 i = 0; i < newLen1; i++)
130
+ {
131
+ charClass = Latin1_CharToClass[(unsigned char)newBuf1[i]];
132
+ freq = Latin1ClassModel[mLastCharClass*CLASS_NUM + charClass];
133
+ if (freq == 0) {
134
+ mState = eNotMe;
135
+ break;
136
+ }
137
+ mFreqCounter[freq]++;
138
+ mLastCharClass = charClass;
139
+ }
140
+
141
+ if (newBuf1 != aBuf)
142
+ PR_FREEIF(newBuf1);
143
+
144
+ return mState;
145
+ }
146
+
147
+ float nsLatin1Prober::GetConfidence(void)
148
+ {
149
+ if (mState == eNotMe)
150
+ return 0.01f;
151
+
152
+ float confidence;
153
+ PRUint32 total = 0;
154
+ for (PRInt32 i = 0; i < FREQ_CAT_NUM; i++)
155
+ total += mFreqCounter[i];
156
+
157
+ if(!total)
158
+ confidence = 0.0f;
159
+ else
160
+ {
161
+ confidence = mFreqCounter[3]*1.0f / total;
162
+ confidence -= mFreqCounter[1]*20.0f/total;
163
+ }
164
+
165
+ if (confidence < 0.0f)
166
+ confidence = 0.0f;
167
+
168
+ // lower the confidence of latin1 so that other more accurate detector
169
+ // can take priority.
170
+ confidence *= 0.50f;
171
+
172
+ return confidence;
173
+ }
174
+
175
+ #ifdef DEBUG_chardet
176
+ void nsLatin1Prober::DumpStatus()
177
+ {
178
+ printf(" Latin1Prober: %1.3f [%s]\r\n", GetConfidence(), GetCharSetName());
179
+ }
180
+ #endif
181
+
182
+