added QuotedPrintable{De,En}coder.
This commit is contained in:
parent
01df7ac29c
commit
02735ff4a1
7 changed files with 72 additions and 28 deletions
|
@ -32,6 +32,9 @@ export class AppComponent extends OnInit {
|
|||
try {
|
||||
result = converter.convert(content);
|
||||
} catch (error) {
|
||||
if (typeof console === "object" && typeof console.log === "function") {
|
||||
console.log(error);
|
||||
}
|
||||
result = null;
|
||||
}
|
||||
if (result === null) {
|
||||
|
|
42
app/converter/quotedprintabledecoder.ts
Normal file
42
app/converter/quotedprintabledecoder.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import {Converter} from "./converter";
|
||||
|
||||
declare var window:any;
|
||||
|
||||
export class QuotedPrintableDecoder implements Converter {
|
||||
|
||||
private utf8:any = window.utf8;
|
||||
private quotedPrintable:any = window.quotedPrintable;
|
||||
|
||||
getDisplayname():string {
|
||||
return "Decode quoted printable";
|
||||
}
|
||||
|
||||
getId():string {
|
||||
return "decodequotedprintable";
|
||||
}
|
||||
|
||||
convert(input:string):string {
|
||||
return this.utf8.decode(this.quotedPrintable.decode(input));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"id": "decodequotedprintable",
|
||||
"name": "Decode quoted printable",
|
||||
"convert": function (input) {
|
||||
try {
|
||||
return {
|
||||
"status": "OK",
|
||||
"content": utf8.decode(quotedPrintable.decode(input))
|
||||
};
|
||||
} catch (exception) {
|
||||
return {
|
||||
"status": "ERROR",
|
||||
"content": "Invalid quoted printable string."
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
*/
|
18
app/converter/quotedprintableencoder.ts
Normal file
18
app/converter/quotedprintableencoder.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import {Converter} from "./converter";
|
||||
|
||||
declare var window:any;
|
||||
|
||||
export class QuotedPrintableEncoder implements Converter {
|
||||
|
||||
getDisplayname():string {
|
||||
return "Encode quoted printable";
|
||||
}
|
||||
|
||||
getId():string {
|
||||
return "encodequotedprintable";
|
||||
}
|
||||
|
||||
convert(input:string):string {
|
||||
return window.quotedPrintable.encode(window.utf8.encode(input));
|
||||
}
|
||||
}
|
|
@ -12,6 +12,8 @@ import {DecToHexConverter} from "./converter/dectohexconverter";
|
|||
import {HexToDecConverter} from "./converter/hextodecconverter";
|
||||
import {DecToBinConverter} from "./converter/dectobinconverter";
|
||||
import {BinToDecConverter} from "./converter/bintodecconverter";
|
||||
import {QuotedPrintableDecoder} from "./converter/quotedprintabledecoder";
|
||||
import {QuotedPrintableEncoder} from "./converter/quotedprintableencoder";
|
||||
|
||||
@Injectable()
|
||||
export class ConverterregistryService {
|
||||
|
@ -47,6 +49,8 @@ export class ConverterregistryService {
|
|||
this.registerConverter(new HexToDecConverter());
|
||||
this.registerConverter(new DecToBinConverter());
|
||||
this.registerConverter(new BinToDecConverter());
|
||||
this.registerConverter(new QuotedPrintableEncoder());
|
||||
this.registerConverter(new QuotedPrintableDecoder());
|
||||
}
|
||||
|
||||
private registerConverter(converter:Converter):void {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue