From 1835634d6cf371bdf70c1e3abce6c5b9a5f65f6c Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 28 Sep 2016 13:53:05 +0200 Subject: [PATCH 1/2] split quotedprintable and utf8 converters --- app/converter/quotedprintabledecoder.ts | 2 +- app/converter/quotedprintableencoder.ts | 2 +- app/converter/utf8decoder.ts | 23 +++++++++++++++++++++++ app/converter/utf8encoder.ts | 23 +++++++++++++++++++++++ app/converterregistry.service.ts | 4 ++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 app/converter/utf8decoder.ts create mode 100644 app/converter/utf8encoder.ts diff --git a/app/converter/quotedprintabledecoder.ts b/app/converter/quotedprintabledecoder.ts index d998038..7196f65 100644 --- a/app/converter/quotedprintabledecoder.ts +++ b/app/converter/quotedprintabledecoder.ts @@ -15,7 +15,7 @@ export class QuotedPrintableDecoder implements Converter { convert(input:string):string { try { - return this.nativeLibraryWrapperService.utf8.decode(this.nativeLibraryWrapperService.quotedPrintable.decode(input)); + return this.nativeLibraryWrapperService.quotedPrintable.decode(input); } catch (error) { throw new Error("The input can not be interpreted as quoted-printable. May be corrupt?"); } diff --git a/app/converter/quotedprintableencoder.ts b/app/converter/quotedprintableencoder.ts index 048dbc6..5dfb386 100644 --- a/app/converter/quotedprintableencoder.ts +++ b/app/converter/quotedprintableencoder.ts @@ -14,6 +14,6 @@ export class QuotedPrintableEncoder implements Converter { } convert(input:string):string { - return this.nativeLibraryWrapperService.quotedPrintable.encode(this.nativeLibraryWrapperService.utf8.encode(input)); + return this.nativeLibraryWrapperService.quotedPrintable.encode(input); } } diff --git a/app/converter/utf8decoder.ts b/app/converter/utf8decoder.ts new file mode 100644 index 0000000..2dde0a9 --- /dev/null +++ b/app/converter/utf8decoder.ts @@ -0,0 +1,23 @@ +import {Converter} from "./converter"; +import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; + +export class UTF8Decoder implements Converter { + constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) { + } + + getDisplayname():string { + return "Decode UTF-8"; + } + + getId():string { + return "decodeutf8"; + } + + convert(input:string):string { + try { + return this.nativeLibraryWrapperService.utf8.decode(input); + } catch (error) { + throw new Error("The input can not be interpreted a valid UTF-8 encoded string. May be corrupt?"); + } + } +} diff --git a/app/converter/utf8encoder.ts b/app/converter/utf8encoder.ts new file mode 100644 index 0000000..0e03824 --- /dev/null +++ b/app/converter/utf8encoder.ts @@ -0,0 +1,23 @@ +import {Converter} from "./converter"; +import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; + +export class UTF8Encoder implements Converter { + constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) { + } + + getDisplayname():string { + return "Encode UTF-8"; + } + + getId():string { + return "encodeutf8"; + } + + convert(input:string):string { + try { + return this.nativeLibraryWrapperService.utf8.encode(input); + } catch (error) { + throw new Error("The input can not be encoded as UTF-8. May be corrupt?"); + } + } +} diff --git a/app/converterregistry.service.ts b/app/converterregistry.service.ts index af6e30b..677520b 100644 --- a/app/converterregistry.service.ts +++ b/app/converterregistry.service.ts @@ -17,6 +17,8 @@ import {QuotedPrintableEncoder} from "./converter/quotedprintableencoder"; import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service"; import {PunycodeEncoder} from "./converter/punycodeencoder"; import {PunycodeDecoder} from "./converter/punycodedecoder"; +import {UTF8Encoder} from "./converter/utf8encoder"; +import {UTF8Decoder} from "./converter/utf8decoder"; @Injectable() export class ConverterRegistryService { @@ -56,6 +58,8 @@ export class ConverterRegistryService { this.registerConverter(new BinToDecConverter()); this.registerConverter(new PunycodeEncoder(this.wrapper)); this.registerConverter(new PunycodeDecoder(this.wrapper)); + this.registerConverter(new UTF8Encoder(this.wrapper)); + this.registerConverter(new UTF8Decoder(this.wrapper)); } private registerConverter(converter:Converter):void { From 9b29d638d15368ca83f759c07ca5bbcbbe409f99 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 15 Mar 2017 00:09:57 +0100 Subject: [PATCH 2/2] Split utf8 from quoted printable --- src/app/converter/quotedprintabledecoder.ts | 1 + src/app/converter/quotedprintableencoder.ts | 1 + {app => src/app}/converter/utf8decoder.ts | 1 + {app => src/app}/converter/utf8encoder.ts | 1 + 4 files changed, 4 insertions(+) rename {app => src/app}/converter/utf8decoder.ts (99%) rename {app => src/app}/converter/utf8encoder.ts (99%) diff --git a/src/app/converter/quotedprintabledecoder.ts b/src/app/converter/quotedprintabledecoder.ts index 7196f65..025a8cb 100644 --- a/src/app/converter/quotedprintabledecoder.ts +++ b/src/app/converter/quotedprintabledecoder.ts @@ -2,6 +2,7 @@ import {Converter} from "./converter"; import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; export class QuotedPrintableDecoder implements Converter { + constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) { } diff --git a/src/app/converter/quotedprintableencoder.ts b/src/app/converter/quotedprintableencoder.ts index 5dfb386..cd7425d 100644 --- a/src/app/converter/quotedprintableencoder.ts +++ b/src/app/converter/quotedprintableencoder.ts @@ -2,6 +2,7 @@ import {Converter} from "./converter"; import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; export class QuotedPrintableEncoder implements Converter { + constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) { } diff --git a/app/converter/utf8decoder.ts b/src/app/converter/utf8decoder.ts similarity index 99% rename from app/converter/utf8decoder.ts rename to src/app/converter/utf8decoder.ts index 2dde0a9..58ca580 100644 --- a/app/converter/utf8decoder.ts +++ b/src/app/converter/utf8decoder.ts @@ -2,6 +2,7 @@ import {Converter} from "./converter"; import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; export class UTF8Decoder implements Converter { + constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) { } diff --git a/app/converter/utf8encoder.ts b/src/app/converter/utf8encoder.ts similarity index 99% rename from app/converter/utf8encoder.ts rename to src/app/converter/utf8encoder.ts index 0e03824..660da6c 100644 --- a/app/converter/utf8encoder.ts +++ b/src/app/converter/utf8encoder.ts @@ -2,6 +2,7 @@ import {Converter} from "./converter"; import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; export class UTF8Encoder implements Converter { + constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) { }