split quotedprintable and utf8 converters
This commit is contained in:
parent
242d733b01
commit
1835634d6c
5 changed files with 52 additions and 2 deletions
|
@ -15,7 +15,7 @@ export class QuotedPrintableDecoder implements Converter {
|
||||||
|
|
||||||
convert(input:string):string {
|
convert(input:string):string {
|
||||||
try {
|
try {
|
||||||
return this.nativeLibraryWrapperService.utf8.decode(this.nativeLibraryWrapperService.quotedPrintable.decode(input));
|
return this.nativeLibraryWrapperService.quotedPrintable.decode(input);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error("The input can not be interpreted as quoted-printable. May be corrupt?");
|
throw new Error("The input can not be interpreted as quoted-printable. May be corrupt?");
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,6 @@ export class QuotedPrintableEncoder implements Converter {
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(input:string):string {
|
convert(input:string):string {
|
||||||
return this.nativeLibraryWrapperService.quotedPrintable.encode(this.nativeLibraryWrapperService.utf8.encode(input));
|
return this.nativeLibraryWrapperService.quotedPrintable.encode(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
23
app/converter/utf8decoder.ts
Normal file
23
app/converter/utf8decoder.ts
Normal file
|
@ -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?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
app/converter/utf8encoder.ts
Normal file
23
app/converter/utf8encoder.ts
Normal file
|
@ -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?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,8 @@ import {QuotedPrintableEncoder} from "./converter/quotedprintableencoder";
|
||||||
import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service";
|
import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service";
|
||||||
import {PunycodeEncoder} from "./converter/punycodeencoder";
|
import {PunycodeEncoder} from "./converter/punycodeencoder";
|
||||||
import {PunycodeDecoder} from "./converter/punycodedecoder";
|
import {PunycodeDecoder} from "./converter/punycodedecoder";
|
||||||
|
import {UTF8Encoder} from "./converter/utf8encoder";
|
||||||
|
import {UTF8Decoder} from "./converter/utf8decoder";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConverterRegistryService {
|
export class ConverterRegistryService {
|
||||||
|
@ -56,6 +58,8 @@ export class ConverterRegistryService {
|
||||||
this.registerConverter(new BinToDecConverter());
|
this.registerConverter(new BinToDecConverter());
|
||||||
this.registerConverter(new PunycodeEncoder(this.wrapper));
|
this.registerConverter(new PunycodeEncoder(this.wrapper));
|
||||||
this.registerConverter(new PunycodeDecoder(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 {
|
private registerConverter(converter:Converter):void {
|
||||||
|
|
Loading…
Reference in a new issue