summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/iconv-lite/encodings/dbcs-codec.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/iconv-lite/encodings/dbcs-codec.js')
-rw-r--r--deps/npm/node_modules/iconv-lite/encodings/dbcs-codec.js35
1 files changed, 18 insertions, 17 deletions
diff --git a/deps/npm/node_modules/iconv-lite/encodings/dbcs-codec.js b/deps/npm/node_modules/iconv-lite/encodings/dbcs-codec.js
index 7a8559824e..1fe3e16011 100644
--- a/deps/npm/node_modules/iconv-lite/encodings/dbcs-codec.js
+++ b/deps/npm/node_modules/iconv-lite/encodings/dbcs-codec.js
@@ -42,7 +42,7 @@ function DBCSCodec(codecOptions, iconv) {
this.decodeTables = [];
this.decodeTables[0] = UNASSIGNED_NODE.slice(0); // Create root node.
- // Sometimes a MBCS char corresponds to a sequence of unicode chars. We store them as arrays of integers here.
+ // Sometimes a MBCS char corresponds to a sequence of unicode chars. We store them as arrays of integers here.
this.decodeTableSeq = [];
// Actual mapping tables consist of chunks. Use them to fill up decode tables.
@@ -51,7 +51,7 @@ function DBCSCodec(codecOptions, iconv) {
this.defaultCharUnicode = iconv.defaultCharUnicode;
-
+
// Encode tables: Unicode -> DBCS.
// `encodeTable` is array mapping from unicode char to encoded char. All its values are integers for performance.
@@ -60,7 +60,7 @@ function DBCSCodec(codecOptions, iconv) {
// == UNASSIGNED -> no conversion found. Output a default char.
// <= SEQ_START -> it's an index in encodeTableSeq, see below. The character starts a sequence.
this.encodeTable = [];
-
+
// `encodeTableSeq` is used when a sequence of unicode characters is encoded as a single code. We use a tree of
// objects where keys correspond to characters in sequence and leafs are the encoded dbcs values. A special DEF_CHAR key
// means end of sequence (needed when one sequence is a strict subsequence of another).
@@ -78,7 +78,7 @@ function DBCSCodec(codecOptions, iconv) {
for (var j = val.from; j <= val.to; j++)
skipEncodeChars[j] = true;
}
-
+
// Use decode trie to recursively fill out encode tables.
this._fillEncodeTable(0, 0, skipEncodeChars);
@@ -115,7 +115,7 @@ function DBCSCodec(codecOptions, iconv) {
thirdByteNode[i] = NODE_START - fourthByteNodeIdx;
for (var i = 0x30; i <= 0x39; i++)
fourthByteNode[i] = GB18030_CODE
- }
+ }
}
DBCSCodec.prototype.encoder = DBCSEncoder;
@@ -180,7 +180,7 @@ DBCSCodec.prototype._addDecodeChunk = function(chunk) {
else
writeTable[curAddr++] = code; // Basic char
}
- }
+ }
else if (typeof part === "number") { // Integer, meaning increasing sequence starting with prev character.
var charCode = writeTable[curAddr - 1] + 1;
for (var l = 0; l < part; l++)
@@ -211,7 +211,7 @@ DBCSCodec.prototype._setEncodeChar = function(uCode, dbcsCode) {
}
DBCSCodec.prototype._setEncodeSequence = function(seq, dbcsCode) {
-
+
// Get the root of character tree according to first character of the sequence.
var uCode = seq[0];
var bucket = this._getEncodeBucket(uCode);
@@ -272,7 +272,7 @@ function DBCSEncoder(options, codec) {
// Encoder state
this.leadSurrogate = -1;
this.seqObj = undefined;
-
+
// Static data
this.encodeTable = codec.encodeTable;
this.encodeTableSeq = codec.encodeTableSeq;
@@ -294,7 +294,7 @@ DBCSEncoder.prototype.write = function(str) {
}
else {
var uCode = nextChar;
- nextChar = -1;
+ nextChar = -1;
}
// 1. Handle surrogates.
@@ -316,7 +316,7 @@ DBCSEncoder.prototype.write = function(str) {
// Incomplete surrogate pair - only trail surrogate found.
uCode = UNASSIGNED;
}
-
+
}
}
else if (leadSurrogate !== -1) {
@@ -357,7 +357,7 @@ DBCSEncoder.prototype.write = function(str) {
var subtable = this.encodeTable[uCode >> 8];
if (subtable !== undefined)
dbcsCode = subtable[uCode & 0xFF];
-
+
if (dbcsCode <= SEQ_START) { // Sequence start
seqObj = this.encodeTableSeq[SEQ_START-dbcsCode];
continue;
@@ -380,7 +380,7 @@ DBCSEncoder.prototype.write = function(str) {
// 3. Write dbcsCode character.
if (dbcsCode === UNASSIGNED)
dbcsCode = this.defaultCharSingleByte;
-
+
if (dbcsCode < 0x100) {
newBuf[j++] = dbcsCode;
}
@@ -427,7 +427,7 @@ DBCSEncoder.prototype.end = function() {
newBuf[j++] = this.defaultCharSingleByte;
this.leadSurrogate = -1;
}
-
+
return newBuf.slice(0, j);
}
@@ -451,21 +451,21 @@ function DBCSDecoder(options, codec) {
DBCSDecoder.prototype.write = function(buf) {
var newBuf = Buffer.alloc(buf.length*2),
- nodeIdx = this.nodeIdx,
+ nodeIdx = this.nodeIdx,
prevBuf = this.prevBuf, prevBufOffset = this.prevBuf.length,
seqStart = -this.prevBuf.length, // idx of the start of current parsed sequence.
uCode;
if (prevBufOffset > 0) // Make prev buf overlap a little to make it easier to slice later.
prevBuf = Buffer.concat([prevBuf, buf.slice(0, 10)]);
-
+
for (var i = 0, j = 0; i < buf.length; i++) {
var curByte = (i >= 0) ? buf[i] : prevBuf[i + prevBufOffset];
// Lookup in current trie node.
var uCode = this.decodeTables[nodeIdx][curByte];
- if (uCode >= 0) {
+ if (uCode >= 0) {
// Normal character, just use it.
}
else if (uCode === UNASSIGNED) { // Unknown char.
@@ -497,7 +497,7 @@ DBCSDecoder.prototype.write = function(buf) {
throw new Error("iconv-lite internal error: invalid decoding table value " + uCode + " at " + nodeIdx + "/" + curByte);
// Write the character to buffer, handling higher planes using surrogate pair.
- if (uCode > 0xFFFF) {
+ if (uCode > 0xFFFF) {
uCode -= 0x10000;
var uCodeLead = 0xD800 + Math.floor(uCode / 0x400);
newBuf[j++] = uCodeLead & 0xFF;
@@ -552,3 +552,4 @@ function findIdx(table, val) {
}
return l;
}
+