From 5ceb23a38d7e36aa1a9c8bf330cf931335cc6cf2 Mon Sep 17 00:00:00 2001 From: jiangle Date: Wed, 15 Mar 2023 18:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E4=B8=AD=E5=AD=98=E5=9C=A8"""=E6=88=96"'"=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 8 ++++++++ index.ts | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/index.js b/index.js index 2bea34c..ec71e0b 100644 --- a/index.js +++ b/index.js @@ -116,6 +116,14 @@ function toLua(obj, currDepth, CurrEntry) { } if (!lodash.isObject(obj)) { if (typeof obj === 'string') { + let hasTwo = obj.indexOf("\"") >= 0; + let hasOne = obj.indexOf("\'") >= 0; + if (hasTwo && hasOne) { + return '"' + obj.replace(/\"/g, "\\\"").replace(/\'/, "\\\'") + '"'; + } + else if (hasTwo) { + return "'" + obj + "'"; + } return '"' + obj + '"'; } return obj.toString(); diff --git a/index.ts b/index.ts index f7ae08f..df940e5 100644 --- a/index.ts +++ b/index.ts @@ -112,6 +112,13 @@ function toLua(obj: any, currDepth: number, CurrEntry?: string): string { } if (!lodash.isObject(obj)) { if (typeof obj === 'string') { + let hasTwo = obj.indexOf("\"") >= 0; + let hasOne = obj.indexOf("\'") >= 0; + if (hasTwo && hasOne) { + return '"' + obj.replace(/\"/g, "\\\"").replace(/\'/, "\\\'") + '"'; + } else if (hasTwo) { + return "'" + obj + "'"; + } return '"' + obj + '"'; } return obj.toString();