Skip to content
Browse files

Add escape()/unescape() ability

  • Loading branch information...
1 parent 235d9f4 commit 3b76569ff6dabd901114f6bb117853c18a96b59f @Infocatcher committed Mar 1, 2013
Showing with 86 additions and 42 deletions.
  1. +86 −42 converter.js
View
128 converter.js
@@ -39,6 +39,10 @@
// Encode/decode Uniform Resource Identifiers (URIs) with
// encodeURI/decodeURI or encodeURIComponent/decodeURIComponent
+// Hexadecimal escape/unescape
+// JavaScript's escape()/unescape()
+// "test тест" <=> %22test%20%u0442%u0435%u0441%u0442%22
+
// Base64 encode/decode
// based on code from http://www.farfarfar.com/scripts/encrypt/
@@ -55,7 +59,7 @@
// -mode=1 - encode
// -mode=2 - decode
// -type="RegExp" - type of converter ("HTML", "Escapes", "RegExp", "String",
-// "URI", "URIComponent", "Base64", "Charset", "Recode")
+// "URI", "URIComponent", "Unescape", "Base64", "Charset", "Recode")
// -action=1 - sum of flags: 1 - insert, 2 - copy, 4 - show
// -dialog=false - don't show dialog
// -onlySelected=true - use only selected text
@@ -147,7 +151,7 @@ function _localize(s) {
"&&#c&ode; => symbol": {
ru: "&&#к&од; => символ"
},
- "sy&mbol => &&#code;": {
+ "sym&bol => &&#code;": {
ru: "си&мвол => &&#код;"
},
"he&x-code": {
@@ -174,8 +178,11 @@ function _localize(s) {
"Base64": {
ru: "Base64"
},
- "&Base64": {
- ru: "&Base64"
+ "Hexadeci&mal escape": {
+ ru: "&Шестнадцатеричное кодирование"
+ },
+ "Base&64": {
+ ru: "Base&64"
},
"Direction": {
ru: "Направление"
@@ -867,6 +874,13 @@ function decodeURICustom(str, cp) {
return /%/.test(ret) ? str : ret;
}
+function escapeWrapped(str) {
+ return escape(str);
+}
+function unescapeWrapped(str) {
+ return unescape(str);
+}
+
var base64 = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
@@ -1092,6 +1106,13 @@ var converters = {
encode: encodeURIComponentWrapped,
decode: decodeURIComponentWrapped
},
+ unescape: {
+ prettyName: "Unescape",
+ firstAction: "decode",
+ speed: [24e3, 120e3],
+ encode: escapeWrapped,
+ decode: unescapeWrapped
+ },
base64: {
prettyName: "Base64",
firstAction: "decode",
@@ -1342,20 +1363,21 @@ function converterDialog(modal) {
var IDC_TYPE_URI = 1012;
var IDC_TYPE_URIC = 1013;
var IDC_TYPE_BASE64 = 1014;
- var IDC_TO_DATA_URI = 1015;
- var IDC_TO_BASE64 = 1016;
- var IDC_MODE_AUTO = 1017;
- var IDC_MODE_ENCODE = 1018;
- var IDC_MODE_DECODE = 1019;
- var IDC_ACT_INSERT = 1020;
- var IDC_ACT_COPY = 1021;
- var IDC_ACT_SHOW = 1022;
- var IDC_OUTPUT = 1023;
- var IDC_OK = 1024;
- var IDC_CONVERT = 1025;
- var IDC_CANCEL = 1026;
-
- var hWndGroupType, hWndTypeHTML, hWndTypeEscapes, hWndTypeRegExp, hWndTypeString, hWndTypeURI, hWndTypeURIC, hWndTypeBase64;
+ var IDC_TYPE_UNESCAPE = 1015;
+ var IDC_TO_DATA_URI = 1016;
+ var IDC_TO_BASE64 = 1017;
+ var IDC_MODE_AUTO = 1018;
+ var IDC_MODE_ENCODE = 1019;
+ var IDC_MODE_DECODE = 1020;
+ var IDC_ACT_INSERT = 1021;
+ var IDC_ACT_COPY = 1022;
+ var IDC_ACT_SHOW = 1023;
+ var IDC_OUTPUT = 1024;
+ var IDC_OK = 1025;
+ var IDC_CONVERT = 1026;
+ var IDC_CANCEL = 1027;
+
+ var hWndGroupType, hWndTypeHTML, hWndTypeEscapes, hWndTypeRegExp, hWndTypeString, hWndTypeURI, hWndTypeURIC, hWndTypeUnescape, hWndTypeBase64;
var hWndDecEnt, hWndEncEnt, hWndDecEntSp, hWndEncEntSp, hWndDecChr, hWndEncChr, hWndEncChrHex;
var hWndToDataURI, hWndToBase64;
var hWndGroupMode, hWndModeAuto, hWndModeEncode, hWndModeDecode;
@@ -1391,7 +1413,7 @@ function converterDialog(modal) {
var sizeNonClientY = oSys.Call("user32::GetSystemMetrics", 33 /*SM_CYSIZEFRAME*/) * 2 + oSys.Call("user32::GetSystemMetrics", 4 /*SM_CYCAPTION*/);
var dlgMinW = scale.x(410) + sizeNonClientX;
- var dlgMinH = scale.y(373) + sizeNonClientY; // + outputH + 12
+ var dlgMinH = scale.y(392) + sizeNonClientY; // + outputH + 12
var outputMinH = 20;
if(outputH != undefined)
@@ -1447,7 +1469,7 @@ function converterDialog(modal) {
12, //x
10, //y
386, //nWidth
- 214, //nHeight
+ 233, //nHeight
hWnd, //hWndParent
IDC_STATIC, //ID
hInstanceDLL, //hInstance
@@ -1582,7 +1604,7 @@ function converterDialog(modal) {
hInstanceDLL, //hInstance
0 //lpParam
);
- setWindowFontAndText(hWndEncChr, hGuiFont, _localize("sy&mbol => &&#code;"));
+ setWindowFontAndText(hWndEncChr, hGuiFont, _localize("sym&bol => &&#code;"));
checked(hWndEncChr, encodeChars);
// Checkbox: HTML symbol => &#code; as hex
@@ -1733,22 +1755,40 @@ function converterDialog(modal) {
checked(hWndToBase64, toBase64);
+ // Radiobutton escape/unescape converter
+ hWndTypeUnescape = createWindowEx(
+ 0, //dwExStyle
+ "BUTTON", //lpClassName
+ 0, //lpWindowName
+ 0x50000004, //WS_VISIBLE|WS_CHILD|BS_RADIOBUTTON
+ 24, //x
+ 202, //y
+ 350, //nWidth
+ 16, //nHeight
+ hWnd, //hWndParent
+ IDC_TYPE_UNESCAPE, //ID
+ hInstanceDLL, //hInstance
+ 0 //lpParam
+ );
+ setWindowFontAndText(hWndTypeUnescape, hGuiFont, _localize("Hexadeci&mal escape"));
+ checked(hWndTypeUnescape, type == "unescape");
+
// Radiobutton Base64 converter
hWndTypeBase64 = createWindowEx(
0, //dwExStyle
"BUTTON", //lpClassName
0, //lpWindowName
0x50000004, //WS_VISIBLE|WS_CHILD|BS_RADIOBUTTON
24, //x
- 202, //y
+ 221, //y
350, //nWidth
16, //nHeight
hWnd, //hWndParent
IDC_TYPE_BASE64, //ID
hInstanceDLL, //hInstance
0 //lpParam
);
- setWindowFontAndText(hWndTypeBase64, hGuiFont, _localize("&Base64"));
+ setWindowFontAndText(hWndTypeBase64, hGuiFont, _localize("Base&64"));
checked(hWndTypeBase64, type == "base64");
@@ -1759,7 +1799,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50000007, //WS_VISIBLE|WS_CHILD|BS_GROUPBOX
12, //x
- 234, //y
+ 253, //y
386, //nWidth
42, //nHeight
hWnd, //hWndParent
@@ -1776,7 +1816,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50000004, //WS_VISIBLE|WS_CHILD|BS_RADIOBUTTON
24, //x
- 252, //y
+ 271, //y
116, //nWidth
16, //nHeight
hWnd, //hWndParent
@@ -1794,7 +1834,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50000004, //WS_VISIBLE|WS_CHILD|BS_RADIOBUTTON
148, //x
- 252, //y
+ 271, //y
116, //nWidth
16, //nHeight
hWnd, //hWndParent
@@ -1812,7 +1852,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50000004, //WS_VISIBLE|WS_CHILD|BS_RADIOBUTTON
272, //x
- 252, //y
+ 271, //y
116, //nWidth
16, //nHeight
hWnd, //hWndParent
@@ -1831,7 +1871,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50000007, //WS_VISIBLE|WS_CHILD|BS_GROUPBOX
12, //x
- 286, //y
+ 305, //y
386, //nWidth
42, //nHeight
hWnd, //hWndParent
@@ -1848,7 +1888,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50010003, //WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_AUTOCHECKBOX
24, //x
- 304, //y
+ 323, //y
116, //nWidth
16, //nHeight
hWnd, //hWndParent
@@ -1866,7 +1906,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50010003, //WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_AUTOCHECKBOX
148, //x
- 304, //y
+ 323, //y
116, //nWidth
16, //nHeight
hWnd, //hWndParent
@@ -1884,7 +1924,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50010003, //WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_AUTOCHECKBOX
272, //x
- 304, //y
+ 323, //y
116, //nWidth
16, //nHeight
hWnd, //hWndParent
@@ -1902,7 +1942,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50315904, //WS_VISIBLE|WS_CHILD|WS_VSCROLL|WS_HSCROLL|ES_LEFT|ES_MULTILINE|ES_DISABLENOSCROLL|WS_TABSTOP|ES_SUNKEN|ES_NOHIDESEL|ES_READONLY
12, //x
- 340, //y
+ 359, //y
386, //nWidth
outputH, //nHeight
hWnd, //hWndParent
@@ -1924,7 +1964,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50010001, //WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_DEFPUSHBUTTON
75, //x
- 339 + dh, //y
+ 358 + dh, //y
100, //nWidth
23, //nHeight
hWnd, //hWndParent
@@ -1941,7 +1981,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50010000, //WS_VISIBLE|WS_CHILD|WS_TABSTOP
187, //x
- 339 + dh, //y
+ 358 + dh, //y
100, //nWidth
23, //nHeight
hWnd, //hWndParent
@@ -1958,7 +1998,7 @@ function converterDialog(modal) {
0, //lpWindowName
0x50010000, //WS_VISIBLE|WS_CHILD|WS_TABSTOP
299, //x
- 339 + dh, //y
+ 358 + dh, //y
100, //nWidth
23, //nHeight
hWnd, //hWndParent
@@ -2076,14 +2116,16 @@ function converterDialog(modal) {
case IDC_TYPE_STRING:
case IDC_TYPE_URI:
case IDC_TYPE_URIC:
+ case IDC_TYPE_UNESCAPE:
case IDC_TYPE_BASE64:
- checked(hWndTypeHTML, idc == IDC_TYPE_HTML);
- checked(hWndTypeEscapes, idc == IDC_TYPE_ESCAPES);
- checked(hWndTypeRegExp, idc == IDC_TYPE_REGEXP);
- checked(hWndTypeString, idc == IDC_TYPE_STRING);
- checked(hWndTypeURI, idc == IDC_TYPE_URI);
- checked(hWndTypeURIC, idc == IDC_TYPE_URIC);
- checked(hWndTypeBase64, idc == IDC_TYPE_BASE64);
+ checked(hWndTypeHTML, idc == IDC_TYPE_HTML);
+ checked(hWndTypeEscapes, idc == IDC_TYPE_ESCAPES);
+ checked(hWndTypeRegExp, idc == IDC_TYPE_REGEXP);
+ checked(hWndTypeString, idc == IDC_TYPE_STRING);
+ checked(hWndTypeURI, idc == IDC_TYPE_URI);
+ checked(hWndTypeURIC, idc == IDC_TYPE_URIC);
+ checked(hWndTypeUnescape, idc == IDC_TYPE_UNESCAPE);
+ checked(hWndTypeBase64, idc == IDC_TYPE_BASE64);
setHTMLOptions();
setBase64Options();
@@ -2374,6 +2416,8 @@ function converterDialog(modal) {
type = "uri";
else if(checked(hWndTypeURIC))
type = "uricomponent";
+ else if(checked(hWndTypeUnescape))
+ type = "unescape";
else if(checked(hWndTypeBase64))
type = "base64";
else

0 comments on commit 3b76569

Please sign in to comment.
Something went wrong with that request. Please try again.