Merge branch 'split-quotedprintable-and-utf8' into 'develop'
Split quotedprintable and utf8 Closes #14 See merge request !12
This commit is contained in:
commit
01bb4af7d1
5 changed files with 56 additions and 2 deletions
|
@ -2,6 +2,7 @@ import {Converter} from "./converter";
|
||||||
import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service";
|
import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service";
|
||||||
|
|
||||||
export class QuotedPrintableDecoder implements Converter {
|
export class QuotedPrintableDecoder implements Converter {
|
||||||
|
|
||||||
constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) {
|
constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +16,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?");
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import {Converter} from "./converter";
|
||||||
import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service";
|
import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service";
|
||||||
|
|
||||||
export class QuotedPrintableEncoder implements Converter {
|
export class QuotedPrintableEncoder implements Converter {
|
||||||
|
|
||||||
constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) {
|
constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +15,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
24
src/app/converter/utf8decoder.ts
Normal file
24
src/app/converter/utf8decoder.ts
Normal 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?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
src/app/converter/utf8encoder.ts
Normal file
24
src/app/converter/utf8encoder.ts
Normal 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?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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