Merge branch 'feature/rot-13' of manuel/converter into develop
This commit is contained in:
commit
26e089cb33
2 changed files with 27 additions and 0 deletions
25
src/app/converter/rot13converter.ts
Normal file
25
src/app/converter/rot13converter.ts
Normal 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?');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ import {PunycodeEncoder} from './converter/punycodeencoder';
|
||||||
import {PunycodeDecoder} from './converter/punycodedecoder';
|
import {PunycodeDecoder} from './converter/punycodedecoder';
|
||||||
import {UTF8Encoder} from './converter/utf8encoder';
|
import {UTF8Encoder} from './converter/utf8encoder';
|
||||||
import {UTF8Decoder} from './converter/utf8decoder';
|
import {UTF8Decoder} from './converter/utf8decoder';
|
||||||
|
import {ROT13Converter} from './converter/rot13converter';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConverterRegistryService {
|
export class ConverterRegistryService {
|
||||||
|
@ -60,6 +61,7 @@ export class ConverterRegistryService {
|
||||||
this.registerConverter(new PunycodeDecoder(this.wrapper));
|
this.registerConverter(new PunycodeDecoder(this.wrapper));
|
||||||
this.registerConverter(new UTF8Encoder(this.wrapper));
|
this.registerConverter(new UTF8Encoder(this.wrapper));
|
||||||
this.registerConverter(new UTF8Decoder(this.wrapper));
|
this.registerConverter(new UTF8Decoder(this.wrapper));
|
||||||
|
this.registerConverter(new ROT13Converter());
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerConverter(converter: Converter): void {
|
private registerConverter(converter: Converter): void {
|
||||||
|
|
Loading…
Reference in a new issue