Permalink
Browse files

add string flip() method and function and enable 13 spectests

  • Loading branch information...
mberends committed Apr 15, 2011
1 parent 4b205f2 commit 9e6dc8bdc19d8f3b0fb295e732789dab0d684266
Showing with 15 additions and 4 deletions.
  1. +1 −0 lib/CLRBackend.cs
  2. +6 −4 lib/CORE.setting
  3. +6 −0 lib/Utils.cs
  4. +1 −0 src/CgOp.pm6
  5. +1 −0 t/spectest.data
View
@@ -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);
View
@@ -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) }
@@ -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.
View
@@ -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);
+ }
}
}
View
@@ -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", @_) }
View
@@ -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

0 comments on commit 9e6dc8b

Please sign in to comment.