-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'swap-case' of https://github.com/mikecat/CyberChef
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @author mikecat | ||
* @copyright Crown Copyright 2023 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
|
||
/** | ||
* Swap case operation | ||
*/ | ||
class SwapCase extends Operation { | ||
|
||
/** | ||
* SwapCase constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "Swap case"; | ||
this.module = "Default"; | ||
this.description = "Converts uppercase letters to lowercase ones, and lowercase ones to uppercase ones."; | ||
this.infoURL = ""; | ||
this.inputType = "string"; | ||
this.outputType = "string"; | ||
this.args = []; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
let result = ""; | ||
for (let i = 0; i < input.length; i++) { | ||
const c = input.charAt(i); | ||
const upper = c.toUpperCase(); | ||
if (c === upper) { | ||
result += c.toLowerCase(); | ||
} else { | ||
result += upper; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Highlight Swap case | ||
* | ||
* @param {Object[]} pos | ||
* @param {number} pos[].start | ||
* @param {number} pos[].end | ||
* @param {Object[]} args | ||
* @returns {Object[]} pos | ||
*/ | ||
highlight(pos, args) { | ||
return pos; | ||
} | ||
|
||
/** | ||
* Highlight Swap case in reverse | ||
* | ||
* @param {Object[]} pos | ||
* @param {number} pos[].start | ||
* @param {number} pos[].end | ||
* @param {Object[]} args | ||
* @returns {Object[]} pos | ||
*/ | ||
highlightReverse(pos, args) { | ||
return pos; | ||
} | ||
|
||
} | ||
|
||
export default SwapCase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @author mikecat | ||
* @copyright Crown Copyright 2023 | ||
* @license Apache-2.0 | ||
*/ | ||
import TestRegister from "../../lib/TestRegister.mjs"; | ||
|
||
TestRegister.addTests([ | ||
{ | ||
"name": "Swap Case: basic example", | ||
"input": "Hello, World!", | ||
"expectedOutput": "hELLO, wORLD!", | ||
"recipeConfig": [ | ||
{ | ||
"op": "Swap case", | ||
"args": [ | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
"name": "Swap Case: empty input", | ||
"input": "", | ||
"expectedOutput": "", | ||
"recipeConfig": [ | ||
{ | ||
"op": "Swap case", | ||
"args": [ | ||
], | ||
}, | ||
], | ||
}, | ||
]); |