From 9161cc693d420f99213bf3e256eaf10183a9f2ef Mon Sep 17 00:00:00 2001 From: Matt C Date: Fri, 4 Aug 2017 15:54:00 +0100 Subject: [PATCH] Removes need for runParseEscapedString - Fixes examples - Actually makes it work --- src/core/config/OperationConfig.js | 4 +-- src/core/operations/StrUtils.js | 40 ++++++++++++++---------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 645b7629..417dea3a 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3254,14 +3254,14 @@ const OperationConfig = { }, "Escape String": { description: "Escapes a string so that it can be embedded in another. For example, Don't stop me now becomes Don\\'t stop me now.", - run: StrUtils.run_escape, + run: StrUtils.runEscape, inputType: "string", outputType: "string", args: [] }, "Unescape String": { description: "Unescapes a string that was embedded inside another so that it can be used in it's own right. For example, Don\\'t stop me now becomes Don't stop me now.", - run: StrUtils.run_unescape, + run: StrUtils.runUnescape, inputType: "string", outputType: "string", args: [] diff --git a/src/core/operations/StrUtils.js b/src/core/operations/StrUtils.js index 9250620f..58b7e7a7 100755 --- a/src/core/operations/StrUtils.js +++ b/src/core/operations/StrUtils.js @@ -448,18 +448,6 @@ const StrUtils = { return outputs.join(sampleDelim); }, - - /** - * Parse escaped string operation. - * - * @param {string} input - * @param {Object[]} args - * @returns {string} - */ - runParseEscapedString: function(input, args) { - return Utils.parseEscapedChars(input); - }, - /** * @constant * @default @@ -475,31 +463,41 @@ const StrUtils = { /** * Escapes a string for embedding in another string. * - * Example: "Don't do that" -> "Don\'t do that" - * * @author Vel0x [dalemy@microsoft.com] * * @param {string} input * @param {Object[]} args * @returns {string} + * + * @example + * StrUtils.runUnescape("Don't do that", []) + * > "Don\'t do that" + * StrUtils.runUnescape(`Hello + * World`, []) + * > "Hello\nWorld" */ runEscape: function(input, args) { - return StrUtils._replace_by_keys(input, "unescaped", "escaped"); + return StrUtils._replaceByKeys(input, "unescaped", "escaped"); }, /** * Unescapes a string that was part of another string * - * Example: "Don\'t do that" -> "Don't do that" - * * @author Vel0x [dalemy@microsoft.com] * * @param {string} input * @param {Object[]} args * @returns {string} + * + * @example + * StrUtils.runUnescape("Don\'t do that", []) + * > "Don't do that" + * StrUtils.runUnescape("Hello\nWorld", []) + * > `Hello + * World` */ runUnescape: function(input, args) { - return StrUtils._replace_by_keys(input, "escaped", "unescaped"); + return StrUtils._replaceByKeys(Utils.parseEscapedChars(input), "escaped", "unescaped"); }, /** @@ -515,12 +513,10 @@ const StrUtils = { * @returns {string} */ _replaceByKeys: function(input, patternKey, replacementKey) { - const replacementsLength = StrUtils.ESCAPE_REPLACEMENTS.length; let output = input; - for (let i = 0; i < replacementsLength; i++) { - const replacement = StrUtils.ESCAPE_REPLACEMENTS[i]; + StrUtils.ESCAPE_REPLACEMENTS.forEach(replacement => { output = output.split(replacement[patternKey]).join(replacement[replacementKey]); - } + }); return output; },