On 1/15/12 8:23 AM, Jos van Uden wrote:
import std.conv, std.traits, std.ascii;
S rot13(S)(S s) if (isSomeString!S) {
return rot(s, 13);
}
S rot(S)(S s, int key) if (isSomeString!S) {
dchar[] r = new dchar[s.length];
foreach (i, dchar c; s) {
if (isLower(c))
c = ((c - 'a' + key) % 26 + 'a');
else if (isUpper(c))
c = ((c - 'A' + key) % 26 + 'A');
r[i] = c;
}
return to!S(r);
}
---
still learning this stuff, feel free to correct or improve
Jos
Thanks! Well, we don't have yet the javascript that rotates the
examples. Would anyone be interested to work on that?
Andrei