1Builtins.translate(3kaya) Kaya module reference Builtins.translate(3kaya)
2
3
4
6 Builtins::translate - Translate characters in a String
7
9 Void translate( var String s, Char(Char) rule )
10
12 s The string to translate
13
14 rule The rule to apply
15
17 Replace characters in a String in place, applying the translation func‐
18 tion to each character in turn.
19
20
21 Char rot13(Char c) {
22 if ((c >= 'A' && c <= 'M') ||
23 (c >= 'a' && c <= 'm')) {
24 return Char(c+13);
25 } else if ((c >= 'N' && c <= 'Z') ||
26 (c >= 'n' && c <= 'z')) {
27 return Char(c-13);
28 } else {
29 return c;
30 }
31 }
32
33 Void main() {
34 str = "Hello World";
35 translate(str, rot13);
36 // str = "Uryyb Jbeyq";
37 }
38
40 Kaya standard library by Edwin Brady, Chris Morris and others
41 (kaya@kayalang.org). For further information see http://kayalang.org/
42
44 The Kaya standard library is free software; you can redistribute it
45 and/or modify it under the terms of the GNU Lesser General Public
46 License (version 2.1 or any later version) as published by the Free
47 Software Foundation.
48
49
50
51Kaya December 2010 Builtins.translate(3kaya)