Skip to content
Browse files

Implement Str.chom?p and sub form

  • Loading branch information...
1 parent d96efe7 commit 2d9ebd6056fa254d0654303f31391ca94bbdd963 @sorear committed
Showing with 19 additions and 3 deletions.
  1. +17 −3 lib/CORE.setting
  2. +2 −0 t/spectest.data
View
20 lib/CORE.setting
@@ -170,6 +170,18 @@ my class Cool {
}
method say() { (~self).say }
method chars() { chars(self) }
+ method bytes() { chars(self) * 2 }
+ method chomp() {
+ my $s = ~self;
+ my $l = chars($s);
+ --$l if $l && substr($s, $l-1, 1) eq "\x0A";
+ --$l if $l && substr($s, $l-1, 1) eq "\x0D";
+ substr($s,0,$l);
+ }
+ method chop() {
+ my $s = ~self;
+ substr($s, 0, chars($s) - 1)
+ }
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}))) }}
@@ -374,9 +386,11 @@ 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 flip($s) { (~$s).flip }
+sub lc($s) { (~$s).lc }
+sub uc($s) { (~$s).uc }
+sub chop($s) { (~$s).chop }
+sub chomp($s) { (~$s).chomp }
+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
2 t/spectest.data
@@ -97,6 +97,8 @@ S32-hash/pairs.t
S32-num/power.t
S32-str/append.t
S32-str/bool.t
+S32-str/chomp.t
+S32-str/chop.t
S32-str/flip.t
S32-str/lc.t
S32-str/lines.t

0 comments on commit 2d9ebd6

Please sign in to comment.
Something went wrong with that request. Please try again.