summaryrefslogtreecommitdiff
path: root/encoding_jis.js
diff options
context:
space:
mode:
Diffstat (limited to 'encoding_jis.js')
-rw-r--r--encoding_jis.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/encoding_jis.js b/encoding_jis.js
index d807385..c6152d4 100644
--- a/encoding_jis.js
+++ b/encoding_jis.js
@@ -5,25 +5,31 @@
5// the amount of 19968 to save 5kBytes in this script, so the 5// the amount of 19968 to save 5kBytes in this script, so the
6// actual value is 19968 + encoding_jis_0208_1[ x ] 6// actual value is 19968 + encoding_jis_0208_1[ x ]
7 7
8var page = {
9 us_ascii : 0,
10 jis0208 : 1,
11 jis0201 : 2
12};
13
8function decode_jis( str ) { 14function decode_jis( str ) {
9 var outstring = ""; 15 var outstring = "";
10 var cur_page = "us-ascii"; 16 var cur_page = page.us_ascii;
11 17
12 for( i=0; i<str.length; ++i ) { 18 for( i=0; i<str.length; ++i ) {
13 var append = String.fromCharCode(0xfffd); 19 var append = String.fromCharCode(0xfffd);
14 if( str.charCodeAt( i ) == 27 ) { 20 if( str.charCodeAt( i ) == 27 ) {
15 switch( str.charCodeAt( i + 1 ) * 256 + str.charCodeAt( i + 2 ) ) { 21 switch( str.charCodeAt( i + 1 ) * 256 + str.charCodeAt( i + 2 ) ) {
16 case 0x2440: 22 case 0x2440:
17 cur_page = "jis0208"; // -1978 23 cur_page = page.jis0208; // -1978
18 break; 24 break;
19 case 0x2442: 25 case 0x2442:
20 cur_page = "jis0208"; // -1983 26 cur_page = page.jis0208; // -1983
21 break; 27 break;
22 case 0x2842: 28 case 0x2842:
23 cur_page = "us-ascii"; 29 cur_page = page.us_ascii;
24 break; 30 break;
25 case 0x284a: 31 case 0x284a:
26 cur_page = "jis0201"; 32 cur_page = page.jis0201;
27 break; 33 break;
28 default: 34 default:
29 return outstring + append; 35 return outstring + append;
@@ -32,16 +38,16 @@ function decode_jis( str ) {
32 continue; 38 continue;
33 } 39 }
34 switch( cur_page ) { 40 switch( cur_page ) {
35 case "us-ascii": 41 case page.us_ascii:
36 append = String.fromCharCode( encoding_8859_1[ str.charCodeAt( i ) & 0xff ] ); 42 append = String.fromCharCode( str.charCodeAt( i ) & 0xff );
37 break; 43 break;
38 case "jis0201": 44 case page.jis0201:
39 var off = str.charCodeAt( i ) & 0xff; 45 var off = str.charCodeAt( i ) & 0xff;
40 if( off >= 0x20 && x <= 0xdf ) { 46 if( off >= 0x20 && x <= 0xdf ) {
41 append = String.fromCharCode( encoding_jis_0201[ off - 32 ] ); 47 append = String.fromCharCode( encoding_jis_0201[ off - 32 ] );
42 } 48 }
43 break; 49 break;
44 case "jis0208": 50 case page.jis0208:
45 if( i>str.length-1 ) { return outstring + append; } 51 if( i>str.length-1 ) { return outstring + append; }
46 var x0 = ( str.charCodeAt( i++ ) - 0x21 ) & 0xff; 52 var x0 = ( str.charCodeAt( i++ ) - 0x21 ) & 0xff;
47 var x1 = ( str.charCodeAt( i ) - 0x21 ) & 0xff; 53 var x1 = ( str.charCodeAt( i ) - 0x21 ) & 0xff;