Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Two arg substr implementation #54

Closed p6rt closed 16 years ago

p6rt commented 16 years ago

Migrated from rt.perl.org#49900 (status was 'resolved')

Searchable as RT49900$

p6rt commented 16 years ago

From @avar

If the third argument is omitted the string's length in characters is inserted in its place.

$ ../../parrot perl6.pbc /var/src/v6/v6-KindaPerl6/t/kp6/23-str-substr.t 1..2 ok 1 ok 2

The patch also adds tests to t/01-sanity/07-substr.t

p6rt commented 16 years ago

From @avar

substr.patch ```diff Index: t/01-sanity/07-substr.t =================================================================== --- t/01-sanity/07-substr.t (revision 24949) +++ t/01-sanity/07-substr.t (working copy) @@ -1,9 +1,13 @@ use v6-alpha; -say "1..1"; +say "1..3"; my $string = "Pugs -- Perl6 User's Golfing System"; my $substr = substr $string, 8, 5; if $substr eq "Perl6" { say "ok 1" } else { say "not ok 1" } + +my $str = 'not ok '; +say substr( $str, 4 ) ~ "2"; +say substr( $str, 4 ), "3"; Index: src/builtins/string.pir =================================================================== --- src/builtins/string.pir (revision 24949) +++ src/builtins/string.pir (working copy) @@ -186,7 +186,16 @@ .sub 'substr' .param string x .param int start - .param int len + .param int len :optional + .param int has_len :opt_flag + .local pmc s + + if has_len goto end + s = new 'Perl6Str' + s = x + len = s.'chars'() + + end: $S0 = substr x, start, len .return ($S0) .end ```
p6rt commented 16 years ago

@particle - Status changed from 'new' to 'open'

p6rt commented 16 years ago

From @particle

applied as r24963. ~jerry

p6rt commented 16 years ago

@particle - Status changed from 'open' to 'resolved'