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 ); } diff --git a/t/spectest.data b/t/spectest.data index f935c3c5c00..17f82236472 100644 --- a/t/spectest.data +++ b/t/spectest.data @@ -482,7 +482,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