Removes need for runParseEscapedString

- Fixes examples
- Actually makes it work
This commit is contained in:
Matt C 2017-08-04 15:54:00 +01:00
parent 3186335f47
commit 9161cc693d
2 changed files with 20 additions and 24 deletions

View File

@ -3254,14 +3254,14 @@ const OperationConfig = {
}, },
"Escape String": { "Escape String": {
description: "Escapes a string so that it can be embedded in another. For example, <code>Don't stop me now</code> becomes <code>Don\\'t stop me now</code>.", description: "Escapes a string so that it can be embedded in another. For example, <code>Don't stop me now</code> becomes <code>Don\\'t stop me now</code>.",
run: StrUtils.run_escape, run: StrUtils.runEscape,
inputType: "string", inputType: "string",
outputType: "string", outputType: "string",
args: [] args: []
}, },
"Unescape String": { "Unescape String": {
description: "Unescapes a string that was embedded inside another so that it can be used in it's own right. For example, <code>Don\\'t stop me now</code> becomes <code>Don't stop me now</code>.", description: "Unescapes a string that was embedded inside another so that it can be used in it's own right. For example, <code>Don\\'t stop me now</code> becomes <code>Don't stop me now</code>.",
run: StrUtils.run_unescape, run: StrUtils.runUnescape,
inputType: "string", inputType: "string",
outputType: "string", outputType: "string",
args: [] args: []

View File

@ -448,18 +448,6 @@ const StrUtils = {
return outputs.join(sampleDelim); 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 * @constant
* @default * @default
@ -475,31 +463,41 @@ const StrUtils = {
/** /**
* Escapes a string for embedding in another string. * Escapes a string for embedding in another string.
* *
* Example: "Don't do that" -> "Don\'t do that"
*
* @author Vel0x [dalemy@microsoft.com] * @author Vel0x [dalemy@microsoft.com]
* *
* @param {string} input * @param {string} input
* @param {Object[]} args * @param {Object[]} args
* @returns {string} * @returns {string}
*
* @example
* StrUtils.runUnescape("Don't do that", [])
* > "Don\'t do that"
* StrUtils.runUnescape(`Hello
* World`, [])
* > "Hello\nWorld"
*/ */
runEscape: function(input, args) { 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 * Unescapes a string that was part of another string
* *
* Example: "Don\'t do that" -> "Don't do that"
*
* @author Vel0x [dalemy@microsoft.com] * @author Vel0x [dalemy@microsoft.com]
* *
* @param {string} input * @param {string} input
* @param {Object[]} args * @param {Object[]} args
* @returns {string} * @returns {string}
*
* @example
* StrUtils.runUnescape("Don\'t do that", [])
* > "Don't do that"
* StrUtils.runUnescape("Hello\nWorld", [])
* > `Hello
* World`
*/ */
runUnescape: function(input, args) { 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} * @returns {string}
*/ */
_replaceByKeys: function(input, patternKey, replacementKey) { _replaceByKeys: function(input, patternKey, replacementKey) {
const replacementsLength = StrUtils.ESCAPE_REPLACEMENTS.length;
let output = input; let output = input;
for (let i = 0; i < replacementsLength; i++) { StrUtils.ESCAPE_REPLACEMENTS.forEach(replacement => {
const replacement = StrUtils.ESCAPE_REPLACEMENTS[i];
output = output.split(replacement[patternKey]).join(replacement[replacementKey]); output = output.split(replacement[patternKey]).join(replacement[replacementKey]);
} });
return output; return output;
}, },