converter/src/app/converter/utf8encoder.ts

25 lines
590 B
TypeScript
Raw Normal View History

2017-04-15 19:04:49 +02:00
import {Converter} from './converter';
import {NativeLibraryWrapperService} from '../nativelibrarywrapper.service';
export class UTF8Encoder implements Converter {
2017-03-15 00:09:57 +01:00
constructor(private nativeLibraryWrapperService: NativeLibraryWrapperService) {
}
getDisplayname(): string {
2017-04-15 19:04:49 +02:00
return 'Encode UTF-8';
}
getId(): string {
2017-04-15 19:04:49 +02:00
return 'encodeutf8';
}
convert(input: string): string {
try {
return this.nativeLibraryWrapperService.utf8.encode(input);
} catch (error) {
2017-04-15 19:04:49 +02:00
throw new Error('The input can not be encoded as UTF-8. May be corrupt?');
}
}
}