Skip to content

Commit

Permalink
Add basic support for quoted-printable
Browse files Browse the repository at this point in the history
(#9)
  • Loading branch information
Infocatcher committed Aug 25, 2015
1 parent d9edb7d commit c32eccb
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion converter.js
Expand Up @@ -57,6 +57,10 @@
// based on code from http://www.farfarfar.com/scripts/encrypt/
// Test, проверка <=> VGVzdCwg0L/RgNC+0LLQtdGA0LrQsA== (used UTF-8 code page)

// Quoted-printable encode/decode
// -type="QuotedPrintable"
// [=3D] <=> [=]

// Convert charset
// -type="Charset"
// Encode: WideCharToMultiByte() http://msdn.microsoft.com/en-us/library/dd374130(v=vs.85).aspx
Expand All @@ -70,7 +74,8 @@
// -mode=1 - encode
// -mode=2 - decode
// -type="RegExp" - type of converter ("HTML", "Escapes", "RegExp", "String",
// "URI", "URIComponent", "Unescape", "Base64", "Charset", "Recode")
// "URI", "URIComponent", "Unescape", "Base64", "QuotedPrintable"
// "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
Expand Down Expand Up @@ -1113,6 +1118,24 @@ function decodeBase64(str) {
return base64.decode(str);
}

function encodeQuotedPrintable(str) {
//~ todo: another charset
return str.replace(
/=|[^!-~\s]/g,
function(s) {
var code = s.charCodeAt(0);
var hex = code.toString(16).toUpperCase();
return "=" + "00".substr(hex.length) + hex;
}
);
}
function decodeQuotedPrintable(str) {
//~ todo: another charset
return str.replace(/=([\dA-F]{2})/g, function(s, code) {
return String.fromCharCode("0x" + code);
});
}

var convertersNoGUI = {
charset: true,
recode: true
Expand Down Expand Up @@ -1175,6 +1198,13 @@ var converters = {
encode: encodeBase64,
decode: decodeBase64
},
quotedprintable: {
prettyName: "Quoted-Printable",
firstAction: "decode",
speed: [10e3, 10e3], //~ todo: use real values
encode: encodeQuotedPrintable,
decode: decodeQuotedPrintable
},
charset: {
prettyName: "Charset",
firstAction: "decode",
Expand Down

0 comments on commit c32eccb

Please sign in to comment.