From 683c6435437789eb078702a076b36226d07e02df Mon Sep 17 00:00:00 2001 From: NI Date: Tue, 17 Sep 2019 09:54:22 +0800 Subject: [PATCH] Clean up some code in the Telnet control --- ui/control/telnet.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ui/control/telnet.js b/ui/control/telnet.js index 30df246..56aa985 100644 --- a/ui/control/telnet.js +++ b/ui/control/telnet.js @@ -336,9 +336,15 @@ class Control { this.charset = data.charset; if (this.charset === "utf-8") { + let enc = new TextEncoder(); + this.charsetDecoder = d => { return d; }; + + this.charsetEncoder = dStr => { + return enc.encode(dStr); + }; } else { let dec = new TextDecoder(this.charset), enc = new TextEncoder(); @@ -350,6 +356,10 @@ class Control { }) ); }; + + this.charsetEncoder = dStr => { + return iconv.encode(dStr, this.charset); + }; } this.sender = data.send; @@ -453,13 +463,7 @@ class Control { } let currentLen = 0; - let enc = null; - - if (this.charset !== "utf-8") { - enc = new iconv.encode(data, this.charset); - } else { - enc = new TextEncoder().encode(data); - } + const enc = this.charsetEncoder(data); while (currentLen < enc.length) { const iacPos = this.searchNextIAC(currentLen, enc);