Skip to content

Commit

Permalink
add unicode convertion
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhikang0916 authored and marclipovsky committed Apr 11, 2024
1 parent 60b555e commit b14d1bd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const commandNameFunctionMap = {
duplicateAndIncrement: (str) => str + increment(str),
duplicateAndDecrement: (str) => str + decrement(str),
sequence,
utf8ToChar: (str) => str.match(/\\u[\dA-Fa-f]{4}/g).map((x) => x.slice(2)).map((x) => String.fromCharCode(parseInt(x, 16))).join(""),
charToUtf8: (str) => str.split("").map((x) => `\\u${x.charCodeAt(0).toString(16).padStart(4, '0')}`).join(""),
};
const numberFunctionNames = [
"increment",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@
"title": "Sequence all numbers (starting with first number)",
"category": "String Manipulation",
"command": "string-manipulation.sequence"
},
{
"title": "Convert char to UTF8",
"category": "String Manipulation",
"command": "string-manipulation.charToUtf8"
},
{
"title": "Convert UTF8 to char",
"category": "String Manipulation",
"command": "string-manipulation.utf8ToChar"
}
],
"submenus": [
Expand Down Expand Up @@ -308,6 +318,14 @@
{
"command": "string-manipulation.sequence",
"group": "7_modification"
},
{
"command": "string-manipulation.utf8ToChar",
"group": "7_modification"
},
{
"command": "string-manipulation.charToUtf8",
"group": "7_modification"
}
]
}
Expand Down
2 changes: 2 additions & 0 deletions test/suite/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ suite("Extension Test Suite", () => {
"a14 b15 c16\n17d 18e 19f 20x y21 22z23",
],
["sequence", "-3 4 5 6 7", "-3 -2 -1 0 1"],
["utf8ToChar", "\\u0061\\u0062\\u0063\\u4e2d\\u6587\\ud83d\\udc96", "abc中文💖"],
["charToUtf8", "abc中文💖", "\\u0061\\u0062\\u0063\\u4e2d\\u6587\\ud83d\\udc96"],
];
suite("commandNameFunctionMap outputs correctly for all methods", () => {
tests.forEach(
Expand Down

0 comments on commit b14d1bd

Please sign in to comment.