Merge branch 'feature/rot-13' of manuel/converter into develop

This commit is contained in:
Manuel Friedli 2018-08-31 22:00:36 +02:00 committed by Gitea
commit 26e089cb33
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,25 @@
import {Converter} from './converter';
export class ROT13Converter implements Converter {
getDisplayname(): string {
return 'Perform ROT-13';
}
getId(): string {
return 'rot13convert';
}
convert(input: string): string {
try {
const inChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const outChars = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm';
const translate = c => {
const charIndex = inChars.indexOf(c);
return charIndex > -1 ? outChars[charIndex] : c;
};
return input.split('').map(translate).join('');
} catch (exception) {
throw new Error('Could not perform ROT-13 conversion. Maybe corrupt input?');
}
}
}

View file

@ -19,6 +19,7 @@ import {PunycodeEncoder} from './converter/punycodeencoder';
import {PunycodeDecoder} from './converter/punycodedecoder';
import {UTF8Encoder} from './converter/utf8encoder';
import {UTF8Decoder} from './converter/utf8decoder';
import {ROT13Converter} from './converter/rot13converter';
@Injectable()
export class ConverterRegistryService {
@ -60,6 +61,7 @@ export class ConverterRegistryService {
this.registerConverter(new PunycodeDecoder(this.wrapper));
this.registerConverter(new UTF8Encoder(this.wrapper));
this.registerConverter(new UTF8Decoder(this.wrapper));
this.registerConverter(new ROT13Converter());
}
private registerConverter(converter: Converter): void {