Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add string flip() method and function and enable 13 spectests
  • Loading branch information
mberends committed Apr 15, 2011
1 parent 4b205f2 commit 9e6dc8b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/CLRBackend.cs
Expand Up @@ -3121,6 +3121,7 @@ class NamProcessor {
thandlers["str_substring"] = Methody(null, Tokens.Builtins.GetMethod("LaxSubstring2"));
thandlers["str_tolower"] = Methody(null, Tokens.String.GetMethod("ToLowerInvariant"));
thandlers["str_toupper"] = Methody(null, Tokens.String.GetMethod("ToUpperInvariant"));
thandlers["str_flip"] = Methody(null, typeof(Utils).GetMethod("StrFlip"));
thandlers["strcmp"] = Methody(null, Tokens.String.GetMethod("CompareOrdinal", new Type[] { Tokens.String, Tokens.String }));
thandlers["strbuf_new"] = Constructy(typeof(StringBuilder).GetConstructor(new Type[0]));
thandlers["strbuf_seal"] = Methody(null, Tokens.Object_ToString);
Expand Down
10 changes: 6 additions & 4 deletions lib/CORE.setting
Expand Up @@ -168,8 +168,9 @@ my class Cool {
method say() { (~self).say }
method chars() { chars(self) }
method substr($x,$y) { substr(self,$x,$y) }
method lc() { Q:CgOp { (box Str (str_tolower (obj_getstr {self}))) }}
method uc() { Q:CgOp { (box Str (str_toupper (obj_getstr {self}))) }}
method lc() { Q:CgOp { (box Str (str_tolower (obj_getstr {self}))) }}
method uc() { Q:CgOp { (box Str (str_toupper (obj_getstr {self}))) }}
method flip() { Q:CgOp { (box Str (str_flip (obj_getstr {self}))) }}
method ucfirst() { ucfirst(self) }
method lcfirst() { lcfirst(self) }
Expand Down Expand Up @@ -356,8 +357,9 @@ sub infix:<le>($s1, $s2) { $s1 le $s2 }
sub infix:<lt>($s1, $s2) { $s1 lt $s2 }
sub infix:<eq>($s1, $s2) { $s1 eq $s2 }
sub infix:<ne>($s1, $s2) { $s1 ne $s2 }
sub lc($s) { (~$s).lc }
sub uc($s) { (~$s).uc }
sub lc($s) { (~$s).lc }
sub uc($s) { (~$s).uc }
sub flip($s) { (~$s).flip }
sub lcfirst($o) { my $s = ~$o; lc(substr($s,0,1)) ~ substr($s,1) }
sub ucfirst($o) { my $s = ~$o; uc(substr($s,0,1)) ~ substr($s,1) }
# this one is horribly wrong and only handles the ref eq case.
Expand Down
6 changes: 6 additions & 0 deletions lib/Utils.cs
Expand Up @@ -494,6 +494,12 @@ public class Utils {
public static bool S2NB(string n, out double o) {
return double.TryParse(n, NumberStyles.Float, CultureInfo.InvariantCulture, out o);
}

public static string StrFlip(string n) {
char[] tempCharArray = n.ToCharArray();
Array.Reverse(tempCharArray);
return new string(tempCharArray);
}
}
}

1 change: 1 addition & 0 deletions src/CgOp.pm6
Expand Up @@ -215,6 +215,7 @@ method strbuf_new (*@_) { self._cgop("strbuf_new", @_) }
method strbuf_seal (*@_) { self._cgop("strbuf_seal", @_) }
method str_chr (*@_) { self._cgop("str_chr", @_) }
method strcmp (*@_) { self._cgop("strcmp", @_) }
method str_flip (*@_) { self._cgop("str_flip", @_) }
method str_length (*@_) { self._cgop("str_length", @_) }
method str_substring (*@_) { self._cgop("str_substring", @_) }
method str_tolower (*@_) { self._cgop("str_tolower", @_) }
Expand Down
1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -95,6 +95,7 @@ S32-hash/pairs.t
S32-num/power.t
S32-str/append.t
S32-str/bool.t
S32-str/flip.t
S32-str/lc.t
S32-str/lines.t
S32-str/pos.t
Expand Down

0 comments on commit 9e6dc8b

Please sign in to comment.