@mavogel/awscdk-rootmail 0.1.38 → 0.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +8 -8
- package/lib/rootmail.js +1 -1
- package/lib/ses-receive.js +1 -1
- package/node_modules/@aws-sdk/checksums/package.json +2 -2
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-cjs/index.js +4 -2
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-es/models/enums.js +1 -0
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-es/runtimeConfig.js +2 -1
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/CreateLogGroupCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/DeleteAccountPolicyCommand.d.ts +10 -0
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/DeleteRetentionPolicyCommand.d.ts +3 -0
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/DescribeAccountPoliciesCommand.d.ts +4 -0
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/DescribeLogGroupsCommand.d.ts +5 -2
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/ListAggregateLogGroupSummariesCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/ListLogGroupsCommand.d.ts +2 -2
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/PutAccountPolicyCommand.d.ts +56 -2
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/PutRetentionPolicyCommand.d.ts +8 -0
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/models/enums.d.ts +1 -0
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/models/models_0.d.ts +57 -6
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/ts3.4/models/enums.d.ts +1 -0
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/ts3.4/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/client-cloudwatch-logs/package.json +3 -3
- package/node_modules/@aws-sdk/client-route-53/dist-cjs/index.js +3 -2
- package/node_modules/@aws-sdk/client-route-53/dist-es/runtimeConfig.js +2 -1
- package/node_modules/@aws-sdk/client-route-53/dist-types/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/client-route-53/dist-types/ts3.4/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/client-route-53/package.json +3 -3
- package/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-s3/dist-types/S3Client.d.ts +1 -1
- package/node_modules/@aws-sdk/client-s3/dist-types/ts3.4/S3Client.d.ts +1 -1
- package/node_modules/@aws-sdk/client-s3/package.json +6 -6
- package/node_modules/@aws-sdk/client-ses/dist-cjs/index.js +3 -2
- package/node_modules/@aws-sdk/client-ses/dist-es/runtimeConfig.js +2 -1
- package/node_modules/@aws-sdk/client-ses/dist-types/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/client-ses/dist-types/ts3.4/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/client-ses/package.json +3 -3
- package/node_modules/@aws-sdk/client-ssm/dist-cjs/index.js +3 -2
- package/node_modules/@aws-sdk/client-ssm/dist-es/runtimeConfig.js +2 -1
- package/node_modules/@aws-sdk/client-ssm/dist-types/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/client-ssm/dist-types/ts3.4/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/client-ssm/package.json +3 -3
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js +12 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/client/getDefaultSocketTimeout.js +10 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/client/index.browser.js +1 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/client/index.js +1 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/client/index.native.js +1 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/client/getDefaultSocketTimeout.d.ts +11 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/client/index.browser.d.ts +1 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/client/index.d.ts +1 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/client/index.native.d.ts +1 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/getDefaultSocketTimeout.d.ts +4 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/index.browser.d.ts +1 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/index.d.ts +1 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/index.native.d.ts +1 -0
- package/node_modules/@aws-sdk/core/package.json +1 -1
- package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
- package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +2 -2
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +3 -2
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +3 -2
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +3 -2
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +3 -2
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +3 -2
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/runtimeConfig.js +2 -1
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/runtimeConfig.js +2 -1
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/runtimeConfig.js +2 -1
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/runtimeConfig.js +2 -1
- package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/runtimeConfig.js +2 -1
- package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/cognito-identity/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/signin/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/sso/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/sso-oidc/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/sts/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/nested-clients/dist-types/ts3.4/submodules/cognito-identity/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/nested-clients/dist-types/ts3.4/submodules/signin/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/nested-clients/dist-types/ts3.4/submodules/sso/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/nested-clients/dist-types/ts3.4/submodules/sso-oidc/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/nested-clients/dist-types/ts3.4/submodules/sts/runtimeConfig.d.ts +1 -0
- package/node_modules/@aws-sdk/nested-clients/package.json +2 -2
- package/node_modules/@aws-sdk/token-providers/package.json +3 -3
- package/node_modules/@zone-eu/mailsplit/package.json +5 -5
- package/node_modules/encoding-japanese/README.md +10 -5
- package/node_modules/encoding-japanese/encoding.js +761 -3168
- package/node_modules/encoding-japanese/encoding.min.js +3 -3
- package/node_modules/encoding-japanese/index.d.ts +39 -25
- package/node_modules/encoding-japanese/package.json +6 -6
- package/node_modules/encoding-japanese/src/config.js +7 -33
- package/node_modules/encoding-japanese/src/encoding-convert.js +332 -279
- package/node_modules/encoding-japanese/src/encoding-table.js +108 -5
- package/node_modules/encoding-japanese/src/index.js +61 -49
- package/node_modules/encoding-japanese/src/utf8-to-jis-alias-table.js +3 -1
- package/node_modules/encoding-japanese/src/utf8-to-jis-table.js +91 -1492
- package/node_modules/encoding-japanese/src/utf8-to-jisx0212-table.js +76 -1220
- package/node_modules/encoding-japanese/src/util.js +70 -62
- package/node_modules/libmime/CHANGELOG.md +7 -0
- package/node_modules/libmime/package.json +6 -6
- package/node_modules/mailparser/CHANGELOG.md +7 -0
- package/node_modules/mailparser/package.json +8 -5
- package/package.json +7 -7
- package/node_modules/encoding-japanese/src/jis-to-utf8-table.js +0 -5
- package/node_modules/encoding-japanese/src/jisx0212-to-utf8-table.js +0 -5
|
@@ -8,11 +8,12 @@ var sjisExt = require('./sjis-ext');
|
|
|
8
8
|
* JIS to SJIS
|
|
9
9
|
*/
|
|
10
10
|
function JISToSJIS(data) {
|
|
11
|
-
var results = [];
|
|
12
11
|
var index = 0;
|
|
13
12
|
var i = 0;
|
|
14
13
|
var len = data && data.length;
|
|
15
14
|
var b1, b2;
|
|
15
|
+
var results = createBuffer(8, len);
|
|
16
|
+
var n = 0;
|
|
16
17
|
|
|
17
18
|
for (; i < len; i++) {
|
|
18
19
|
// escape sequence
|
|
@@ -32,7 +33,7 @@ function JISToSJIS(data) {
|
|
|
32
33
|
|
|
33
34
|
i += 3;
|
|
34
35
|
if (data[i] === void 0) {
|
|
35
|
-
return results;
|
|
36
|
+
return util.truncateBuffer(results, n);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -60,19 +61,19 @@ function JISToSJIS(data) {
|
|
|
60
61
|
}
|
|
61
62
|
b2 += 0x7E;
|
|
62
63
|
}
|
|
63
|
-
results[
|
|
64
|
-
results[
|
|
64
|
+
results[n++] = b1 & 0xFF;
|
|
65
|
+
results[n++] = b2 & 0xFF;
|
|
65
66
|
} else if (index === 2) {
|
|
66
|
-
results[
|
|
67
|
+
results[n++] = data[i] + 0x80 & 0xFF;
|
|
67
68
|
} else if (index === 3) {
|
|
68
69
|
// Shift_JIS cannot convert JIS X 0212:1990.
|
|
69
|
-
results[
|
|
70
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
70
71
|
} else {
|
|
71
|
-
results[
|
|
72
|
+
results[n++] = data[i] & 0xFF;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
return results;
|
|
76
|
+
return util.truncateBuffer(results, n);
|
|
76
77
|
}
|
|
77
78
|
exports.JISToSJIS = JISToSJIS;
|
|
78
79
|
|
|
@@ -80,13 +81,13 @@ exports.JISToSJIS = JISToSJIS;
|
|
|
80
81
|
* JIS to EUCJP
|
|
81
82
|
*/
|
|
82
83
|
function JISToEUCJP(data) {
|
|
83
|
-
var results = [];
|
|
84
84
|
var index = 0;
|
|
85
85
|
var len = data && data.length;
|
|
86
86
|
var i = 0;
|
|
87
|
+
var results = createBuffer(8, len * 2);
|
|
88
|
+
var n = 0;
|
|
87
89
|
|
|
88
90
|
for (; i < len; i++) {
|
|
89
|
-
|
|
90
91
|
// escape sequence
|
|
91
92
|
while (data[i] === 0x1B) {
|
|
92
93
|
if ((data[i + 1] === 0x24 && data[i + 2] === 0x42) ||
|
|
@@ -104,26 +105,26 @@ function JISToEUCJP(data) {
|
|
|
104
105
|
|
|
105
106
|
i += 3;
|
|
106
107
|
if (data[i] === void 0) {
|
|
107
|
-
return results;
|
|
108
|
+
return util.truncateBuffer(results, n);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
if (index === 1) {
|
|
112
|
-
results[
|
|
113
|
-
results[
|
|
113
|
+
results[n++] = data[i] + 0x80 & 0xFF;
|
|
114
|
+
results[n++] = data[++i] + 0x80 & 0xFF;
|
|
114
115
|
} else if (index === 2) {
|
|
115
|
-
results[
|
|
116
|
-
results[
|
|
116
|
+
results[n++] = 0x8E;
|
|
117
|
+
results[n++] = data[i] + 0x80 & 0xFF;
|
|
117
118
|
} else if (index === 3) {
|
|
118
|
-
results[
|
|
119
|
-
results[
|
|
120
|
-
results[
|
|
119
|
+
results[n++] = 0x8F;
|
|
120
|
+
results[n++] = data[i] + 0x80 & 0xFF;
|
|
121
|
+
results[n++] = data[++i] + 0x80 & 0xFF;
|
|
121
122
|
} else {
|
|
122
|
-
results[
|
|
123
|
+
results[n++] = data[i] & 0xFF;
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
return results;
|
|
127
|
+
return util.truncateBuffer(results, n);
|
|
127
128
|
}
|
|
128
129
|
exports.JISToEUCJP = JISToEUCJP;
|
|
129
130
|
|
|
@@ -131,11 +132,12 @@ exports.JISToEUCJP = JISToEUCJP;
|
|
|
131
132
|
* SJIS to JIS
|
|
132
133
|
*/
|
|
133
134
|
function SJISToJIS(data) {
|
|
134
|
-
var results = [];
|
|
135
135
|
var index = 0;
|
|
136
136
|
var len = data && data.length;
|
|
137
137
|
var i = 0;
|
|
138
138
|
var b1, b2, remapped;
|
|
139
|
+
var results = createBuffer(8, len * 4 + 4);
|
|
140
|
+
var n = 0;
|
|
139
141
|
|
|
140
142
|
var esc = [
|
|
141
143
|
0x1B, 0x28, 0x42,
|
|
@@ -148,28 +150,28 @@ function SJISToJIS(data) {
|
|
|
148
150
|
if (b1 >= 0xA1 && b1 <= 0xDF) {
|
|
149
151
|
if (index !== 2) {
|
|
150
152
|
index = 2;
|
|
151
|
-
results[
|
|
152
|
-
results[
|
|
153
|
-
results[
|
|
153
|
+
results[n++] = esc[6];
|
|
154
|
+
results[n++] = esc[7];
|
|
155
|
+
results[n++] = esc[8];
|
|
154
156
|
}
|
|
155
|
-
results[
|
|
157
|
+
results[n++] = b1 - 0x80 & 0xFF;
|
|
156
158
|
} else if (b1 >= 0x80) {
|
|
157
159
|
b2 = data[++i];
|
|
158
160
|
if (b2 === 0x7F) {
|
|
159
161
|
if (index !== 0) {
|
|
160
162
|
index = 0;
|
|
161
|
-
results[
|
|
162
|
-
results[
|
|
163
|
-
results[
|
|
163
|
+
results[n++] = esc[0];
|
|
164
|
+
results[n++] = esc[1];
|
|
165
|
+
results[n++] = esc[2];
|
|
164
166
|
}
|
|
165
|
-
results[
|
|
167
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
166
168
|
continue;
|
|
167
169
|
}
|
|
168
170
|
if (index !== 1) {
|
|
169
171
|
index = 1;
|
|
170
|
-
results[
|
|
171
|
-
results[
|
|
172
|
-
results[
|
|
172
|
+
results[n++] = esc[3];
|
|
173
|
+
results[n++] = esc[4];
|
|
174
|
+
results[n++] = esc[5];
|
|
173
175
|
}
|
|
174
176
|
|
|
175
177
|
if (sjisExt.hasCP932DuplicateCode(b1)) {
|
|
@@ -199,26 +201,26 @@ function SJISToJIS(data) {
|
|
|
199
201
|
}
|
|
200
202
|
b2 -= 0x7E;
|
|
201
203
|
}
|
|
202
|
-
results[
|
|
203
|
-
results[
|
|
204
|
+
results[n++] = b1 & 0xFF;
|
|
205
|
+
results[n++] = b2 & 0xFF;
|
|
204
206
|
} else {
|
|
205
207
|
if (index !== 0) {
|
|
206
208
|
index = 0;
|
|
207
|
-
results[
|
|
208
|
-
results[
|
|
209
|
-
results[
|
|
209
|
+
results[n++] = esc[0];
|
|
210
|
+
results[n++] = esc[1];
|
|
211
|
+
results[n++] = esc[2];
|
|
210
212
|
}
|
|
211
|
-
results[
|
|
213
|
+
results[n++] = b1 & 0xFF;
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
216
|
|
|
215
217
|
if (index !== 0) {
|
|
216
|
-
results[
|
|
217
|
-
results[
|
|
218
|
-
results[
|
|
218
|
+
results[n++] = esc[0];
|
|
219
|
+
results[n++] = esc[1];
|
|
220
|
+
results[n++] = esc[2];
|
|
219
221
|
}
|
|
220
222
|
|
|
221
|
-
return results;
|
|
223
|
+
return util.truncateBuffer(results, n);
|
|
222
224
|
}
|
|
223
225
|
exports.SJISToJIS = SJISToJIS;
|
|
224
226
|
|
|
@@ -226,20 +228,21 @@ exports.SJISToJIS = SJISToJIS;
|
|
|
226
228
|
* SJIS to EUCJP
|
|
227
229
|
*/
|
|
228
230
|
function SJISToEUCJP(data) {
|
|
229
|
-
var results = [];
|
|
230
231
|
var len = data && data.length;
|
|
231
232
|
var i = 0;
|
|
232
233
|
var b1, b2, remapped;
|
|
234
|
+
var results = createBuffer(8, len * 2);
|
|
235
|
+
var n = 0;
|
|
233
236
|
|
|
234
237
|
for (; i < len; i++) {
|
|
235
238
|
b1 = data[i];
|
|
236
239
|
if (b1 >= 0xA1 && b1 <= 0xDF) {
|
|
237
|
-
results[
|
|
238
|
-
results[
|
|
240
|
+
results[n++] = 0x8E;
|
|
241
|
+
results[n++] = b1;
|
|
239
242
|
} else if (b1 >= 0x81) {
|
|
240
243
|
b2 = data[++i];
|
|
241
244
|
if (b2 === 0x7F) {
|
|
242
|
-
results[
|
|
245
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
243
246
|
continue;
|
|
244
247
|
}
|
|
245
248
|
if (sjisExt.hasCP932DuplicateCode(b1)) {
|
|
@@ -270,14 +273,14 @@ function SJISToEUCJP(data) {
|
|
|
270
273
|
}
|
|
271
274
|
b2 += 0x02;
|
|
272
275
|
}
|
|
273
|
-
results[
|
|
274
|
-
results[
|
|
276
|
+
results[n++] = b1 & 0xFF;
|
|
277
|
+
results[n++] = b2 & 0xFF;
|
|
275
278
|
} else {
|
|
276
|
-
results[
|
|
279
|
+
results[n++] = b1 & 0xFF;
|
|
277
280
|
}
|
|
278
281
|
}
|
|
279
282
|
|
|
280
|
-
return results;
|
|
283
|
+
return util.truncateBuffer(results, n);
|
|
281
284
|
}
|
|
282
285
|
exports.SJISToEUCJP = SJISToEUCJP;
|
|
283
286
|
|
|
@@ -285,11 +288,12 @@ exports.SJISToEUCJP = SJISToEUCJP;
|
|
|
285
288
|
* EUCJP to JIS
|
|
286
289
|
*/
|
|
287
290
|
function EUCJPToJIS(data) {
|
|
288
|
-
var results = [];
|
|
289
291
|
var index = 0;
|
|
290
292
|
var len = data && data.length;
|
|
291
293
|
var i = 0;
|
|
292
294
|
var b;
|
|
295
|
+
var results = createBuffer(8, len * 4 + 5);
|
|
296
|
+
var n = 0;
|
|
293
297
|
|
|
294
298
|
// escape sequence
|
|
295
299
|
var esc = [
|
|
@@ -304,48 +308,48 @@ function EUCJPToJIS(data) {
|
|
|
304
308
|
if (b === 0x8E) {
|
|
305
309
|
if (index !== 2) {
|
|
306
310
|
index = 2;
|
|
307
|
-
results[
|
|
308
|
-
results[
|
|
309
|
-
results[
|
|
311
|
+
results[n++] = esc[6];
|
|
312
|
+
results[n++] = esc[7];
|
|
313
|
+
results[n++] = esc[8];
|
|
310
314
|
}
|
|
311
|
-
results[
|
|
315
|
+
results[n++] = data[++i] - 0x80 & 0xFF;
|
|
312
316
|
} else if (b === 0x8F) {
|
|
313
317
|
if (index !== 3) {
|
|
314
318
|
index = 3;
|
|
315
|
-
results[
|
|
316
|
-
results[
|
|
317
|
-
results[
|
|
318
|
-
results[
|
|
319
|
+
results[n++] = esc[9];
|
|
320
|
+
results[n++] = esc[10];
|
|
321
|
+
results[n++] = esc[11];
|
|
322
|
+
results[n++] = esc[12];
|
|
319
323
|
}
|
|
320
|
-
results[
|
|
321
|
-
results[
|
|
324
|
+
results[n++] = data[++i] - 0x80 & 0xFF;
|
|
325
|
+
results[n++] = data[++i] - 0x80 & 0xFF;
|
|
322
326
|
} else if (b > 0x8E) {
|
|
323
327
|
if (index !== 1) {
|
|
324
328
|
index = 1;
|
|
325
|
-
results[
|
|
326
|
-
results[
|
|
327
|
-
results[
|
|
329
|
+
results[n++] = esc[3];
|
|
330
|
+
results[n++] = esc[4];
|
|
331
|
+
results[n++] = esc[5];
|
|
328
332
|
}
|
|
329
|
-
results[
|
|
330
|
-
results[
|
|
333
|
+
results[n++] = b - 0x80 & 0xFF;
|
|
334
|
+
results[n++] = data[++i] - 0x80 & 0xFF;
|
|
331
335
|
} else {
|
|
332
336
|
if (index !== 0) {
|
|
333
337
|
index = 0;
|
|
334
|
-
results[
|
|
335
|
-
results[
|
|
336
|
-
results[
|
|
338
|
+
results[n++] = esc[0];
|
|
339
|
+
results[n++] = esc[1];
|
|
340
|
+
results[n++] = esc[2];
|
|
337
341
|
}
|
|
338
|
-
results[
|
|
342
|
+
results[n++] = b & 0xFF;
|
|
339
343
|
}
|
|
340
344
|
}
|
|
341
345
|
|
|
342
346
|
if (index !== 0) {
|
|
343
|
-
results[
|
|
344
|
-
results[
|
|
345
|
-
results[
|
|
347
|
+
results[n++] = esc[0];
|
|
348
|
+
results[n++] = esc[1];
|
|
349
|
+
results[n++] = esc[2];
|
|
346
350
|
}
|
|
347
351
|
|
|
348
|
-
return results;
|
|
352
|
+
return util.truncateBuffer(results, n);
|
|
349
353
|
}
|
|
350
354
|
exports.EUCJPToJIS = EUCJPToJIS;
|
|
351
355
|
|
|
@@ -353,15 +357,16 @@ exports.EUCJPToJIS = EUCJPToJIS;
|
|
|
353
357
|
* EUCJP to SJIS
|
|
354
358
|
*/
|
|
355
359
|
function EUCJPToSJIS(data) {
|
|
356
|
-
var results = [];
|
|
357
360
|
var len = data && data.length;
|
|
358
361
|
var i = 0;
|
|
359
362
|
var b1, b2;
|
|
363
|
+
var results = createBuffer(8, len + 1);
|
|
364
|
+
var n = 0;
|
|
360
365
|
|
|
361
366
|
for (; i < len; i++) {
|
|
362
367
|
b1 = data[i];
|
|
363
368
|
if (b1 === 0x8F) {
|
|
364
|
-
results[
|
|
369
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
365
370
|
i += 2;
|
|
366
371
|
} else if (b1 > 0x8E) {
|
|
367
372
|
b2 = data[++i];
|
|
@@ -387,16 +392,16 @@ function EUCJPToSJIS(data) {
|
|
|
387
392
|
}
|
|
388
393
|
b2 -= 0x02;
|
|
389
394
|
}
|
|
390
|
-
results[
|
|
391
|
-
results[
|
|
395
|
+
results[n++] = b1 & 0xFF;
|
|
396
|
+
results[n++] = b2 & 0xFF;
|
|
392
397
|
} else if (b1 === 0x8E) {
|
|
393
|
-
results[
|
|
398
|
+
results[n++] = data[++i] & 0xFF;
|
|
394
399
|
} else {
|
|
395
|
-
results[
|
|
400
|
+
results[n++] = b1 & 0xFF;
|
|
396
401
|
}
|
|
397
402
|
}
|
|
398
403
|
|
|
399
|
-
return results;
|
|
404
|
+
return util.truncateBuffer(results, n);
|
|
400
405
|
}
|
|
401
406
|
exports.EUCJPToSJIS = EUCJPToSJIS;
|
|
402
407
|
|
|
@@ -404,12 +409,13 @@ exports.EUCJPToSJIS = EUCJPToSJIS;
|
|
|
404
409
|
* SJIS To UTF-8
|
|
405
410
|
*/
|
|
406
411
|
function SJISToUTF8(data) {
|
|
407
|
-
|
|
412
|
+
EncodingTable.initConversionTables();
|
|
408
413
|
|
|
409
|
-
var results = [];
|
|
410
414
|
var i = 0;
|
|
411
415
|
var len = data && data.length;
|
|
412
416
|
var b, b1, b2, u2, u3, jis, utf8, remapped;
|
|
417
|
+
var results = createBuffer(8, len * 3);
|
|
418
|
+
var n = 0;
|
|
413
419
|
|
|
414
420
|
for (; i < len; i++) {
|
|
415
421
|
b = data[i];
|
|
@@ -418,13 +424,13 @@ function SJISToUTF8(data) {
|
|
|
418
424
|
u2 = 0xBC | ((b2 >> 6) & 0x03);
|
|
419
425
|
u3 = 0x80 | (b2 & 0x3F);
|
|
420
426
|
|
|
421
|
-
results[
|
|
422
|
-
results[
|
|
423
|
-
results[
|
|
427
|
+
results[n++] = 0xEF;
|
|
428
|
+
results[n++] = u2 & 0xFF;
|
|
429
|
+
results[n++] = u3 & 0xFF;
|
|
424
430
|
} else if (b >= 0x80) {
|
|
425
431
|
b2 = data[++i];
|
|
426
432
|
if (b2 === 0x7F) {
|
|
427
|
-
results[
|
|
433
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
428
434
|
continue;
|
|
429
435
|
}
|
|
430
436
|
if (sjisExt.hasCP932DuplicateCode(b)) {
|
|
@@ -460,24 +466,24 @@ function SJISToUTF8(data) {
|
|
|
460
466
|
jis = (b1 << 8) + b2;
|
|
461
467
|
|
|
462
468
|
utf8 = EncodingTable.JIS_TO_UTF8_TABLE[jis];
|
|
463
|
-
if (utf8
|
|
464
|
-
results[
|
|
469
|
+
if (!utf8) {
|
|
470
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
465
471
|
} else {
|
|
466
472
|
if (utf8 < 0xFFFF) {
|
|
467
|
-
results[
|
|
468
|
-
results[
|
|
473
|
+
results[n++] = utf8 >> 8 & 0xFF;
|
|
474
|
+
results[n++] = utf8 & 0xFF;
|
|
469
475
|
} else {
|
|
470
|
-
results[
|
|
471
|
-
results[
|
|
472
|
-
results[
|
|
476
|
+
results[n++] = utf8 >> 16 & 0xFF;
|
|
477
|
+
results[n++] = utf8 >> 8 & 0xFF;
|
|
478
|
+
results[n++] = utf8 & 0xFF;
|
|
473
479
|
}
|
|
474
480
|
}
|
|
475
481
|
} else {
|
|
476
|
-
results[
|
|
482
|
+
results[n++] = data[i] & 0xFF;
|
|
477
483
|
}
|
|
478
484
|
}
|
|
479
485
|
|
|
480
|
-
return results;
|
|
486
|
+
return util.truncateBuffer(results, n);
|
|
481
487
|
}
|
|
482
488
|
exports.SJISToUTF8 = SJISToUTF8;
|
|
483
489
|
|
|
@@ -485,12 +491,13 @@ exports.SJISToUTF8 = SJISToUTF8;
|
|
|
485
491
|
* EUC-JP to UTF-8
|
|
486
492
|
*/
|
|
487
493
|
function EUCJPToUTF8(data) {
|
|
488
|
-
|
|
494
|
+
EncodingTable.initConversionTables();
|
|
489
495
|
|
|
490
|
-
var results = [];
|
|
491
496
|
var i = 0;
|
|
492
497
|
var len = data && data.length;
|
|
493
498
|
var b, b2, u2, u3, j2, j3, jis, utf8;
|
|
499
|
+
var results = createBuffer(8, len * 3);
|
|
500
|
+
var n = 0;
|
|
494
501
|
|
|
495
502
|
for (; i < len; i++) {
|
|
496
503
|
b = data[i];
|
|
@@ -499,49 +506,51 @@ function EUCJPToUTF8(data) {
|
|
|
499
506
|
u2 = 0xBC | ((b2 >> 6) & 0x03);
|
|
500
507
|
u3 = 0x80 | (b2 & 0x3F);
|
|
501
508
|
|
|
502
|
-
results[
|
|
503
|
-
results[
|
|
504
|
-
results[
|
|
509
|
+
results[n++] = 0xEF;
|
|
510
|
+
results[n++] = u2 & 0xFF;
|
|
511
|
+
results[n++] = u3 & 0xFF;
|
|
505
512
|
} else if (b === 0x8F) {
|
|
506
513
|
j2 = data[++i] - 0x80;
|
|
507
514
|
j3 = data[++i] - 0x80;
|
|
508
515
|
jis = (j2 << 8) + j3;
|
|
509
516
|
|
|
510
517
|
utf8 = EncodingTable.JISX0212_TO_UTF8_TABLE[jis];
|
|
511
|
-
if (utf8
|
|
512
|
-
results[
|
|
518
|
+
if (!utf8) {
|
|
519
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
513
520
|
} else {
|
|
514
|
-
if (utf8 <
|
|
515
|
-
results[
|
|
516
|
-
|
|
521
|
+
if (utf8 < 0x80) {
|
|
522
|
+
results[n++] = utf8;
|
|
523
|
+
} else if (utf8 < 0xFFFF) {
|
|
524
|
+
results[n++] = utf8 >> 8 & 0xFF;
|
|
525
|
+
results[n++] = utf8 & 0xFF;
|
|
517
526
|
} else {
|
|
518
|
-
results[
|
|
519
|
-
results[
|
|
520
|
-
results[
|
|
527
|
+
results[n++] = utf8 >> 16 & 0xFF;
|
|
528
|
+
results[n++] = utf8 >> 8 & 0xFF;
|
|
529
|
+
results[n++] = utf8 & 0xFF;
|
|
521
530
|
}
|
|
522
531
|
}
|
|
523
532
|
} else if (b >= 0x80) {
|
|
524
533
|
jis = ((b - 0x80) << 8) + (data[++i] - 0x80);
|
|
525
534
|
|
|
526
535
|
utf8 = EncodingTable.JIS_TO_UTF8_TABLE[jis];
|
|
527
|
-
if (utf8
|
|
528
|
-
results[
|
|
536
|
+
if (!utf8) {
|
|
537
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
529
538
|
} else {
|
|
530
539
|
if (utf8 < 0xFFFF) {
|
|
531
|
-
results[
|
|
532
|
-
results[
|
|
540
|
+
results[n++] = utf8 >> 8 & 0xFF;
|
|
541
|
+
results[n++] = utf8 & 0xFF;
|
|
533
542
|
} else {
|
|
534
|
-
results[
|
|
535
|
-
results[
|
|
536
|
-
results[
|
|
543
|
+
results[n++] = utf8 >> 16 & 0xFF;
|
|
544
|
+
results[n++] = utf8 >> 8 & 0xFF;
|
|
545
|
+
results[n++] = utf8 & 0xFF;
|
|
537
546
|
}
|
|
538
547
|
}
|
|
539
548
|
} else {
|
|
540
|
-
results[
|
|
549
|
+
results[n++] = data[i] & 0xFF;
|
|
541
550
|
}
|
|
542
551
|
}
|
|
543
552
|
|
|
544
|
-
return results;
|
|
553
|
+
return util.truncateBuffer(results, n);
|
|
545
554
|
}
|
|
546
555
|
exports.EUCJPToUTF8 = EUCJPToUTF8;
|
|
547
556
|
|
|
@@ -549,13 +558,14 @@ exports.EUCJPToUTF8 = EUCJPToUTF8;
|
|
|
549
558
|
* JIS to UTF-8
|
|
550
559
|
*/
|
|
551
560
|
function JISToUTF8(data) {
|
|
552
|
-
|
|
561
|
+
EncodingTable.initConversionTables();
|
|
553
562
|
|
|
554
|
-
var results = [];
|
|
555
563
|
var index = 0;
|
|
556
564
|
var i = 0;
|
|
557
565
|
var len = data && data.length;
|
|
558
566
|
var b2, u2, u3, jis, utf8;
|
|
567
|
+
var results = createBuffer(8, len * 3);
|
|
568
|
+
var n = 0;
|
|
559
569
|
|
|
560
570
|
for (; i < len; i++) {
|
|
561
571
|
while (data[i] === 0x1B) {
|
|
@@ -574,7 +584,7 @@ function JISToUTF8(data) {
|
|
|
574
584
|
|
|
575
585
|
i += 3;
|
|
576
586
|
if (data[i] === void 0) {
|
|
577
|
-
return results;
|
|
587
|
+
return util.truncateBuffer(results, n);
|
|
578
588
|
}
|
|
579
589
|
}
|
|
580
590
|
|
|
@@ -582,16 +592,16 @@ function JISToUTF8(data) {
|
|
|
582
592
|
jis = (data[i] << 8) + data[++i];
|
|
583
593
|
|
|
584
594
|
utf8 = EncodingTable.JIS_TO_UTF8_TABLE[jis];
|
|
585
|
-
if (utf8
|
|
586
|
-
results[
|
|
595
|
+
if (!utf8) {
|
|
596
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
587
597
|
} else {
|
|
588
598
|
if (utf8 < 0xFFFF) {
|
|
589
|
-
results[
|
|
590
|
-
results[
|
|
599
|
+
results[n++] = utf8 >> 8 & 0xFF;
|
|
600
|
+
results[n++] = utf8 & 0xFF;
|
|
591
601
|
} else {
|
|
592
|
-
results[
|
|
593
|
-
results[
|
|
594
|
-
results[
|
|
602
|
+
results[n++] = utf8 >> 16 & 0xFF;
|
|
603
|
+
results[n++] = utf8 >> 8 & 0xFF;
|
|
604
|
+
results[n++] = utf8 & 0xFF;
|
|
595
605
|
}
|
|
596
606
|
}
|
|
597
607
|
} else if (index === 2) {
|
|
@@ -599,31 +609,33 @@ function JISToUTF8(data) {
|
|
|
599
609
|
u2 = 0xBC | ((b2 >> 6) & 0x03);
|
|
600
610
|
u3 = 0x80 | (b2 & 0x3F);
|
|
601
611
|
|
|
602
|
-
results[
|
|
603
|
-
results[
|
|
604
|
-
results[
|
|
612
|
+
results[n++] = 0xEF;
|
|
613
|
+
results[n++] = u2 & 0xFF;
|
|
614
|
+
results[n++] = u3 & 0xFF;
|
|
605
615
|
} else if (index === 3) {
|
|
606
616
|
jis = (data[i] << 8) + data[++i];
|
|
607
617
|
|
|
608
618
|
utf8 = EncodingTable.JISX0212_TO_UTF8_TABLE[jis];
|
|
609
|
-
if (utf8
|
|
610
|
-
results[
|
|
619
|
+
if (!utf8) {
|
|
620
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
611
621
|
} else {
|
|
612
|
-
if (utf8 <
|
|
613
|
-
results[
|
|
614
|
-
|
|
622
|
+
if (utf8 < 0x80) {
|
|
623
|
+
results[n++] = utf8;
|
|
624
|
+
} else if (utf8 < 0xFFFF) {
|
|
625
|
+
results[n++] = utf8 >> 8 & 0xFF;
|
|
626
|
+
results[n++] = utf8 & 0xFF;
|
|
615
627
|
} else {
|
|
616
|
-
results[
|
|
617
|
-
results[
|
|
618
|
-
results[
|
|
628
|
+
results[n++] = utf8 >> 16 & 0xFF;
|
|
629
|
+
results[n++] = utf8 >> 8 & 0xFF;
|
|
630
|
+
results[n++] = utf8 & 0xFF;
|
|
619
631
|
}
|
|
620
632
|
}
|
|
621
633
|
} else {
|
|
622
|
-
results[
|
|
634
|
+
results[n++] = data[i] & 0xFF;
|
|
623
635
|
}
|
|
624
636
|
}
|
|
625
637
|
|
|
626
|
-
return results;
|
|
638
|
+
return util.truncateBuffer(results, n);
|
|
627
639
|
}
|
|
628
640
|
exports.JISToUTF8 = JISToUTF8;
|
|
629
641
|
|
|
@@ -631,11 +643,14 @@ exports.JISToUTF8 = JISToUTF8;
|
|
|
631
643
|
* UTF-8 to SJIS
|
|
632
644
|
*/
|
|
633
645
|
function UTF8ToSJIS(data, options) {
|
|
634
|
-
|
|
646
|
+
EncodingTable.initConversionTables();
|
|
647
|
+
|
|
635
648
|
var i = 0;
|
|
636
649
|
var len = data && data.length;
|
|
637
650
|
var b, b1, b2, bytes, utf8, jis;
|
|
638
651
|
var fallbackOption = options && options.fallback;
|
|
652
|
+
var results = createBuffer(8, len, fallbackOption);
|
|
653
|
+
var n = 0;
|
|
639
654
|
|
|
640
655
|
for (; i < len; i++) {
|
|
641
656
|
b = data[i];
|
|
@@ -664,13 +679,13 @@ function UTF8ToSJIS(data, options) {
|
|
|
664
679
|
EncodingTable.UTF8_TO_JIS_ALIAS_TABLE[utf8];
|
|
665
680
|
if (jis == null) {
|
|
666
681
|
if (fallbackOption) {
|
|
667
|
-
handleFallback(results, bytes, fallbackOption);
|
|
682
|
+
n = handleFallback(results, n, bytes, fallbackOption);
|
|
668
683
|
} else {
|
|
669
|
-
results[
|
|
684
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
670
685
|
}
|
|
671
686
|
} else {
|
|
672
687
|
if (jis < 0xFF) {
|
|
673
|
-
results[
|
|
688
|
+
results[n++] = jis + 0x80;
|
|
674
689
|
} else {
|
|
675
690
|
b1 = jis >> 8;
|
|
676
691
|
b2 = jis & 0xFF;
|
|
@@ -696,16 +711,16 @@ function UTF8ToSJIS(data, options) {
|
|
|
696
711
|
}
|
|
697
712
|
b2 += 0x7E;
|
|
698
713
|
}
|
|
699
|
-
results[
|
|
700
|
-
results[
|
|
714
|
+
results[n++] = b1 & 0xFF;
|
|
715
|
+
results[n++] = b2 & 0xFF;
|
|
701
716
|
}
|
|
702
717
|
}
|
|
703
718
|
} else {
|
|
704
|
-
results[
|
|
719
|
+
results[n++] = data[i] & 0xFF;
|
|
705
720
|
}
|
|
706
721
|
}
|
|
707
722
|
|
|
708
|
-
return results;
|
|
723
|
+
return util.truncateBuffer(results, n);
|
|
709
724
|
}
|
|
710
725
|
exports.UTF8ToSJIS = UTF8ToSJIS;
|
|
711
726
|
|
|
@@ -713,11 +728,14 @@ exports.UTF8ToSJIS = UTF8ToSJIS;
|
|
|
713
728
|
* UTF-8 to EUC-JP
|
|
714
729
|
*/
|
|
715
730
|
function UTF8ToEUCJP(data, options) {
|
|
716
|
-
|
|
731
|
+
EncodingTable.initConversionTables();
|
|
732
|
+
|
|
717
733
|
var i = 0;
|
|
718
734
|
var len = data && data.length;
|
|
719
735
|
var b, bytes, utf8, jis, isJISX0212;
|
|
720
736
|
var fallbackOption = options && options.fallback;
|
|
737
|
+
var results = createBuffer(8, len * 2, fallbackOption);
|
|
738
|
+
var n = 0;
|
|
721
739
|
|
|
722
740
|
for (; i < len; i++) {
|
|
723
741
|
b = data[i];
|
|
@@ -751,28 +769,28 @@ function UTF8ToEUCJP(data, options) {
|
|
|
751
769
|
}
|
|
752
770
|
if (jis == null) {
|
|
753
771
|
if (fallbackOption) {
|
|
754
|
-
handleFallback(results, bytes, fallbackOption);
|
|
772
|
+
n = handleFallback(results, n, bytes, fallbackOption);
|
|
755
773
|
} else {
|
|
756
|
-
results[
|
|
774
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
757
775
|
}
|
|
758
776
|
} else {
|
|
759
777
|
if (jis < 0xFF) {
|
|
760
|
-
results[
|
|
761
|
-
results[
|
|
778
|
+
results[n++] = 0x8E;
|
|
779
|
+
results[n++] = jis - 0x80 & 0xFF;
|
|
762
780
|
} else {
|
|
763
781
|
if (isJISX0212) {
|
|
764
|
-
results[
|
|
782
|
+
results[n++] = 0x8F;
|
|
765
783
|
}
|
|
766
|
-
results[
|
|
767
|
-
results[
|
|
784
|
+
results[n++] = (jis >> 8) - 0x80 & 0xFF;
|
|
785
|
+
results[n++] = (jis & 0xFF) - 0x80 & 0xFF;
|
|
768
786
|
}
|
|
769
787
|
}
|
|
770
788
|
} else {
|
|
771
|
-
results[
|
|
789
|
+
results[n++] = data[i] & 0xFF;
|
|
772
790
|
}
|
|
773
791
|
}
|
|
774
792
|
|
|
775
|
-
return results;
|
|
793
|
+
return util.truncateBuffer(results, n);
|
|
776
794
|
}
|
|
777
795
|
exports.UTF8ToEUCJP = UTF8ToEUCJP;
|
|
778
796
|
|
|
@@ -780,12 +798,15 @@ exports.UTF8ToEUCJP = UTF8ToEUCJP;
|
|
|
780
798
|
* UTF-8 to JIS
|
|
781
799
|
*/
|
|
782
800
|
function UTF8ToJIS(data, options) {
|
|
783
|
-
|
|
801
|
+
EncodingTable.initConversionTables();
|
|
802
|
+
|
|
784
803
|
var index = 0;
|
|
785
804
|
var len = data && data.length;
|
|
786
805
|
var i = 0;
|
|
787
806
|
var b, bytes, utf8, jis, isJISX0212;
|
|
788
807
|
var fallbackOption = options && options.fallback;
|
|
808
|
+
var results = createBuffer(8, len * 4 + 3, fallbackOption);
|
|
809
|
+
var n = 0;
|
|
789
810
|
|
|
790
811
|
var esc = [
|
|
791
812
|
0x1B, 0x28, 0x42,
|
|
@@ -799,11 +820,11 @@ function UTF8ToJIS(data, options) {
|
|
|
799
820
|
if (b < 0x80) {
|
|
800
821
|
if (index !== 0) {
|
|
801
822
|
index = 0;
|
|
802
|
-
results[
|
|
803
|
-
results[
|
|
804
|
-
results[
|
|
823
|
+
results[n++] = esc[0];
|
|
824
|
+
results[n++] = esc[1];
|
|
825
|
+
results[n++] = esc[2];
|
|
805
826
|
}
|
|
806
|
-
results[
|
|
827
|
+
results[n++] = b & 0xFF;
|
|
807
828
|
} else {
|
|
808
829
|
if (b <= 0xDF) {
|
|
809
830
|
// 2 bytes
|
|
@@ -836,57 +857,57 @@ function UTF8ToJIS(data, options) {
|
|
|
836
857
|
if (jis == null) {
|
|
837
858
|
if (index !== 0) {
|
|
838
859
|
index = 0;
|
|
839
|
-
results[
|
|
840
|
-
results[
|
|
841
|
-
results[
|
|
860
|
+
results[n++] = esc[0];
|
|
861
|
+
results[n++] = esc[1];
|
|
862
|
+
results[n++] = esc[2];
|
|
842
863
|
}
|
|
843
864
|
|
|
844
865
|
if (fallbackOption) {
|
|
845
|
-
handleFallback(results, bytes, fallbackOption);
|
|
866
|
+
n = handleFallback(results, n, bytes, fallbackOption);
|
|
846
867
|
} else {
|
|
847
|
-
results[
|
|
868
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
848
869
|
}
|
|
849
870
|
} else {
|
|
850
871
|
if (jis < 0xFF) {
|
|
851
872
|
// Halfwidth Katakana
|
|
852
873
|
if (index !== 2) {
|
|
853
874
|
index = 2;
|
|
854
|
-
results[
|
|
855
|
-
results[
|
|
856
|
-
results[
|
|
875
|
+
results[n++] = esc[6];
|
|
876
|
+
results[n++] = esc[7];
|
|
877
|
+
results[n++] = esc[8];
|
|
857
878
|
}
|
|
858
|
-
results[
|
|
879
|
+
results[n++] = jis & 0xFF;
|
|
859
880
|
} else {
|
|
860
881
|
if (isJISX0212) {
|
|
861
882
|
// JIS X 0212:1990
|
|
862
883
|
if (index !== 3) {
|
|
863
884
|
index = 3;
|
|
864
|
-
results[
|
|
865
|
-
results[
|
|
866
|
-
results[
|
|
867
|
-
results[
|
|
885
|
+
results[n++] = esc[9];
|
|
886
|
+
results[n++] = esc[10];
|
|
887
|
+
results[n++] = esc[11];
|
|
888
|
+
results[n++] = esc[12];
|
|
868
889
|
}
|
|
869
890
|
} else if (index !== 1) {
|
|
870
891
|
// JIS X 0208
|
|
871
892
|
index = 1;
|
|
872
|
-
results[
|
|
873
|
-
results[
|
|
874
|
-
results[
|
|
893
|
+
results[n++] = esc[3];
|
|
894
|
+
results[n++] = esc[4];
|
|
895
|
+
results[n++] = esc[5];
|
|
875
896
|
}
|
|
876
|
-
results[
|
|
877
|
-
results[
|
|
897
|
+
results[n++] = jis >> 8 & 0xFF;
|
|
898
|
+
results[n++] = jis & 0xFF;
|
|
878
899
|
}
|
|
879
900
|
}
|
|
880
901
|
}
|
|
881
902
|
}
|
|
882
903
|
|
|
883
904
|
if (index !== 0) {
|
|
884
|
-
results[
|
|
885
|
-
results[
|
|
886
|
-
results[
|
|
905
|
+
results[n++] = esc[0];
|
|
906
|
+
results[n++] = esc[1];
|
|
907
|
+
results[n++] = esc[2];
|
|
887
908
|
}
|
|
888
909
|
|
|
889
|
-
return results;
|
|
910
|
+
return util.truncateBuffer(results, n);
|
|
890
911
|
}
|
|
891
912
|
exports.UTF8ToJIS = UTF8ToJIS;
|
|
892
913
|
|
|
@@ -894,10 +915,11 @@ exports.UTF8ToJIS = UTF8ToJIS;
|
|
|
894
915
|
* UTF-16 (JavaScript Unicode array) to UTF-8
|
|
895
916
|
*/
|
|
896
917
|
function UNICODEToUTF8(data) {
|
|
897
|
-
var results = [];
|
|
898
918
|
var i = 0;
|
|
899
919
|
var len = data && data.length;
|
|
900
920
|
var c, second;
|
|
921
|
+
var results = createBuffer(8, len * 4);
|
|
922
|
+
var n = 0;
|
|
901
923
|
|
|
902
924
|
for (; i < len; i++) {
|
|
903
925
|
c = data[i];
|
|
@@ -913,23 +935,25 @@ function UNICODEToUTF8(data) {
|
|
|
913
935
|
}
|
|
914
936
|
|
|
915
937
|
if (c < 0x80) {
|
|
916
|
-
results[
|
|
938
|
+
results[n++] = c;
|
|
917
939
|
} else if (c < 0x800) {
|
|
918
|
-
results[
|
|
919
|
-
results[
|
|
940
|
+
results[n++] = 0xC0 | (c >> 6);
|
|
941
|
+
results[n++] = 0x80 | (c & 0x3F);
|
|
920
942
|
} else if (c < 0x10000) {
|
|
921
|
-
results[
|
|
922
|
-
results[
|
|
923
|
-
results[
|
|
924
|
-
} else if (c <
|
|
925
|
-
results[
|
|
926
|
-
results[
|
|
927
|
-
results[
|
|
928
|
-
results[
|
|
943
|
+
results[n++] = 0xE0 | (c >> 12);
|
|
944
|
+
results[n++] = 0x80 | ((c >> 6) & 0x3F);
|
|
945
|
+
results[n++] = 0x80 | (c & 0x3F);
|
|
946
|
+
} else if (c < 0x110000) {
|
|
947
|
+
results[n++] = 0xF0 | (c >> 18);
|
|
948
|
+
results[n++] = 0x80 | ((c >> 12) & 0x3F);
|
|
949
|
+
results[n++] = 0x80 | ((c >> 6) & 0x3F);
|
|
950
|
+
results[n++] = 0x80 | (c & 0x3F);
|
|
951
|
+
} else {
|
|
952
|
+
results[n++] = config.FALLBACK_CHARACTER;
|
|
929
953
|
}
|
|
930
954
|
}
|
|
931
955
|
|
|
932
|
-
return results;
|
|
956
|
+
return util.truncateBuffer(results, n);
|
|
933
957
|
}
|
|
934
958
|
exports.UNICODEToUTF8 = UNICODEToUTF8;
|
|
935
959
|
|
|
@@ -937,26 +961,27 @@ exports.UNICODEToUTF8 = UNICODEToUTF8;
|
|
|
937
961
|
* UTF-8 to UTF-16 (JavaScript Unicode array)
|
|
938
962
|
*/
|
|
939
963
|
function UTF8ToUNICODE(data, options) {
|
|
940
|
-
var results = [];
|
|
941
964
|
var i = 0;
|
|
942
965
|
var len = data && data.length;
|
|
943
|
-
var
|
|
966
|
+
var nibble, c, c2, c3, c4, code;
|
|
944
967
|
// For internal use only
|
|
945
968
|
// Returns raw Unicode code points without splitting into surrogate pairs
|
|
946
969
|
var asCodePoint = options && options.asCodePoint;
|
|
970
|
+
var results = asCodePoint ? [] : createBuffer(16, len * 2);
|
|
971
|
+
var n = 0;
|
|
947
972
|
|
|
948
973
|
while (i < len) {
|
|
949
974
|
c = data[i++];
|
|
950
|
-
|
|
951
|
-
if (
|
|
975
|
+
nibble = c >> 4;
|
|
976
|
+
if (nibble >= 0 && nibble <= 7) {
|
|
952
977
|
// 0xxx xxxx
|
|
953
978
|
code = c;
|
|
954
|
-
} else if (
|
|
979
|
+
} else if (nibble === 12 || nibble === 13) {
|
|
955
980
|
// 110x xxxx
|
|
956
981
|
// 10xx xxxx
|
|
957
982
|
c2 = data[i++];
|
|
958
983
|
code = ((c & 0x1F) << 6) | (c2 & 0x3F);
|
|
959
|
-
} else if (
|
|
984
|
+
} else if (nibble === 14) {
|
|
960
985
|
// 1110 xxxx
|
|
961
986
|
// 10xx xxxx
|
|
962
987
|
// 10xx xxxx
|
|
@@ -965,7 +990,7 @@ function UTF8ToUNICODE(data, options) {
|
|
|
965
990
|
code = ((c & 0x0F) << 12) |
|
|
966
991
|
((c2 & 0x3F) << 6) |
|
|
967
992
|
(c3 & 0x3F);
|
|
968
|
-
} else if (
|
|
993
|
+
} else if (nibble === 15) {
|
|
969
994
|
// 1111 0xxx
|
|
970
995
|
// 10xx xxxx
|
|
971
996
|
// 10xx xxxx
|
|
@@ -977,19 +1002,22 @@ function UTF8ToUNICODE(data, options) {
|
|
|
977
1002
|
((c2 & 0x3F) << 12) |
|
|
978
1003
|
((c3 & 0x3F) << 6) |
|
|
979
1004
|
(c4 & 0x3F);
|
|
1005
|
+
} else {
|
|
1006
|
+
// 10xx xxxx: Ignore a continuation byte without a lead byte
|
|
1007
|
+
continue;
|
|
980
1008
|
}
|
|
981
1009
|
|
|
982
1010
|
if (code <= 0xFFFF || asCodePoint) {
|
|
983
|
-
results[
|
|
1011
|
+
results[n++] = code;
|
|
984
1012
|
} else {
|
|
985
1013
|
// Split in surrogate halves
|
|
986
1014
|
code -= 0x10000;
|
|
987
|
-
results[
|
|
988
|
-
results[
|
|
1015
|
+
results[n++] = (code >> 10) + 0xD800; // High surrogate
|
|
1016
|
+
results[n++] = (code % 0x400) + 0xDC00; // Low surrogate
|
|
989
1017
|
}
|
|
990
1018
|
}
|
|
991
1019
|
|
|
992
|
-
return results;
|
|
1020
|
+
return util.truncateBuffer(results, n);
|
|
993
1021
|
}
|
|
994
1022
|
exports.UTF8ToUNICODE = UTF8ToUNICODE;
|
|
995
1023
|
|
|
@@ -1027,12 +1055,14 @@ function UNICODEToUTF16(data, options) {
|
|
|
1027
1055
|
utf16 = UNICODEToUTF16LE(data);
|
|
1028
1056
|
}
|
|
1029
1057
|
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
results
|
|
1058
|
+
var len = utf16.length;
|
|
1059
|
+
var n = 0;
|
|
1060
|
+
results = createBuffer(8, len + 2);
|
|
1061
|
+
results[n++] = bom[0];
|
|
1062
|
+
results[n++] = bom[1];
|
|
1033
1063
|
|
|
1034
|
-
for (var i = 0
|
|
1035
|
-
results[
|
|
1064
|
+
for (var i = 0; i < len; i++) {
|
|
1065
|
+
results[n++] = utf16[i];
|
|
1036
1066
|
}
|
|
1037
1067
|
} else {
|
|
1038
1068
|
// Should be interpreted as being big-endian when text has no BOM
|
|
@@ -1050,23 +1080,24 @@ exports.UNICODEToUTF16 = UNICODEToUTF16;
|
|
|
1050
1080
|
* UTF-16, an encoding of ISO 10646
|
|
1051
1081
|
*/
|
|
1052
1082
|
function UNICODEToUTF16BE(data) {
|
|
1053
|
-
var results = [];
|
|
1054
1083
|
var i = 0;
|
|
1055
1084
|
var len = data && data.length;
|
|
1056
1085
|
var c;
|
|
1086
|
+
var results = createBuffer(8, len * 2);
|
|
1087
|
+
var n = 0;
|
|
1057
1088
|
|
|
1058
1089
|
while (i < len) {
|
|
1059
1090
|
c = data[i++];
|
|
1060
1091
|
if (c <= 0xFF) {
|
|
1061
|
-
results[
|
|
1062
|
-
results[
|
|
1092
|
+
results[n++] = 0;
|
|
1093
|
+
results[n++] = c;
|
|
1063
1094
|
} else if (c <= 0xFFFF) {
|
|
1064
|
-
results[
|
|
1065
|
-
results[
|
|
1095
|
+
results[n++] = c >> 8 & 0xFF;
|
|
1096
|
+
results[n++] = c & 0xFF;
|
|
1066
1097
|
}
|
|
1067
1098
|
}
|
|
1068
1099
|
|
|
1069
|
-
return results;
|
|
1100
|
+
return util.truncateBuffer(results, n);
|
|
1070
1101
|
}
|
|
1071
1102
|
exports.UNICODEToUTF16BE = UNICODEToUTF16BE;
|
|
1072
1103
|
|
|
@@ -1077,23 +1108,24 @@ exports.UNICODEToUTF16BE = UNICODEToUTF16BE;
|
|
|
1077
1108
|
* UTF-16, an encoding of ISO 10646
|
|
1078
1109
|
*/
|
|
1079
1110
|
function UNICODEToUTF16LE(data) {
|
|
1080
|
-
var results = [];
|
|
1081
1111
|
var i = 0;
|
|
1082
1112
|
var len = data && data.length;
|
|
1083
1113
|
var c;
|
|
1114
|
+
var results = createBuffer(8, len * 2);
|
|
1115
|
+
var n = 0;
|
|
1084
1116
|
|
|
1085
1117
|
while (i < len) {
|
|
1086
1118
|
c = data[i++];
|
|
1087
1119
|
if (c <= 0xFF) {
|
|
1088
|
-
results[
|
|
1089
|
-
results[
|
|
1120
|
+
results[n++] = c;
|
|
1121
|
+
results[n++] = 0;
|
|
1090
1122
|
} else if (c <= 0xFFFF) {
|
|
1091
|
-
results[
|
|
1092
|
-
results[
|
|
1123
|
+
results[n++] = c & 0xFF;
|
|
1124
|
+
results[n++] = c >> 8 & 0xFF;
|
|
1093
1125
|
}
|
|
1094
1126
|
}
|
|
1095
1127
|
|
|
1096
|
-
return results;
|
|
1128
|
+
return util.truncateBuffer(results, n);
|
|
1097
1129
|
}
|
|
1098
1130
|
exports.UNICODEToUTF16LE = UNICODEToUTF16LE;
|
|
1099
1131
|
|
|
@@ -1104,10 +1136,11 @@ exports.UNICODEToUTF16LE = UNICODEToUTF16LE;
|
|
|
1104
1136
|
* UTF-16, an encoding of ISO 10646
|
|
1105
1137
|
*/
|
|
1106
1138
|
function UTF16BEToUNICODE(data) {
|
|
1107
|
-
var results = [];
|
|
1108
1139
|
var i = 0;
|
|
1109
1140
|
var len = data && data.length;
|
|
1110
1141
|
var c1, c2;
|
|
1142
|
+
var results = createBuffer(16, len);
|
|
1143
|
+
var n = 0;
|
|
1111
1144
|
|
|
1112
1145
|
if (len >= 2 &&
|
|
1113
1146
|
((data[0] === 0xFE && data[1] === 0xFF) ||
|
|
@@ -1120,13 +1153,13 @@ function UTF16BEToUNICODE(data) {
|
|
|
1120
1153
|
c1 = data[i++];
|
|
1121
1154
|
c2 = data[i++];
|
|
1122
1155
|
if (c1 === 0) {
|
|
1123
|
-
results[
|
|
1156
|
+
results[n++] = c2;
|
|
1124
1157
|
} else {
|
|
1125
|
-
results[
|
|
1158
|
+
results[n++] = ((c1 & 0xFF) << 8) | (c2 & 0xFF);
|
|
1126
1159
|
}
|
|
1127
1160
|
}
|
|
1128
1161
|
|
|
1129
|
-
return results;
|
|
1162
|
+
return util.truncateBuffer(results, n);
|
|
1130
1163
|
}
|
|
1131
1164
|
exports.UTF16BEToUNICODE = UTF16BEToUNICODE;
|
|
1132
1165
|
|
|
@@ -1137,10 +1170,11 @@ exports.UTF16BEToUNICODE = UTF16BEToUNICODE;
|
|
|
1137
1170
|
* UTF-16, an encoding of ISO 10646
|
|
1138
1171
|
*/
|
|
1139
1172
|
function UTF16LEToUNICODE(data) {
|
|
1140
|
-
var results = [];
|
|
1141
1173
|
var i = 0;
|
|
1142
1174
|
var len = data && data.length;
|
|
1143
1175
|
var c1, c2;
|
|
1176
|
+
var results = createBuffer(16, len);
|
|
1177
|
+
var n = 0;
|
|
1144
1178
|
|
|
1145
1179
|
if (len >= 2 &&
|
|
1146
1180
|
((data[0] === 0xFE && data[1] === 0xFF) ||
|
|
@@ -1153,13 +1187,13 @@ function UTF16LEToUNICODE(data) {
|
|
|
1153
1187
|
c1 = data[i++];
|
|
1154
1188
|
c2 = data[i++];
|
|
1155
1189
|
if (c2 === 0) {
|
|
1156
|
-
results[
|
|
1190
|
+
results[n++] = c1;
|
|
1157
1191
|
} else {
|
|
1158
|
-
results[
|
|
1192
|
+
results[n++] = ((c2 & 0xFF) << 8) | (c1 & 0xFF);
|
|
1159
1193
|
}
|
|
1160
1194
|
}
|
|
1161
1195
|
|
|
1162
|
-
return results;
|
|
1196
|
+
return util.truncateBuffer(results, n);
|
|
1163
1197
|
}
|
|
1164
1198
|
exports.UTF16LEToUNICODE = UTF16LEToUNICODE;
|
|
1165
1199
|
|
|
@@ -1170,12 +1204,13 @@ exports.UTF16LEToUNICODE = UTF16LEToUNICODE;
|
|
|
1170
1204
|
* UTF-16, an encoding of ISO 10646
|
|
1171
1205
|
*/
|
|
1172
1206
|
function UTF16ToUNICODE(data) {
|
|
1173
|
-
var results = [];
|
|
1174
1207
|
var i = 0;
|
|
1175
1208
|
var len = data && data.length;
|
|
1176
1209
|
var isLE = false;
|
|
1177
1210
|
var first = true;
|
|
1178
1211
|
var c1, c2;
|
|
1212
|
+
var results = createBuffer(16, len);
|
|
1213
|
+
var n = 0;
|
|
1179
1214
|
|
|
1180
1215
|
while (i < len) {
|
|
1181
1216
|
c1 = data[i++];
|
|
@@ -1197,20 +1232,20 @@ function UTF16ToUNICODE(data) {
|
|
|
1197
1232
|
|
|
1198
1233
|
if (isLE) {
|
|
1199
1234
|
if (c2 === 0) {
|
|
1200
|
-
results[
|
|
1235
|
+
results[n++] = c1;
|
|
1201
1236
|
} else {
|
|
1202
|
-
results[
|
|
1237
|
+
results[n++] = ((c2 & 0xFF) << 8) | (c1 & 0xFF);
|
|
1203
1238
|
}
|
|
1204
1239
|
} else {
|
|
1205
1240
|
if (c1 === 0) {
|
|
1206
|
-
results[
|
|
1241
|
+
results[n++] = c2;
|
|
1207
1242
|
} else {
|
|
1208
|
-
results[
|
|
1243
|
+
results[n++] = ((c1 & 0xFF) << 8) | (c2 & 0xFF);
|
|
1209
1244
|
}
|
|
1210
1245
|
}
|
|
1211
1246
|
}
|
|
1212
1247
|
|
|
1213
|
-
return results;
|
|
1248
|
+
return util.truncateBuffer(results, n);
|
|
1214
1249
|
}
|
|
1215
1250
|
exports.UTF16ToUNICODE = UTF16ToUNICODE;
|
|
1216
1251
|
|
|
@@ -1218,12 +1253,13 @@ exports.UTF16ToUNICODE = UTF16ToUNICODE;
|
|
|
1218
1253
|
* UTF-16 to UTF-16BE
|
|
1219
1254
|
*/
|
|
1220
1255
|
function UTF16ToUTF16BE(data) {
|
|
1221
|
-
var results = [];
|
|
1222
1256
|
var i = 0;
|
|
1223
1257
|
var len = data && data.length;
|
|
1224
1258
|
var isLE = false;
|
|
1225
1259
|
var first = true;
|
|
1226
1260
|
var c1, c2;
|
|
1261
|
+
var results = createBuffer(8, len);
|
|
1262
|
+
var n = 0;
|
|
1227
1263
|
|
|
1228
1264
|
while (i < len) {
|
|
1229
1265
|
c1 = data[i++];
|
|
@@ -1244,15 +1280,15 @@ function UTF16ToUTF16BE(data) {
|
|
|
1244
1280
|
}
|
|
1245
1281
|
|
|
1246
1282
|
if (isLE) {
|
|
1247
|
-
results[
|
|
1248
|
-
results[
|
|
1283
|
+
results[n++] = c2;
|
|
1284
|
+
results[n++] = c1;
|
|
1249
1285
|
} else {
|
|
1250
|
-
results[
|
|
1251
|
-
results[
|
|
1286
|
+
results[n++] = c1;
|
|
1287
|
+
results[n++] = c2;
|
|
1252
1288
|
}
|
|
1253
1289
|
}
|
|
1254
1290
|
|
|
1255
|
-
return results;
|
|
1291
|
+
return util.truncateBuffer(results, n);
|
|
1256
1292
|
}
|
|
1257
1293
|
exports.UTF16ToUTF16BE = UTF16ToUTF16BE;
|
|
1258
1294
|
|
|
@@ -1279,9 +1315,10 @@ function UTF16BEToUTF16(data, options) {
|
|
|
1279
1315
|
}
|
|
1280
1316
|
}
|
|
1281
1317
|
|
|
1282
|
-
var results = [];
|
|
1283
1318
|
var len = data && data.length;
|
|
1284
1319
|
var i = 0;
|
|
1320
|
+
var results = createBuffer(8, len + 2);
|
|
1321
|
+
var n = 0;
|
|
1285
1322
|
|
|
1286
1323
|
if (len >= 2 &&
|
|
1287
1324
|
((data[0] === 0xFE && data[1] === 0xFF) ||
|
|
@@ -1291,8 +1328,8 @@ function UTF16BEToUTF16(data, options) {
|
|
|
1291
1328
|
}
|
|
1292
1329
|
|
|
1293
1330
|
if (bom) {
|
|
1294
|
-
results[
|
|
1295
|
-
results[
|
|
1331
|
+
results[n++] = bom[0];
|
|
1332
|
+
results[n++] = bom[1];
|
|
1296
1333
|
}
|
|
1297
1334
|
|
|
1298
1335
|
var c1, c2;
|
|
@@ -1301,15 +1338,15 @@ function UTF16BEToUTF16(data, options) {
|
|
|
1301
1338
|
c2 = data[i++];
|
|
1302
1339
|
|
|
1303
1340
|
if (isLE) {
|
|
1304
|
-
results[
|
|
1305
|
-
results[
|
|
1341
|
+
results[n++] = c2;
|
|
1342
|
+
results[n++] = c1;
|
|
1306
1343
|
} else {
|
|
1307
|
-
results[
|
|
1308
|
-
results[
|
|
1344
|
+
results[n++] = c1;
|
|
1345
|
+
results[n++] = c2;
|
|
1309
1346
|
}
|
|
1310
1347
|
}
|
|
1311
1348
|
|
|
1312
|
-
return results;
|
|
1349
|
+
return util.truncateBuffer(results, n);
|
|
1313
1350
|
}
|
|
1314
1351
|
exports.UTF16BEToUTF16 = UTF16BEToUTF16;
|
|
1315
1352
|
|
|
@@ -1317,13 +1354,15 @@ exports.UTF16BEToUTF16 = UTF16BEToUTF16;
|
|
|
1317
1354
|
* UTF-16 to UTF-16LE
|
|
1318
1355
|
*/
|
|
1319
1356
|
function UTF16ToUTF16LE(data) {
|
|
1320
|
-
var results = [];
|
|
1321
1357
|
var i = 0;
|
|
1322
1358
|
var len = data && data.length;
|
|
1323
1359
|
var isLE = false;
|
|
1324
1360
|
var first = true;
|
|
1325
1361
|
var c1, c2;
|
|
1326
1362
|
|
|
1363
|
+
var results = createBuffer(8, len);
|
|
1364
|
+
var n = 0;
|
|
1365
|
+
|
|
1327
1366
|
while (i < len) {
|
|
1328
1367
|
c1 = data[i++];
|
|
1329
1368
|
c2 = data[i++];
|
|
@@ -1343,15 +1382,15 @@ function UTF16ToUTF16LE(data) {
|
|
|
1343
1382
|
}
|
|
1344
1383
|
|
|
1345
1384
|
if (isLE) {
|
|
1346
|
-
results[
|
|
1347
|
-
results[
|
|
1385
|
+
results[n++] = c1;
|
|
1386
|
+
results[n++] = c2;
|
|
1348
1387
|
} else {
|
|
1349
|
-
results[
|
|
1350
|
-
results[
|
|
1388
|
+
results[n++] = c2;
|
|
1389
|
+
results[n++] = c1;
|
|
1351
1390
|
}
|
|
1352
1391
|
}
|
|
1353
1392
|
|
|
1354
|
-
return results;
|
|
1393
|
+
return util.truncateBuffer(results, n);
|
|
1355
1394
|
}
|
|
1356
1395
|
exports.UTF16ToUTF16LE = UTF16ToUTF16LE;
|
|
1357
1396
|
|
|
@@ -1378,9 +1417,10 @@ function UTF16LEToUTF16(data, options) {
|
|
|
1378
1417
|
}
|
|
1379
1418
|
}
|
|
1380
1419
|
|
|
1381
|
-
var results = [];
|
|
1382
1420
|
var len = data && data.length;
|
|
1383
1421
|
var i = 0;
|
|
1422
|
+
var results = createBuffer(8, len + 2);
|
|
1423
|
+
var n = 0;
|
|
1384
1424
|
|
|
1385
1425
|
if (len >= 2 &&
|
|
1386
1426
|
((data[0] === 0xFE && data[1] === 0xFF) ||
|
|
@@ -1390,8 +1430,8 @@ function UTF16LEToUTF16(data, options) {
|
|
|
1390
1430
|
}
|
|
1391
1431
|
|
|
1392
1432
|
if (bom) {
|
|
1393
|
-
results[
|
|
1394
|
-
results[
|
|
1433
|
+
results[n++] = bom[0];
|
|
1434
|
+
results[n++] = bom[1];
|
|
1395
1435
|
}
|
|
1396
1436
|
|
|
1397
1437
|
var c1, c2;
|
|
@@ -1400,15 +1440,15 @@ function UTF16LEToUTF16(data, options) {
|
|
|
1400
1440
|
c2 = data[i++];
|
|
1401
1441
|
|
|
1402
1442
|
if (isLE) {
|
|
1403
|
-
results[
|
|
1404
|
-
results[
|
|
1443
|
+
results[n++] = c1;
|
|
1444
|
+
results[n++] = c2;
|
|
1405
1445
|
} else {
|
|
1406
|
-
results[
|
|
1407
|
-
results[
|
|
1446
|
+
results[n++] = c2;
|
|
1447
|
+
results[n++] = c1;
|
|
1408
1448
|
}
|
|
1409
1449
|
}
|
|
1410
1450
|
|
|
1411
|
-
return results;
|
|
1451
|
+
return util.truncateBuffer(results, n);
|
|
1412
1452
|
}
|
|
1413
1453
|
exports.UTF16LEToUTF16 = UTF16LEToUTF16;
|
|
1414
1454
|
|
|
@@ -1416,10 +1456,11 @@ exports.UTF16LEToUTF16 = UTF16LEToUTF16;
|
|
|
1416
1456
|
* UTF-16BE to UTF-16LE
|
|
1417
1457
|
*/
|
|
1418
1458
|
function UTF16BEToUTF16LE(data) {
|
|
1419
|
-
var results = [];
|
|
1420
1459
|
var i = 0;
|
|
1421
1460
|
var len = data && data.length;
|
|
1422
1461
|
var c1, c2;
|
|
1462
|
+
var results = createBuffer(8, len);
|
|
1463
|
+
var n = 0;
|
|
1423
1464
|
|
|
1424
1465
|
if (len >= 2 &&
|
|
1425
1466
|
((data[0] === 0xFE && data[1] === 0xFF) ||
|
|
@@ -1431,11 +1472,11 @@ function UTF16BEToUTF16LE(data) {
|
|
|
1431
1472
|
while (i < len) {
|
|
1432
1473
|
c1 = data[i++];
|
|
1433
1474
|
c2 = data[i++];
|
|
1434
|
-
results[
|
|
1435
|
-
results[
|
|
1475
|
+
results[n++] = c2;
|
|
1476
|
+
results[n++] = c1;
|
|
1436
1477
|
}
|
|
1437
1478
|
|
|
1438
|
-
return results;
|
|
1479
|
+
return util.truncateBuffer(results, n);
|
|
1439
1480
|
}
|
|
1440
1481
|
exports.UTF16BEToUTF16LE = UTF16BEToUTF16LE;
|
|
1441
1482
|
|
|
@@ -1687,28 +1728,39 @@ function UTF16LEToSJIS(data, options) {
|
|
|
1687
1728
|
}
|
|
1688
1729
|
exports.UTF16LEToSJIS = UTF16LEToSJIS;
|
|
1689
1730
|
|
|
1731
|
+
function canUseCreateBuffer(fallbackOption) {
|
|
1732
|
+
return !fallbackOption || fallbackOption === 'ignore' || fallbackOption === 'error';
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
function createBuffer(bits, size, fallbackOption) {
|
|
1736
|
+
if (!canUseCreateBuffer(fallbackOption)) {
|
|
1737
|
+
return [];
|
|
1738
|
+
}
|
|
1739
|
+
return util.createBuffer(bits, size);
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1690
1742
|
/**
|
|
1691
1743
|
* Fallback handler when a character can't be represented
|
|
1692
1744
|
*/
|
|
1693
|
-
function handleFallback(results, bytes, fallbackOption) {
|
|
1745
|
+
function handleFallback(results, n, bytes, fallbackOption) {
|
|
1694
1746
|
switch (fallbackOption) {
|
|
1695
1747
|
case 'html-entity':
|
|
1696
1748
|
case 'html-entity-hex':
|
|
1697
1749
|
var unicode = UTF8ToUNICODE(bytes, { asCodePoint: true })[0];
|
|
1698
1750
|
if (unicode) {
|
|
1699
|
-
results[
|
|
1700
|
-
results[
|
|
1751
|
+
results[n++] = 0x26; // &
|
|
1752
|
+
results[n++] = 0x23; // #
|
|
1701
1753
|
|
|
1702
1754
|
var radix = fallbackOption.slice(-3) === 'hex' ? 16 : 10;
|
|
1703
1755
|
if (radix === 16) {
|
|
1704
|
-
results[
|
|
1756
|
+
results[n++] = 0x78; // x
|
|
1705
1757
|
}
|
|
1706
1758
|
|
|
1707
1759
|
var entity = unicode.toString(radix);
|
|
1708
1760
|
for (var i = 0, len = entity.length; i < len; i++) {
|
|
1709
|
-
results[
|
|
1761
|
+
results[n++] = entity.charCodeAt(i);
|
|
1710
1762
|
}
|
|
1711
|
-
results[
|
|
1763
|
+
results[n++] = 0x3B; // ;
|
|
1712
1764
|
}
|
|
1713
1765
|
break;
|
|
1714
1766
|
case 'error':
|
|
@@ -1716,4 +1768,5 @@ function handleFallback(results, bytes, fallbackOption) {
|
|
|
1716
1768
|
case 'ignore':
|
|
1717
1769
|
break;
|
|
1718
1770
|
}
|
|
1771
|
+
return n;
|
|
1719
1772
|
}
|