Merge branch 'split-quotedprintable-and-utf8' into 'develop'

Split quotedprintable and utf8

Closes #14

See merge request !12
This commit is contained in:
Manuel Friedli 2017-03-15 00:14:19 +01:00
commit 01bb4af7d1
5 changed files with 56 additions and 2 deletions

View file

@ -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?");
}

View file

@ -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);
}
}

View file

@ -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?");
}
}
}

View file

@ -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?");
}
}
}

View file

@ -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 {