From 85648371b452f94e255ba76c19c41d7edb2d5a85 Mon Sep 17 00:00:00 2001 From: Solomon Foster Date: Mon, 15 Feb 2010 17:57:03 -0500 Subject: [PATCH 1/2] Add trim-leading and trim-trailing, and reimplement trim in terms of them. --- src/core/Any-str.pm | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/Any-str.pm b/src/core/Any-str.pm index a30694c859e..88a339b995d 100644 --- a/src/core/Any-str.pm +++ b/src/core/Any-str.pm @@ -181,16 +181,29 @@ augment class Any { (~self).split('').reverse().join; } - # TODO: signature not fully specced in S32 yet - multi method trim() is export { - # (~self).subst(/(^\s+)|(\s+$)/, "", :g) - if self ~~ /^\s*(.*?)\s*$/ { + # Not yet spec'd, I expect it will be renamed + multi method trim-leading() is export { + if self ~~ /^\s*(\S.*)$/ { + ~$/[0]; + } else { + self; + } + } + + # Not yet spec'd, I expect it will be renamed + multi method trim-trailing() is export { + if self ~~ /^(.*\S)\s*$/ { ~$/[0]; } else { self; } } + # TODO: signature not fully specced in S32 yet + multi method trim() is export { + self.trim-leading.trim-trailing; + } + multi method words(Int $limit = *) { self.comb( / \S+ /, $limit ); } From 4246be20f4d32663c8f8fb3f98b36b8f7c444a7f Mon Sep 17 00:00:00 2001 From: Solomon Foster Date: Mon, 15 Feb 2010 17:57:18 -0500 Subject: [PATCH 2/2] Turn on trim.t. --- t/spectest.data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/spectest.data b/t/spectest.data index 711dae6ad7c..801a31df1e9 100644 --- a/t/spectest.data +++ b/t/spectest.data @@ -478,7 +478,7 @@ S32-str/split-simple2.t # CHEAT! simplified version of split-simple.t # S32-str/split.t # S32-str/sprintf.t # S32-str/substr.t -# S32-str/trim.t +S32-str/trim.t S32-str/ucfirst.t S32-str/uc.t # icu # S32-str/unpack.t