Clean up some code in the Telnet control

This commit is contained in:
NI
2019-09-17 09:54:22 +08:00
parent cd88e06d9a
commit 683c643543

View File

@@ -336,9 +336,15 @@ class Control {
this.charset = data.charset; this.charset = data.charset;
if (this.charset === "utf-8") { if (this.charset === "utf-8") {
let enc = new TextEncoder();
this.charsetDecoder = d => { this.charsetDecoder = d => {
return d; return d;
}; };
this.charsetEncoder = dStr => {
return enc.encode(dStr);
};
} else { } else {
let dec = new TextDecoder(this.charset), let dec = new TextDecoder(this.charset),
enc = new TextEncoder(); enc = new TextEncoder();
@@ -350,6 +356,10 @@ class Control {
}) })
); );
}; };
this.charsetEncoder = dStr => {
return iconv.encode(dStr, this.charset);
};
} }
this.sender = data.send; this.sender = data.send;
@@ -453,13 +463,7 @@ class Control {
} }
let currentLen = 0; let currentLen = 0;
let enc = null; const enc = this.charsetEncoder(data);
if (this.charset !== "utf-8") {
enc = new iconv.encode(data, this.charset);
} else {
enc = new TextEncoder().encode(data);
}
while (currentLen < enc.length) { while (currentLen < enc.length) {
const iacPos = this.searchNextIAC(currentLen, enc); const iacPos = this.searchNextIAC(currentLen, enc);