diff --git a/.gitignore b/.gitignore index 2f35768..cae7181 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ testing.js ignore test/data/collation -test/data/conversion \ No newline at end of file +test/data/conversion +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 1588c09..22116b5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,34 @@ -chardet -======= -chardet \ No newline at end of file +chardet - nodejs characted detection module, written in pure Javascript +====== + +# Installation + + npm install chardet + +# Usage + + var chardet = require('chardet'); + chardet.detect(new Buffer('hello there!')); + // or + chardet.detectFile('/path/to/file', function(err, encoding) {}); + // or + chardet.detectFileSync('/path/to/file'); + +# Supported Encodings: + +* UTF-8 +* UTF-16 LE +* UTF-16 BE +* UTF-32 LE +* UTF-32 BE +* ISO-2022-JP +* ISO-2022-KR +* ISO-2022-CN +* Shift-JIS +* Big5 +* EUC-JP +* EUC-KR +* GB18030 + +Currently only these encodings are supported, more will be added soon. \ No newline at end of file diff --git a/encoding/mbcs.js b/encoding/mbcs.js index 7742aa2..019c388 100644 --- a/encoding/mbcs.js +++ b/encoding/mbcs.js @@ -194,7 +194,7 @@ mbcs.prototype.nextChar = function(iter, det) {}; */ module.exports.sjis = function() { this.name = function() { - return "Shift_JIS"; + return "Shift-JIS"; }; this.language = function() { return "ja"; @@ -298,71 +298,65 @@ util.inherits(module.exports.big5, mbcs); /** - * EUC charset recognizers. One abstract class that provides the common function - * for getting the next character according to the EUC encoding scheme, - * and nested derived classes for EUC_KR, EUC_JP, EUC_CN. + * EUC charset recognizers. One abstract class that provides the common function + * for getting the next character according to the EUC encoding scheme, + * and nested derived classes for EUC_KR, EUC_JP, EUC_CN. * + * Get the next character value for EUC based encodings. + * Character "value" is simply the raw bytes that make up the character + * packed into an int. */ -module.exports.euc = function() { - - /* - * Get the next character value for EUC based encodings. - * Character "value" is simply the raw bytes that make up the character - * packed into an int. - */ - this.nextChar = function(iter, det) { - it.index = it.nextIndex; - iter.error = false; - var firstByte = 0; - var secondByte = 0; - var thirdByte = 0; - //int fourthByte = 0; - buildChar: { - firstByte = iter.charValue = iter.nextByte(det); - if (firstByte < 0) { - // Ran off the end of the input data - iter.done = true; - break buildChar; +function eucNextChar(iter, det) { + it.index = it.nextIndex; + iter.error = false; + var firstByte = 0; + var secondByte = 0; + var thirdByte = 0; + //int fourthByte = 0; + buildChar: { + firstByte = iter.charValue = iter.nextByte(det); + if (firstByte < 0) { + // Ran off the end of the input data + iter.done = true; + break buildChar; + } + if (firstByte <= 0x8d) { + // single byte char + break buildChar; + } + secondByte = iter.nextByte(det); + iter.charValue = (iter.charValue << 8) | secondByte; + if (firstByte >= 0xA1 && firstByte <= 0xfe) { + // Two byte Char + if (secondByte < 0xa1) { + iter.error = true; } - if (firstByte <= 0x8d) { - // single byte char - break buildChar; + break buildChar; + } + if (firstByte == 0x8e) { + // Code Set 2. + // In EUC-JP, total char size is 2 bytes, only one byte of actual char value. + // In EUC-TW, total char size is 4 bytes, three bytes contribute to char value. + // We don't know which we've got. + // Treat it like EUC-JP. If the data really was EUC-TW, the following two + // bytes will look like a well formed 2 byte char. + if (secondByte < 0xa1) { + iter.error = true; } - secondByte = iter.nextByte(det); - iter.charValue = (iter.charValue << 8) | secondByte; - if (firstByte >= 0xA1 && firstByte <= 0xfe) { - // Two byte Char - if (secondByte < 0xa1) { - iter.error = true; - } - break buildChar; - } - if (firstByte == 0x8e) { - // Code Set 2. - // In EUC-JP, total char size is 2 bytes, only one byte of actual char value. - // In EUC-TW, total char size is 4 bytes, three bytes contribute to char value. - // We don't know which we've got. - // Treat it like EUC-JP. If the data really was EUC-TW, the following two - // bytes will look like a well formed 2 byte char. - if (secondByte < 0xa1) { - iter.error = true; - } - break buildChar; - } - if (firstByte == 0x8f) { - // Code set 3. - // Three byte total char size, two bytes of actual char value. - thirdByte = iter.nextByte(det); - iter.charValue = (iter.charValue << 8) | thirdByte; - if (thirdByte < 0xa1) { - iter.error = true; - } + break buildChar; + } + if (firstByte == 0x8f) { + // Code set 3. + // Three byte total char size, two bytes of actual char value. + thirdByte = iter.nextByte(det); + iter.charValue = (iter.charValue << 8) | thirdByte; + if (thirdByte < 0xa1) { + iter.error = true; } } - return (iter.done == false); - }; + } + return (iter.done == false); }; -util.inherits(module.exports.euc, mbcs); @@ -393,8 +387,10 @@ module.exports.euc_jp = function() { 0xa5e5, 0xa5e9, 0xa5ea, 0xa5eb, 0xa5ec, 0xa5ed, 0xa5f3, 0xb8a9, 0xb9d4, 0xbaee, 0xbbc8, 0xbef0, 0xbfb7, 0xc4ea, 0xc6fc, 0xc7bd, 0xcab8, 0xcaf3, 0xcbdc, 0xcdd1 ]; + + this.nextChar = eucNextChar; }; -util.inherits(module.exports.euc_jp, module.exports.euc); +util.inherits(module.exports.euc_jp, mbcs); @@ -425,8 +421,10 @@ module.exports.euc_kr = function() { 0xc0da, 0xc0e5, 0xc0fb, 0xc0fc, 0xc1a4, 0xc1a6, 0xc1b6, 0xc1d6, 0xc1df, 0xc1f6, 0xc1f8, 0xc4a1, 0xc5cd, 0xc6ae, 0xc7cf, 0xc7d1, 0xc7d2, 0xc7d8, 0xc7e5, 0xc8ad ]; + + this.nextChar = eucNextChar; }; -util.inherits(module.exports.euc_kr, module.exports.euc); +util.inherits(module.exports.euc_kr, mbcs); diff --git a/index.js b/index.js index 563edf5..a343dc8 100644 --- a/index.js +++ b/index.js @@ -43,8 +43,7 @@ module.exports.detect = function(buffer) { return a.confidence - b.confidence; }); - console.log(matches); - + // console.log(matches); return matches.length ? matches.pop().name : null; }; diff --git a/package.json b/package.json new file mode 100644 index 0000000..bd691ee --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "chardet", + "version": "0.0.3", + "homepage": "https://github.com/runk/node-chardet", + "description": "Character detector", + "keywords": ["encoding", "character", "utf8", "detector"], + "author": "Shirokov Dmitry ", + "dependencies": { + + }, + "repository": { + "type":"git", + "url":"git@github.com:runk/node-chardet.git" + }, + "bugs": { + "mail":"deadrunk@gmail.com", + "url":"http://github.com/runk/node-chardet/issues" + }, + "scripts": { + "test": "mocha -R spec --recursive" + }, + "main": "index.js", + "engine": { + "node": ">=0.8.0", "npm": "1" + }, + "licences": [{ + "type":"LGPL2.1", + "url": "http://www.gnu.org/licenses/lgpl-2.1.txt" + }] +} diff --git a/test.js b/test.js deleted file mode 100644 index e69de29..0000000 diff --git a/test/chardet.js b/test/chardet.js new file mode 100644 index 0000000..2e1bb16 --- /dev/null +++ b/test/chardet.js @@ -0,0 +1,30 @@ +var assert = require('assert'), + chardet = require('../'), + fs = require('fs'); + +describe('chardet', function() { + + var path = __dirname + '/data/encodings/utf8'; + + describe('#detect', function() { + it('should detect encoding', function() { + assert.equal(chardet.detect(fs.readFileSync(path)), 'UTF-8'); + }); + }); + + describe('#detectFile', function() { + it('should detect encoding', function(done) { + chardet.detectFile(path, function(err, res) { + assert.equal(err, null); + assert.equal(res, 'UTF-8'); + done(); + }); + }); + }); + + describe('#detectFileSync', function() { + it('should detect encoding', function() { + assert.equal(chardet.detectFileSync(path), 'UTF-8'); + }); + }); +}); \ No newline at end of file diff --git a/test/data/encodings/big5 b/test/data/encodings/big5 index d0ea2fb..d6089ae 100644 --- a/test/data/encodings/big5 +++ b/test/data/encodings/big5 @@ -1,2 +1,2 @@ - -饼獺 \ No newline at end of file +現┎戈癟м羆菏快そ㎝キ单诀穦〆穦快礚毁锚呼古砛璸购辨硓筁裹蹦ノ礚毁锚呼砞璸呼崩笆穨㎝诀篶ㄤ呼蹦ノ礚毁锚呼砞璸琵穦顶糷珹摧痚よ獽莉呼戈癟㎝ㄏノ呼狝叭礚毁锚呼古砛璸购箋贱ㄥ搂盢20134る15ら羭︽Ω羭快瓣悔IT蹲弘眒笆ぇΤ闽冈薄叫聅凝硂柑 +現┎璓崩笆ネ約獂莱ノ戈癟м現┎戈癟м羆菏快そ秨甶兜翠┦古砛璸购醇眶古砛璸购喘ら盽ネい縩伐ㄏノ戈癟の硄癟м躬纘膥尿ㄏノ戈癟の硄癟м古砛璸购砞Τ蝗簧贱疭﹚戳丁ЧΘ﹚璶―莉箋秘古砛靡の贱礟Τ闽冈薄叫聅凝硂柑 \ No newline at end of file diff --git a/test/data/encodings/euc_jp b/test/data/encodings/euc_jp index a883a13..b433417 100644 --- a/test/data/encodings/euc_jp +++ b/test/data/encodings/euc_jp @@ -1,13 +1,10 @@ -コンピュ〖タ〖は、塑剂弄には眶机しか胺うことができません。コンピュ〖タ〖は、矢机や淡规などのそれぞれに戎规を充り慷ることによって胺えるようにします。ユニコ〖ドが叫丸るまでは、これらの戎规を充り慷る慌寥みが部纱硷梧も赂哼しました。どの办つをとっても、浇尸な矢机を崔んではいませんでした。毋えば、菠剑息圭办つを斧ても、そのすべての咐胳をカバ〖するためには、いくつかの佰なる射规步の慌寥みが涩妥でした。毖胳のような办つの咐胳に嘎っても、办つだけの射规步の慌寥みでは、办忍弄に蝗われるすべての矢机、剁粕爬、祷窖弄な淡规などを胺うには稍浇尸でした。 +毖胳は戮の驴くのヨ〖ロッパ咐胳が积っている叹混の呈恃步や瓢混の客疚恃步のほとんどを己ったため、矢面の呈簇犯∈茂が茂に部をどうするか∷を胳界に巴赂しており、したがって胳界が盖年弄であり≈矢房∽がはっきりしている。 +泣塑の毖胳兜伴ではCˇTˇオニオンズの捏晶した5矢房という雇え数が毖胳の答塑矢房として弓く蝗われている∈悸狠には、5つの矢房ではうまく棱汤できない矢も赂哼するとし、5矢房を动拇しすぎることが笛って池浆の烁げになる、という肩磨も牧しくない∷。 +5矢房は、毖矢の面看をなす肩胳揭胳婶尸において、涟弥混痰しに胳を事べただけで矢ができあがっている湿を尸梧したものと咐える。そこで蝗われている胳は肩胳としての叹混、赂哼を咐う揭胳としてのbe瓢混、侯脱を咐う揭胳としての办忍瓢混、肩胳の拉剂や觉轮を咐う妨推混、办忍瓢混の誊弄胳になる叹混、その誊弄胳に滦する柒推弄な揭胳になる瓢混の付妨や叹混や妨推混である。このように5矢房は肩胳と瓢混と、涟弥混痰しで事ぶ叹混とその叹混に滦して柒推弄な揭胳として事ぶ帽姐な妨という嘎られた婶尸において、事んだ胳の硷梧によって尸梧し5つの妨にまとめた湿と咐える。ここには矢の络答塑である肩胳と揭胳に崔まれている罢蹋への雇弧がなされていない。そのため罢蹋に答づいて咐驼を蝗脱しようとしている池浆荚にはかえって烁げとなっているのである。 +これまでは布淡の矢房が肩妥かつ脚妥なものであるとして胺われてきた。毖矢の菇陇の尸梧恕としての5矢房は泣塑笆嘲の柜ではあまり办忍弄ではないが、瓢混の胳恕を棱汤する惧では、≈答塑5矢房∽をベ〖スとした瓢混房の尸梧が坤肠弄に减け掐れられていて、ジ〖ニアス毖下辑诺、Oxford Advanced Leaner's Dictionary 霹の驴くの涪耙ある辑今において姥端弄に何脱されている。 +奶撅、渴乖妨の矢は妈2矢房とは斧なさず、瓢混婶尸を话帽附など肩胳に圭わせた妨にして矢房を雇える。また窗位妨も票屯である。また减瓢轮の矢も5矢房に碰てはまらない。凡瓢混を崔む矢は凡瓢混链挛を1つの瓢混と雇えることが驴い。また、凡瓢混は锦瓢混と塑瓢混が突圭したものであるので、泼侍な妨の锦瓢混として胺えばよい。 そもそも5矢房は锦瓢混を近殿した肩胳と揭胳の婶尸において胳の事びだけによって尸梧した湿なのである。 +ランドルフˇクァ〖クは烧裁胳A (Adverbial) を裁えた雇え数を捏晶している。烧裁胳Aは饯峻胳Mとは佰なり臼维することができない。この雇えでは骄丸の5矢房にSVAとSVOAという矢房が裁わる。また妈2矢房のうちVがbe瓢混の眷圭を泼侍に胺う雇えもある∈つまりS be C∷。また AˇSˇホ〖ンビ〖は妈3矢房、妈4矢房、妈5矢房のOやCが稍年混や尸混や瓢叹混やthat泪の眷圭などで嘿かく尸梧した矢房を捏晶している。 -これらの射规步の慌寥みは、陵高に谭解するものでもありました。企つの佰なる射规步の慌寥みが、企つの佰なる矢机に票办の戎规を烧けることもできるし、票じ矢机に佰なる戎规を烧けることもできるのです。どのようなコンピュ〖タ〖も∈泼にサ〖バ〖は∷驴くの佰なった射规步の慌寥みをサポ〖トする涩妥があります。たとえデ〖タが佰なる射规步の慌寥みやプラットフォ〖ムを奶册しても、いつどこでデ〖タが宛れるか尸からない错副を肆すことのなるのです。 -ユニコ〖ドはすべてを恃えます +ゲルマン废の帽胳のほかに、ラテン废の帽胳も寒掐しているが、これは、ノルマンˇコンクエスト笆惯、フランスから丸た诞虏超甸がロマンス紧胳のオイル胳废のノルマン胳を厦していたことの逼读である∈箕袋弄には 11坤氮笆惯で、面毖胳∷。毖胳の叹混に拉や呈がほぼ久糖して、胳萨恃步もほかのヨ〖ロッパ胳と孺べてとても警ないのはこのノルマンˇコンクエストによってである。それ笆涟は剩花であったイギリスの咐胳が、イギリスの诞虏超甸や阑喀荚や兜徽がノルマン客になり毖胳を厦さなくなった冯蔡、筋瘫の粗で词帽に厦せるように词燎步されていった。それとともに诞虏超甸やジェントリ〖がフランス胳にも夺いノルマン胳を厦し、阑喀荚がラテン胳を厦すようになりその冯蔡として驴くのラテン胳やフランス胳も稼脱されることになった。 -ユニコ〖ドは、プラットフォ〖ムに犯わらず、プログラムに犯わらず、咐胳に犯わらず、すべての矢机に迫惟した戎规を涂えます。ユニコ〖ド筛洁は、アップル、ヒュ〖レットパッカ〖ド、IBM、ジャストシステム、マイクロソフト、オラクル、SAP、サン、サイベ〖スなどの缓度肠の肩瞥弄措度と戮の驴くの措度に何脱されています。ユニコ〖ドは、XML、Java、ECMAScript(JavaScript)、LDAP、CORBA 3.0などの呵黎眉の筛洁の涟捏となっており、ユニコ〖ドを悸刘すれば、ISO/IEC 10646に努圭することになります。ユニコ〖ドは、驴くのオペレ〖ティングシステムとすべての呵糠のブラウザ〖と戮の驴くの澜墒でサポ〖トされています。ユニコ〖ド筛洁の叫附とユニコ〖ドをサポ〖トするツ〖ル梧は、候海覆螟になっているソフトウエア祷窖のグロ〖バル步の萎れに滦して、泼に舔に惟っています。 - -ユニコ〖ドをクライアントサ〖バ〖房のアプリケ〖ションや、驴霖菇陇を积つアプリケ〖ション、ウェブサイトなどにに寥み哈むことで、骄丸の矢机コ〖ドセットを脱いるよりも汤らかなコスト猴负が材墙です。ユニコ〖ドは、帽办のソフトウエア澜墒、帽办のウェブサイトに、部ら缄を裁えることなく、剩眶のプラットフォ〖ム、剩眶の咐胳、剩眶の柜をカバ〖することが叫丸るのです。ユニコ〖ドは、デ〖タが驴くの佰なるシステムの粗を、部の宛れもなしに啪流することを材墙とするのです。 -ユニコ〖ドコンソ〖シアムについて - -ユニコ〖ドコンソ〖シアムは、呵糠のソフトウエア澜墒と筛洁においてテキストを山附することを罢蹋する∪ユニコ〖ド筛洁∩の菇蜜、券鸥、舍第、网脱楼渴を誊弄として肋惟された润蹦网寥骏です。票コンソ〖シアムの柴镑は、コンピュ〖タ〖と攫鼠借妄に犯わる弓绕な措度や寥骏から菇喇されています。票コンソ〖シアムは、衡蜡弄には、姐胯に柴锐のみによって笨蹦されています。ユニコ〖ド筛洁を毁积し、その橙磨と悸刘を毁辩する坤肠面の寥骏や改客は、だれもがユニコ〖ドコンソ〖シアムの柴镑なることができます。 - -より拒しいことをお梦りになりたい数は、Glossary, Unicode-Enabled Products, Technical Introduction および Useful Resourcesをご徊救ください。 +カナダは傅毖挝竣瘫孟であった孟拌だが、その毖挝竣瘫孟にそれ笆涟はヌ〖ベルフランスであり、海でもフランス胳が蝗われ鲁けているケベック剑があることから、カナダ链挛の给脱胳として毖胳とフランス胳の尉数が扩年されており、息水蜡绍のサイトや措度の睛墒棱汤などは链て毖施尉咐胳で乖われている。奠毖挝の柜としては、链客庚の柒、毖胳を熟胳とする客の充圭は58%と你く、フランス胳が22%を狸める。これは、败瘫が润撅に驴いため妈企咐胳として毖胳を蝗脱している客庚が润撅に驴いからである。また、アメリカ圭桨柜が钨に疤弥していることから、奠毖挝であるとはいえ、オ〖ストラリアやインドなどほかの奠毖挝竣瘫孟とは般い、孺べるとカナダの毖胳はイギリス毖胳よりもアメリカ毖胳に夺いが、帽胳の闹りとしてはイギリス毖胳及を何脱することが驴い。ケベック剑ではフランス胳が给脱胳であることから、毖胳を熟胳とせず毖胳笨脱墙蜗が光くない客も警なくないが、ケベック剑とニュ〖ブランズウィック剑、オンタリオ剑笆嘲ではほとんどフランス胳が蝗われないこともあり、カナダ毖胳におけるフランス胳の逼读は厂痰に夺い。 \ No newline at end of file diff --git a/test/data/encodings/gb18030 b/test/data/encodings/gb18030 new file mode 100644 index 0000000..26534d6 --- /dev/null +++ b/test/data/encodings/gb18030 @@ -0,0 +1,13 @@ +基本上,计算机只是处理数字。它们指定一个数字,来储存字母或其他字符。在创造Unicode之前,有数百种指定这些数字的编码系统。没有一个编码可以包含足够的字符:例如,单单欧州共同体就需要好几种不同的编码来包括所有的语言。即使是单一种语言,例如英语,也没有哪一个编码可以适用于所有的字母,标点符号,和常用的技术符号。 + +这些编码系统也会互相冲突。也就是说,两种编码可能使用相同的数字代表两个不同的字符,或使用不同的数字代表相同的字符。任何一台特定的计算机(特别是服务器)都需要支持许多不同的编码,但是,不论什么时候数据通过不同的编码或平台之间,那些数据总会有损坏的危险。 +Unicode正在改变所有这一切! + +Unicode给每个字符提供了一个唯一的数字,不论是什么平台,不论是什么程序,不论什么语言。Unicode标准已经被这些工业界的领导们所采用,例如:Apple, HP, IBM, JustSystem, Microsoft, Oracle, SAP, Sun, Sybase, Unisys和其它许多公司。最新的标准都需要Unicode,例如XML, Java, ECMAScript (JavaScript), LDAP, CORBA 3.0, WML等等,并且,Unicode是实现ISO/IEC 10646的正规方式。许多操作系统,所有最新的浏览器和许多其他产品都支持它。Unicode标准的出现和支持它工具的存在,是近来全球软件技术最重要的发展趋势。 + +将Unicode与客户服务器或多层应用程序和网站结合,比使用传统字符集节省费用。Unicode使单一软件产品或单一网站能够贯穿多个平台,语言和国家,而不需要重建。它可将数据传输到许多不同的系统,而无损坏。 +关于Unicode学术学会 + +Unicode学术学会是一个非盈利的组织,是为发展,扩展和推广使用Unicode标准而建立的,Unicode学术学会设立了现代软件产品和标准文本的表示法。学术学会的会员代表了广泛领域的计算机和资讯工业的公司和组织。学术学会只由会员提供资金。Unicode学术学会的会员资格开放给世界上任何支持Unicode标准和希望协助其扩展和执行的组织及个人。 + +欲知更多信息,请参阅术语词汇表,Unicode产品样本,技术简介和参考资料。 diff --git a/test/data/encodings/lang_chinese b/test/data/encodings/lang_chinese index 7e9c310..a295e5a 100644 --- a/test/data/encodings/lang_chinese +++ b/test/data/encodings/lang_chinese @@ -1,13 +1,2 @@ -鍩烘湰涓婏紝璁$畻鏈哄彧鏄鐞嗘暟瀛椼傚畠浠寚瀹氫竴涓暟瀛楋紝鏉ュ偍瀛樺瓧姣嶆垨鍏朵粬瀛楃銆傚湪鍒涢燯nicode涔嬪墠锛屾湁鏁扮櫨绉嶆寚瀹氳繖浜涙暟瀛楃殑缂栫爜绯荤粺銆傛病鏈変竴涓紪鐮佸彲浠ュ寘鍚冻澶熺殑瀛楃锛氫緥濡傦紝鍗曞崟娆у窞鍏卞悓浣撳氨闇瑕佸ソ鍑犵涓嶅悓鐨勭紪鐮佹潵鍖呮嫭鎵鏈夌殑璇█銆傚嵆浣挎槸鍗曚竴绉嶈瑷锛屼緥濡傝嫳璇紝涔熸病鏈夊摢涓涓紪鐮佸彲浠ラ傜敤浜庢墍鏈夌殑瀛楁瘝锛屾爣鐐圭鍙凤紝鍜屽父鐢ㄧ殑鎶鏈鍙枫 - -杩欎簺缂栫爜绯荤粺涔熶細浜掔浉鍐茬獊銆備篃灏辨槸璇达紝涓ょ缂栫爜鍙兘浣跨敤鐩稿悓鐨勬暟瀛椾唬琛ㄤ袱涓笉鍚岀殑瀛楃锛屾垨浣跨敤涓嶅悓鐨勬暟瀛椾唬琛ㄧ浉鍚岀殑瀛楃銆備换浣曚竴鍙扮壒瀹氱殑璁$畻鏈(鐗瑰埆鏄湇鍔″櫒)閮介渶瑕佹敮鎸佽澶氫笉鍚岀殑缂栫爜锛屼絾鏄紝涓嶈浠涔堟椂鍊欐暟鎹氳繃涓嶅悓鐨勭紪鐮佹垨骞冲彴涔嬮棿锛岄偅浜涙暟鎹讳細鏈夋崯鍧忕殑鍗遍櫓銆 -Unicode姝e湪鏀瑰彉鎵鏈夎繖涓鍒囷紒 - -Unicode缁欐瘡涓瓧绗︽彁渚涗簡涓涓敮涓鐨勬暟瀛楋紝涓嶈鏄粈涔堝钩鍙帮紝涓嶈鏄粈涔堢▼搴忥紝涓嶈浠涔堣瑷銆俇nicode鏍囧噯宸茬粡琚繖浜涘伐涓氱晫鐨勯瀵间滑鎵閲囩敤锛屼緥濡傦細Apple, HP, IBM, JustSystem, Microsoft, Oracle, SAP, Sun, Sybase, Unisys鍜屽叾瀹冭澶氬叕鍙搞傛渶鏂扮殑鏍囧噯閮介渶瑕乁nicode锛屼緥濡俋ML, Java, ECMAScript (JavaScript), LDAP, CORBA 3.0, WML绛夌瓑锛屽苟涓旓紝Unicode鏄疄鐜癐SO/IEC 10646鐨勬瑙勬柟寮忋傝澶氭搷浣滅郴缁燂紝鎵鏈夋渶鏂扮殑娴忚鍣ㄥ拰璁稿鍏朵粬浜у搧閮芥敮鎸佸畠銆俇nicode鏍囧噯鐨勫嚭鐜板拰鏀寔瀹冨伐鍏风殑瀛樺湪锛屾槸杩戞潵鍏ㄧ悆杞欢鎶鏈渶閲嶈鐨勫彂灞曡秼鍔裤 - -灏哢nicode涓庡鎴锋湇鍔″櫒鎴栧灞傚簲鐢ㄧ▼搴忓拰缃戠珯缁撳悎锛屾瘮浣跨敤浼犵粺瀛楃闆嗚妭鐪佽垂鐢ㄣ俇nicode浣垮崟涓杞欢浜у搧鎴栧崟涓缃戠珯鑳藉璐┛澶氫釜骞冲彴锛岃瑷鍜屽浗瀹讹紝鑰屼笉闇瑕侀噸寤恒傚畠鍙皢鏁版嵁浼犺緭鍒拌澶氫笉鍚岀殑绯荤粺锛岃屾棤鎹熷潖銆 -鍏充簬Unicode瀛︽湳瀛︿細 - -Unicode瀛︽湳瀛︿細鏄竴涓潪鐩堝埄鐨勭粍缁囷紝鏄负鍙戝睍锛屾墿灞曞拰鎺ㄥ箍浣跨敤Unicode鏍囧噯鑰屽缓绔嬬殑锛孶nicode瀛︽湳瀛︿細璁剧珛浜嗙幇浠h蒋浠朵骇鍝佸拰鏍囧噯鏂囨湰鐨勮〃绀烘硶銆傚鏈浼氱殑浼氬憳浠h〃浜嗗箍娉涢鍩熺殑璁$畻鏈哄拰璧勮宸ヤ笟鐨勫叕鍙稿拰缁勭粐銆傚鏈浼氬彧鐢变細鍛樻彁渚涜祫閲戙俇nicode瀛︽湳瀛︿細鐨勪細鍛樿祫鏍煎紑鏀剧粰涓栫晫涓婁换浣曟敮鎸乁nicode鏍囧噯鍜屽笇鏈涘崗鍔╁叾鎵╁睍鍜屾墽琛岀殑缁勭粐鍙婁釜浜恒 - -娆茬煡鏇村淇℃伅锛岃鍙傞槄鏈璇嶆眹琛紝Unicode浜у搧鏍锋湰锛屾妧鏈畝浠嬪拰鍙傝冭祫鏂欍 +鏀垮簻璩囪▕绉戞妧绺界洠杈﹀叕瀹ゅ拰骞崇瓑姗熸渻濮斿摗鏈冨悎杈︾劇闅滅缍查爜鍢夎ū瑷堝妰锛屽笇鏈涢忛亷琛ㄥ桨鎺$敤鐒¢殰绀欑恫闋佽ō瑷堢殑缍茬珯锛屾帹鍕曟洿澶氫紒妤拰姗熸鍦ㄥ叾缍茬珯鎺$敤鐒¢殰绀欑恫闋佽ō瑷堬紝璁撶ぞ鏈冨悇闅庡堡鍖呮嫭娈樼柧浜哄+鏇存柟渚垮湴鐛插彇缍蹭笂璩囪▕鍜屼娇鐢ㄧ恫涓婃湇鍕欍傜劇闅滅缍查爜鍢夎ū瑷堝妰闋掔崕鍏哥Ξ灏囨柤2013骞4鏈15鏃ヨ垑琛岋紝鐐洪娆¤垑杈︾殑銆屽湅闅汭T鍖嶇殑绮惧僵娲诲嫊涔嬩竴銆傛湁闂滆┏鎯咃紝璜嬬忚閫欒!銆 +鏀垮簻涓鍚戣嚧鍔涙帹鍕曢暦鑰呭湪鐢熸椿涓婃洿寤f硾鎳夌敤璩囪▕绉戞妧銆傛斂搴滆硣瑷婄鎶绺界洠杈﹀叕瀹ゅ凡闁嬪睍涓闋呭叏娓у槈瑷辫▓鍔冦屾櫤閱掗暦鑰呭槈瑷辫▓鍔冦嶏紝琛ㄦ彋鍦ㄦ棩甯哥敓娲讳腑绌嶆サ浣跨敤璩囪▕鍙婇氳▕绉戞妧鐨勯暦鑰咃紝浠ラ紦鍕典粬鍊戠辜绾屼娇鐢ㄨ硣瑷婂強閫氳▕绉戞妧銆傚槈瑷辫▓鍔冭ō鏈夐噾銆侀妧銆侀妳鐛庯紝闀疯呮柤鐗瑰畾鏈熼枔瀹屾垚鎸囧畾瑕佹眰锛屽彲鐛查爳璐堝槈瑷辫瓑鏇稿強鐛庣墝銆傛湁闂滆┏鎯咃紝璜嬬忚閫欒!銆 \ No newline at end of file diff --git a/test/data/encodings/lang_japanese b/test/data/encodings/lang_japanese index 5b3462a..5c2cb26 100644 --- a/test/data/encodings/lang_japanese +++ b/test/data/encodings/lang_japanese @@ -9,5 +9,3 @@ 銉︺儖銈炽兗銉夈偝銉炽偨銉笺偡銈€儬銇仱銇勩仸 銉︺儖銈炽兗銉夈偝銉炽偨銉笺偡銈€儬銇佹渶鏂般伄銈姐儠銉堛偊銈ㄣ偄瑁藉搧銇ㄦ婧栥伀銇娿亜銇︺儐銈偣銉堛倰琛ㄧ従銇欍倠銇撱仺銈掓剰鍛炽仚銈嬧溿儲銉嬨偝銉笺儔妯欐簴鈥濄伄妲嬬瘔銆佺櫤灞曘佹櫘鍙娿佸埄鐢ㄤ績閫层倰鐩殑銇ㄣ仐銇﹁ō绔嬨仌銈屻仧闈炲柖鍒╃祫绻斻仹銇欍傚悓銈炽兂銈姐兗銈枫偄銉犮伄浼氬摗銇併偝銉炽償銉ャ兗銈裤兗銇ㄦ儏鍫卞嚘鐞嗐伀淇傘倧銈嬪簝姹庛仾浼佹キ銈勭祫绻斻亱銈夋鎴愩仌銈屻仸銇勩伨銇欍傚悓銈炽兂銈姐兗銈枫偄銉犮伅銆佽病鏀跨殑銇伅銆佺磾绮嬨伀浼氳不銇伩銇倛銇c仸閬嬪柖銇曘倢銇︺亜銇俱仚銆傘儲銉嬨偝銉笺儔妯欐簴銈掓敮鎸併仐銆併仢銇嫛寮点仺瀹熻銈掓敮鎻淬仚銈嬩笘鐣屼腑銇祫绻斻倓鍊嬩汉銇併仩銈屻倐銇屻儲銉嬨偝銉笺儔銈炽兂銈姐兗銈枫偄銉犮伄浼氬摗銇倠銇撱仺銇屻仹銇嶃伨銇欍 - -銈堛倞瑭炽仐銇勩亾銇ㄣ倰銇婄煡銈娿伀銇倞銇熴亜鏂广伅銆丟lossary, Unicode-Enabled Products, Technical Introduction 銇娿倛銇 Useful Resources銈掋仈鍙傜収銇忋仩銇曘亜銆 diff --git a/test/iso2022.js b/test/encodings/iso2022.js similarity index 56% rename from test/iso2022.js rename to test/encodings/iso2022.js index a5aae8f..883f04a 100644 --- a/test/iso2022.js +++ b/test/encodings/iso2022.js @@ -1,25 +1,28 @@ var assert = require('assert'), - chardet = require('../'); + chardet = require('../../'); + +describe('ISO-2022', function() { + + var base = __dirname + '/../data/encodings'; -describe('iso2022', function() { it('should return ISO-2022-JP', function() { assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/iso2022jp'), + chardet.detectFileSync(base + '/iso2022jp'), 'ISO-2022-JP' ); }); it('should return ISO-2022-KR', function() { assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/iso2022kr'), + chardet.detectFileSync(base + '/iso2022kr'), 'ISO-2022-KR' ); }); it('should return ISO-2022-CN', function() { assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/iso2022cn'), + chardet.detectFileSync(base + '/iso2022cn'), 'ISO-2022-CN' ); }); diff --git a/test/encodings/mbcs.js b/test/encodings/mbcs.js new file mode 100644 index 0000000..3d60aaa --- /dev/null +++ b/test/encodings/mbcs.js @@ -0,0 +1,44 @@ + +var assert = require('assert'), + chardet = require('../../'); + +describe('Multybyte Character Sets', function() { + + var base = __dirname + '/../data/encodings'; + + it('should return SHIFT-JIS', function() { + assert.equal( + chardet.detectFileSync(base + '/shiftjis'), + 'Shift-JIS' + ); + }); + + it('should return GB18030', function() { + assert.equal( + chardet.detectFileSync(base + '/gb18030'), + 'GB18030' + ); + }); + + it('should return Big5', function() { + assert.equal( + chardet.detectFileSync(base + '/big5'), + 'Big5' + ); + }); + + it('should return EUC-JP', function() { + assert.equal( + chardet.detectFileSync(base + '/euc_jp'), + 'EUC-JP' + ); + }); + + it('should return EUC-KR', function() { + assert.equal( + chardet.detectFileSync(base + '/euc_kr'), + 'EUC-KR' + ); + }); + +}); \ No newline at end of file diff --git a/test/unicode.js b/test/encodings/unicode.js similarity index 56% rename from test/unicode.js rename to test/encodings/unicode.js index 3b3c213..4502e97 100644 --- a/test/unicode.js +++ b/test/encodings/unicode.js @@ -1,32 +1,35 @@ var assert = require('assert'), - chardet = require('../'); + chardet = require('../../'); + +describe('Unicode', function() { + + var base = __dirname + '/../data/encodings'; -describe('unicode', function() { it('should return UTF-16LE', function() { assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/utf16le'), + chardet.detectFileSync(base + '/utf16le'), 'UTF-16LE' ); }); it('should return UTF-16BE', function() { assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/utf16be'), + chardet.detectFileSync(base + '/utf16be'), 'UTF-16BE' ); }); it('should return UTF-32LE', function() { assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/utf32le'), + chardet.detectFileSync(base + '/utf32le'), 'UTF-32LE' ); }); it('should return UTF-32BE', function() { assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/utf32be'), + chardet.detectFileSync(base + '/utf32be'), 'UTF-32BE' ); }); diff --git a/test/encodings/utf8.js b/test/encodings/utf8.js new file mode 100644 index 0000000..14db5db --- /dev/null +++ b/test/encodings/utf8.js @@ -0,0 +1,12 @@ + +var assert = require('assert'), + chardet = require('../../'); + +describe('UTF-8', function() { + it('should return UTF-8', function() { + assert.equal( + chardet.detectFileSync(__dirname + '/../data/encodings/utf8'), + 'UTF-8' + ); + }); +}); \ No newline at end of file diff --git a/test/mbcs.js b/test/mbcs.js deleted file mode 100644 index 7cce66b..0000000 --- a/test/mbcs.js +++ /dev/null @@ -1,30 +0,0 @@ - -var assert = require('assert'), - chardet = require('../'); - -describe('Multy byte character sets', function() { - it('should return SHIFT_JIS', function() { - assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/shiftjis'), - 'Shift_JIS' - ); - }); - - it('should return BIG-5'); - - it('should return EUC-JP', function() { - assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/euc_jp'), - 'EUC-JP' - ); - }); - - it('should return EUC-KR', function() { - assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/euc_kr'), - 'EUC-KR' - ); - }); - - -}); \ No newline at end of file diff --git a/test/utf8.js b/test/utf8.js deleted file mode 100644 index ec36d2b..0000000 --- a/test/utf8.js +++ /dev/null @@ -1,12 +0,0 @@ - -var assert = require('assert'), - chardet = require('../'); - -describe('utf8', function() { - it('should return UTF-8', function() { - assert.equal( - chardet.detectFileSync(__dirname + '/data/encodings/utf8'), - 'UTF-8' - ); - }); -}); \ No newline at end of file