2017-04-15 19:04:49 +02:00
|
|
|
import {Converter} from './converter';
|
|
|
|
import {NativeLibraryWrapperService} from '../nativelibrarywrapper.service';
|
2016-09-28 13:53:05 +02:00
|
|
|
|
|
|
|
export class UTF8Decoder implements Converter {
|
2017-03-15 00:09:57 +01:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
constructor(private nativeLibraryWrapperService: NativeLibraryWrapperService) {
|
|
|
|
}
|
2016-09-28 13:53:05 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
getDisplayname(): string {
|
2017-04-15 19:04:49 +02:00
|
|
|
return 'Decode UTF-8';
|
2017-04-15 18:51:22 +02:00
|
|
|
}
|
2016-09-28 13:53:05 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
getId(): string {
|
2017-04-15 19:04:49 +02:00
|
|
|
return 'decodeutf8';
|
2017-04-15 18:51:22 +02:00
|
|
|
}
|
2016-09-28 13:53:05 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
convert(input: string): string {
|
|
|
|
try {
|
|
|
|
return this.nativeLibraryWrapperService.utf8.decode(input);
|
|
|
|
} catch (error) {
|
2017-04-15 19:04:49 +02:00
|
|
|
throw new Error('The input can not be interpreted a valid UTF-8 encoded string. May be corrupt?');
|
2016-09-28 13:53:05 +02:00
|
|
|
}
|
2017-04-15 18:51:22 +02:00
|
|
|
}
|
2016-09-28 13:53:05 +02:00
|
|
|
}
|