版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

README.md 19 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. # js-codepage
  2. [Codepages](https://en.wikipedia.org/wiki/Codepage) are character encodings. In
  3. many contexts, single- or double-byte character sets are used in lieu of Unicode
  4. encodings. The codepages map between characters and numbers.
  5. ## Setup
  6. In node:
  7. ```js
  8. var cptable = require('codepage');
  9. ```
  10. In the browser:
  11. ```html
  12. <script src="cptable.js"></script>
  13. <script src="cputils.js"></script>
  14. ```
  15. Alternatively, use the full version in the dist folder:
  16. ```html
  17. <script src="cptable.full.js"></script>
  18. ```
  19. The complete set of codepages is large due to some Double Byte Character Set
  20. encodings. A much smaller file that only includes SBCS codepages is provided in
  21. this repo (`sbcs.js`), as well as a file for other projects (`cpexcel.js`)
  22. If you know which codepages you need, you can include individual scripts for
  23. each codepage. The individual files are provided in the `bits/` directory.
  24. For example, to include only the Mac codepages:
  25. ```html
  26. <script src="bits/10000.js"></script>
  27. <script src="bits/10006.js"></script>
  28. <script src="bits/10007.js"></script>
  29. <script src="bits/10029.js"></script>
  30. <script src="bits/10079.js"></script>
  31. <script src="bits/10081.js"></script>
  32. ```
  33. All of the browser scripts define and append to the `cptable` object. To rename
  34. the object, edit the `JSVAR` shell variable in `make.sh` and run the script.
  35. The utilities functions are contained in `cputils.js`, which assumes that the
  36. appropriate codepage scripts were loaded.
  37. The script will manipulate `module.exports` if available . This is not always
  38. desirable. To prevent the behavior, define `DO_NOT_EXPORT_CODEPAGE`.
  39. ## Usage
  40. Most codepages are indexed by number. To get the Unicode character for a given
  41. codepoint, use the `dec` property:
  42. ```js
  43. var unicode_cp10000_255 = cptable[10000].dec[255]; // ˇ
  44. ```
  45. To get the codepoint for a given character, use the `enc` property:
  46. ```js
  47. var cp10000_711 = cptable[10000].enc[String.fromCharCode(711)]; // 255
  48. ```
  49. There are a few utilities that deal with strings and buffers:
  50. ```js
  51. var 汇总 = cptable.utils.decode(936, [0xbb,0xe3,0xd7,0xdc]);
  52. var buf = cptable.utils.encode(936, 汇总);
  53. var sushi= cptable.utils.decode(65001, [0xf0,0x9f,0x8d,0xa3]); // 🍣
  54. var sbuf = cptable.utils.encode(65001, sushi);
  55. ```
  56. `cptable.utils.encode(CP, data, ofmt)` accepts a String or Array of characters
  57. and returns a representation controlled by `ofmt`:
  58. - Default output is a Buffer (or Array) of bytes (integers between 0 and 255)
  59. - If `ofmt == 'str'`, return a binary String (byte `i` is `o.charCodeAt(i)`)
  60. - If `ofmt == 'arr'`, return an Array of bytes
  61. `cptable.utils.decode(CP, data)` accepts a byte String or Array of numbers or
  62. Buffer and returns a JS string.
  63. ## Known Excel Codepages
  64. A much smaller script, including only the codepages known to be used in Excel,
  65. is available under the name `cpexcel`. It exposes the same variable `cptable`
  66. and is suitable as a drop-in replacement when the full codepage tables are not
  67. needed.
  68. In node:
  69. ```js
  70. var cptable = require('codepage/dist/cpexcel.full');
  71. ```
  72. ## Rolling your own script
  73. The `make.sh` script in the repo can take a manifest and generate JS source.
  74. Usage:
  75. ```bash
  76. $ bash make.sh path_to_manifest output_file_name JSVAR
  77. ```
  78. where
  79. - `JSVAR` is the name of the exported variable (generally `cptable`)
  80. - `output_file_name` is the output file (`cpexcel.js`, `cptable.js`, ...)
  81. - `path_to_manifest` is the path to the manifest file.
  82. The manifest file is expected to be a CSV with 3 columns:
  83. ```
  84. <codepage number>,<source>,<size>
  85. ```
  86. If a source is specified, it will try to download the specified file and parse.
  87. The file format is expected to follow the format from the unicode.org site.
  88. The size should be `1` for a single-byte codepage and `2` for a double-byte
  89. codepage. For mixed codepages (which use some single- and some double-byte
  90. codes), the script assumes the mapping is a prefix code and generates efficient
  91. JS code.
  92. Generated scripts only include the mapping. `cat` a mapping with `cputils.js`
  93. to produce a complete script like `cpexcel.full.js`.
  94. ## Building the complete script
  95. This script uses [voc](npm.im/voc). The script to build the codepage tables and
  96. the JS source is `codepage.md`, so building involves `voc codepage.md`.
  97. ## Generated Codepages
  98. The complete list of codepages can be found in the file `pages.csv`.
  99. Some codepages are easier to implement algorithmically. Since those character
  100. tables are not generated, there is no corresponding entry (they are "magic").
  101. | CP# | Source | Description |
  102. |--------:|:-----------:|:-----------------------------------------------------|
  103. | ` 37` | unicode.org | IBM EBCDIC US-Canada |
  104. | ` 437` | unicode.org | OEM United States |
  105. | ` 500` | unicode.org | IBM EBCDIC International |
  106. | ` 620` | NLS | Mazovia (Polish) MS-DOS |
  107. | ` 708` | Windows 7 | Arabic (ASMO 708) |
  108. | ` 720` | Windows 7 | Arabic (Transparent ASMO); Arabic (DOS) |
  109. | ` 737` | unicode.org | OEM Greek (formerly 437G); Greek (DOS) |
  110. | ` 775` | unicode.org | OEM Baltic; Baltic (DOS) |
  111. | ` 808` | unicode.org | OEM Russian; Cyrillic + Euro symbol |
  112. | ` 850` | unicode.org | OEM Multilingual Latin 1; Western European (DOS) |
  113. | ` 852` | unicode.org | OEM Latin 2; Central European (DOS) |
  114. | ` 855` | unicode.org | OEM Cyrillic (primarily Russian) |
  115. | ` 857` | unicode.org | OEM Turkish; Turkish (DOS) |
  116. | ` 858` | Windows 7 | OEM Multilingual Latin 1 + Euro symbol |
  117. | ` 860` | unicode.org | OEM Portuguese; Portuguese (DOS) |
  118. | ` 861` | unicode.org | OEM Icelandic; Icelandic (DOS) |
  119. | ` 862` | unicode.org | OEM Hebrew; Hebrew (DOS) |
  120. | ` 863` | unicode.org | OEM French Canadian; French Canadian (DOS) |
  121. | ` 864` | unicode.org | OEM Arabic; Arabic (864) |
  122. | ` 865` | unicode.org | OEM Nordic; Nordic (DOS) |
  123. | ` 866` | unicode.org | OEM Russian; Cyrillic (DOS) |
  124. | ` 869` | unicode.org | OEM Modern Greek; Greek, Modern (DOS) |
  125. | ` 870` | Windows 7 | IBM EBCDIC Multilingual/ROECE (Latin 2) |
  126. | ` 872` | unicode.org | OEM Cyrillic (primarily Russian) + Euro Symbol |
  127. | ` 874` | unicode.org | Windows Thai |
  128. | ` 875` | unicode.org | IBM EBCDIC Greek Modern |
  129. | ` 895` | NLS | Kamenický (Czech) MS-DOS |
  130. | ` 932` | unicode.org | Japanese Shift-JIS |
  131. | ` 936` | unicode.org | Simplified Chinese GBK |
  132. | ` 949` | unicode.org | Korean |
  133. | ` 950` | unicode.org | Traditional Chinese Big5 |
  134. | ` 1010` | IBM | IBM EBCDIC French |
  135. | ` 1026` | unicode.org | IBM EBCDIC Turkish (Latin 5) |
  136. | ` 1047` | Windows 7 | IBM EBCDIC Latin 1/Open System |
  137. | ` 1132` | IBM | IBM EBCDIC Lao (1132 / 1133 / 1341) |
  138. | ` 1140` | Windows 7 | IBM EBCDIC US-Canada (037 + Euro symbol) |
  139. | ` 1141` | Windows 7 | IBM EBCDIC Germany (20273 + Euro symbol) |
  140. | ` 1142` | Windows 7 | IBM EBCDIC Denmark-Norway (20277 + Euro symbol) |
  141. | ` 1143` | Windows 7 | IBM EBCDIC Finland-Sweden (20278 + Euro symbol) |
  142. | ` 1144` | Windows 7 | IBM EBCDIC Italy (20280 + Euro symbol) |
  143. | ` 1145` | Windows 7 | IBM EBCDIC Latin America-Spain (20284 + Euro symbol) |
  144. | ` 1146` | Windows 7 | IBM EBCDIC United Kingdom (20285 + Euro symbol) |
  145. | ` 1147` | Windows 7 | IBM EBCDIC France (20297 + Euro symbol) |
  146. | ` 1148` | Windows 7 | IBM EBCDIC International (500 + Euro symbol) |
  147. | ` 1149` | Windows 7 | IBM EBCDIC Icelandic (20871 + Euro symbol) |
  148. | ` 1200` | magic | Unicode UTF-16, little endian (BMP of ISO 10646) |
  149. | ` 1201` | magic | Unicode UTF-16, big endian |
  150. | ` 1250` | unicode.org | Windows Central Europe |
  151. | ` 1251` | unicode.org | Windows Cyrillic |
  152. | ` 1252` | unicode.org | Windows Latin I |
  153. | ` 1253` | unicode.org | Windows Greek |
  154. | ` 1254` | unicode.org | Windows Turkish |
  155. | ` 1255` | unicode.org | Windows Hebrew |
  156. | ` 1256` | unicode.org | Windows Arabic |
  157. | ` 1257` | unicode.org | Windows Baltic |
  158. | ` 1258` | unicode.org | Windows Vietnam |
  159. | ` 1361` | Windows 7 | Korean (Johab) |
  160. | `10000` | unicode.org | MAC Roman |
  161. | `10001` | Windows 7 | Japanese (Mac) |
  162. | `10002` | Windows 7 | MAC Traditional Chinese (Big5) |
  163. | `10003` | Windows 7 | Korean (Mac) |
  164. | `10004` | Windows 7 | Arabic (Mac) |
  165. | `10005` | Windows 7 | Hebrew (Mac) |
  166. | `10006` | unicode.org | Greek (Mac) |
  167. | `10007` | unicode.org | Cyrillic (Mac) |
  168. | `10008` | Windows 7 | MAC Simplified Chinese (GB 2312) |
  169. | `10010` | Windows 7 | Romanian (Mac) |
  170. | `10017` | Windows 7 | Ukrainian (Mac) |
  171. | `10021` | Windows 7 | Thai (Mac) |
  172. | `10029` | unicode.org | MAC Latin 2 (Central European) |
  173. | `10079` | unicode.org | Icelandic (Mac) |
  174. | `10081` | unicode.org | Turkish (Mac) |
  175. | `10082` | Windows 7 | Croatian (Mac) |
  176. | `12000` | magic | Unicode UTF-32, little endian byte order |
  177. | `12001` | magic | Unicode UTF-32, big endian byte order |
  178. | `20000` | Windows 7 | CNS Taiwan (Chinese Traditional) |
  179. | `20001` | Windows 7 | TCA Taiwan |
  180. | `20002` | Windows 7 | ETEN Taiwan (Chinese Traditional) |
  181. | `20003` | Windows 7 | IBM5550 Taiwan |
  182. | `20004` | Windows 7 | TeleText Taiwan |
  183. | `20005` | Windows 7 | Wang Taiwan |
  184. | `20105` | Windows 7 | Western European IA5 (IRV International Alphabet 5) |
  185. | `20106` | Windows 7 | IA5 German (7-bit) |
  186. | `20107` | Windows 7 | IA5 Swedish (7-bit) |
  187. | `20108` | Windows 7 | IA5 Norwegian (7-bit) |
  188. | `20127` | magic | US-ASCII (7-bit) |
  189. | `20261` | Windows 7 | T.61 |
  190. | `20269` | Windows 7 | ISO 6937 Non-Spacing Accent |
  191. | `20273` | Windows 7 | IBM EBCDIC Germany |
  192. | `20277` | Windows 7 | IBM EBCDIC Denmark-Norway |
  193. | `20278` | Windows 7 | IBM EBCDIC Finland-Sweden |
  194. | `20280` | Windows 7 | IBM EBCDIC Italy |
  195. | `20284` | Windows 7 | IBM EBCDIC Latin America-Spain |
  196. | `20285` | Windows 7 | IBM EBCDIC United Kingdom |
  197. | `20290` | Windows 7 | IBM EBCDIC Japanese Katakana Extended |
  198. | `20297` | Windows 7 | IBM EBCDIC France |
  199. | `20420` | Windows 7 | IBM EBCDIC Arabic |
  200. | `20423` | Windows 7 | IBM EBCDIC Greek |
  201. | `20424` | Windows 7 | IBM EBCDIC Hebrew |
  202. | `20833` | Windows 7 | IBM EBCDIC Korean Extended |
  203. | `20838` | Windows 7 | IBM EBCDIC Thai |
  204. | `20866` | Windows 7 | Russian Cyrillic (KOI8-R) |
  205. | `20871` | Windows 7 | IBM EBCDIC Icelandic |
  206. | `20880` | Windows 7 | IBM EBCDIC Cyrillic Russian |
  207. | `20905` | Windows 7 | IBM EBCDIC Turkish |
  208. | `20924` | Windows 7 | IBM EBCDIC Latin 1/Open System (1047 + Euro symbol) |
  209. | `20932` | Windows 7 | Japanese (JIS 0208-1990 and 0212-1990) |
  210. | `20936` | Windows 7 | Simplified Chinese (GB2312-80) |
  211. | `20949` | Windows 7 | Korean Wansung |
  212. | `21025` | Windows 7 | IBM EBCDIC Cyrillic Serbian-Bulgarian |
  213. | `21027` | NLS | Extended/Ext Alpha Lowercase |
  214. | `21866` | Windows 7 | Ukrainian Cyrillic (KOI8-U) |
  215. | `28591` | unicode.org | ISO 8859-1 Latin 1 (Western European) |
  216. | `28592` | unicode.org | ISO 8859-2 Latin 2 (Central European) |
  217. | `28593` | unicode.org | ISO 8859-3 Latin 3 |
  218. | `28594` | unicode.org | ISO 8859-4 Baltic |
  219. | `28595` | unicode.org | ISO 8859-5 Cyrillic |
  220. | `28596` | unicode.org | ISO 8859-6 Arabic |
  221. | `28597` | unicode.org | ISO 8859-7 Greek |
  222. | `28598` | unicode.org | ISO 8859-8 Hebrew (ISO-Visual) |
  223. | `28599` | unicode.org | ISO 8859-9 Turkish |
  224. | `28600` | unicode.org | ISO 8859-10 Latin 6 |
  225. | `28601` | unicode.org | ISO 8859-11 Latin (Thai) |
  226. | `28603` | unicode.org | ISO 8859-13 Latin 7 (Estonian) |
  227. | `28604` | unicode.org | ISO 8859-14 Latin 8 (Celtic) |
  228. | `28605` | unicode.org | ISO 8859-15 Latin 9 |
  229. | `28606` | unicode.org | ISO 8859-15 Latin 10 |
  230. | `29001` | Windows 7 | Europa 3 |
  231. | `38598` | Windows 7 | ISO 8859-8 Hebrew (ISO-Logical) |
  232. | `47451` | unicode.org | Atari ST/TT |
  233. | `50220` | magic | ISO 2022 JIS Japanese with no halfwidth Katakana |
  234. | `50221` | magic | ISO 2022 JIS Japanese with halfwidth Katakana |
  235. | `50222` | magic | ISO 2022 Japanese JIS X 0201-1989 (1 byte Kana-SO/SI)|
  236. | `50225` | magic | ISO 2022 Korean |
  237. | `50227` | magic | ISO 2022 Simplified Chinese |
  238. | `51932` | Windows 7 | EUC Japanese |
  239. | `51936` | Windows 7 | EUC Simplified Chinese |
  240. | `51949` | Windows 7 | EUC Korean |
  241. | `52936` | Windows 7 | HZ-GB2312 Simplified Chinese |
  242. | `54936` | Windows 7 | GB18030 Simplified Chinese (4 byte) |
  243. | `57002` | Windows 7 | ISCII Devanagari |
  244. | `57003` | Windows 7 | ISCII Bengali |
  245. | `57004` | Windows 7 | ISCII Tamil |
  246. | `57005` | Windows 7 | ISCII Telugu |
  247. | `57006` | Windows 7 | ISCII Assamese |
  248. | `57007` | Windows 7 | ISCII Oriya |
  249. | `57008` | Windows 7 | ISCII Kannada |
  250. | `57009` | Windows 7 | ISCII Malayalam |
  251. | `57010` | Windows 7 | ISCII Gujarati |
  252. | `57011` | Windows 7 | ISCII Punjabi |
  253. | `65000` | magic | Unicode (UTF-7) |
  254. | `65001` | magic | Unicode (UTF-8) |
  255. `unicode.org` refers to the Unicode Consortium Public Mappings, a database of
  256. various mappings between Unicode characters and respective character sets. The
  257. tables are processed by a few scripts in the build process.
  258. `IBM` refers to the IBM coded character set database. Even though IBM uses a
  259. different numbering scheme from Windows, the IBM numbers are used when there is
  260. no conflict. The tables are manually generated from the symbol manifests.
  261. `Windows 7` refers to direct inspection of Windows 7 machines using .NET class
  262. `System.Text.Encoding`. The enclosed `MakeEncoding.cs` C# program brute-forces
  263. code pages. `MakeEncoding.cs` deviates from unicode.org in some cases. When they
  264. map a given code to different characters, unicode.org value is used. When
  265. unicode.org does not prescribe a value, `MakeEncoding.cs` value is used.
  266. `NLS` refers to the National Language Support files supplied in various versions
  267. of Windows. In older versions of Windows (like Windows 98) these files followed
  268. the name pattern `CP_#.NLS`, but newer versions use the name pattern `C_#.NLS`.
  269. ## Testing
  270. `make test` will run the nodejs-based test.
  271. To run the in-browser tests, run a local server and go to the `ctest` directory.
  272. `make ctestserv` will start a python `SimpleHTTPServer` server on port 8000.
  273. To update the browser artifacts, run `make ctest`.
  274. ## Sources
  275. - [Unicode Consortium Public Mappings](http://www.unicode.org/Public/MAPPINGS/)
  276. - [Windows Code Page Enumeration](http://msdn.microsoft.com/en-us/library/cc195051.aspx)
  277. - [Windows Code Page Identifiers](http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756.aspx)
  278. - [IBM Coded Character Sets](https://www-01.ibm.com/software/globalization/ccsid/ccsid_registered.html)
  279. - [ISO/IEC 2022 / ECMA-35](https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-035.pdf)
  280. - [International Register of Coded Character Sets To Be Used With Escape Sequences](https://www.itscj.ipsj.or.jp/itscj_english/iso-ir/ISO-IR.pdf)
  281. - [Japanese Character Encoding for Internet Messages](https://tools.ietf.org/html/rfc1468)
  282. ## License
  283. Please consult the attached LICENSE file for details. All rights not explicitly
  284. granted by the Apache 2.0 license are reserved by the Original Author.
  285. ## Badges
  286. [![Sauce Test Status](https://saucelabs.com/browser-matrix/codepage.svg)](https://saucelabs.com/u/codepage)
  287. [![Build Status](https://travis-ci.org/SheetJS/js-codepage.svg?branch=master)](https://travis-ci.org/SheetJS/js-codepage)
  288. [![Coverage Status](http://img.shields.io/coveralls/SheetJS/js-codepage/master.svg)](https://coveralls.io/r/SheetJS/js-codepage?branch=master)
  289. [![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-codepage?pixel)](https://github.com/SheetJS/js-codepage)