diff --git a/src/app/converter/quotedprintabledecoder.ts b/src/app/converter/quotedprintabledecoder.ts index d998038..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) { } @@ -15,7 +16,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/src/app/converter/quotedprintableencoder.ts b/src/app/converter/quotedprintableencoder.ts index 048dbc6..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) { } @@ -14,6 +15,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/src/app/converter/utf8decoder.ts b/src/app/converter/utf8decoder.ts new file mode 100644 index 0000000..58ca580 --- /dev/null +++ b/src/app/converter/utf8decoder.ts @@ -0,0 +1,24 @@ +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/src/app/converter/utf8encoder.ts b/src/app/converter/utf8encoder.ts new file mode 100644 index 0000000..660da6c --- /dev/null +++ b/src/app/converter/utf8encoder.ts @@ -0,0 +1,24 @@ +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/src/app/converterregistry.service.ts b/src/app/converterregistry.service.ts index af6e30b..677520b 100644 --- a/src/app/converterregistry.service.ts +++ b/src/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 {