New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moving methods from Str.pir to any-str.pir #345
Comments
From @bacekHello. For consistency sake (and removing many dummy proxy methods) -- |
From @bacekstr_moving_methods.patchcommit be069166b765ed48e5e21df11498d32ece41b13d
Author: Vasily Chekalkin <bacek@bacek.com>
Date: Sat Sep 27 22:37:34 2008 +1000
Move many methods from Str.pir to any-str.pir
diff --git a/languages/perl6/src/builtins/any-str.pir b/languages/perl6/src/builtins/any-str.pir
index 5e20b48..2772cc4 100644
--- a/languages/perl6/src/builtins/any-str.pir
+++ b/languages/perl6/src/builtins/any-str.pir
@@ -21,7 +21,7 @@ the size of that file down and to emphasize their generic,
.namespace []
.sub 'onload' :anon :init :load
$P0 = get_hll_namespace ['Any']
- '!EXPORT'('chars ord index rindex substr', 'from'=>$P0)
+ '!EXPORT'('capitalize chop chars index lc lcfirst rindex ord substr uc ucfirst', 'from'=>$P0)
.end
@@ -30,12 +30,89 @@ the size of that file down and to emphasize their generic,
=cut
.namespace ['Any']
+
+=item capitalize
+
+ our Str multi Str::capitalize ( Str $string )
+
+Has the effect of first doing an C<lc> on the entire string, then performing a
+C<s:g/(\w+)/{ucfirst $1}/> on it.
+
+=cut
+
+.sub 'capitalize' :method
+ .local string tmps
+ .local string fchr
+ .local pmc retv
+ .local int len
+
+ retv = new 'Perl6Str'
+ tmps = self
+
+ len = length tmps
+ if len == 0 goto done
+
+ downcase tmps
+
+ .local int pos, is_ws, is_lc
+ pos = 0
+ goto first_char
+ next_grapheme:
+ if pos == len goto done
+ is_ws = is_cclass .CCLASS_WHITESPACE, tmps, pos
+ if is_ws goto ws
+ advance:
+ pos += 1
+ goto next_grapheme
+ ws:
+ pos += 1
+ first_char:
+ is_lc = is_cclass .CCLASS_LOWERCASE, tmps, pos
+ unless is_lc goto advance
+ $S1 = substr tmps, pos, 1
+ upcase $S1
+ substr tmps, pos, 1, $S1
+ ## the length may have changed after replacement, so measure it again
+ len = length tmps
+ goto advance
+ done:
+ retv = tmps
+ .return (retv)
+.end
+
.sub 'chars' :method :multi(_)
$S0 = self
$I0 = length $S0
.return ($I0)
.end
+
+=item chop
+
+ our Str method Str::chop ( Str $string: )
+
+Returns string with one Char removed from the end.
+
+=cut
+
+.sub 'chop' :method
+ .local string tmps
+ .local pmc retv
+ .local int len
+
+ retv = new 'Perl6Str'
+ tmps = self
+
+ len = length tmps
+ if len == 0 goto done
+ dec len
+ substr tmps,tmps, 0, len
+ done:
+ retv = tmps
+ .return(retv)
+.end
+
+
=item comb()
Partial implementation for now, returns a list of strings
@@ -110,6 +187,62 @@ Partial implementation for now, returns a list of strings
.return ($P0)
.end
+
+=item lc
+
+ our Str multi Str::lc ( Str $string )
+
+Returns the input string after converting each character to its lowercase
+form, if uppercase.
+
+=cut
+
+.sub 'lc' :method
+ .local string tmps
+ .local pmc retv
+
+ tmps = self
+ downcase tmps
+
+ retv = new 'Perl6Str'
+ retv = tmps
+
+ .return(retv)
+.end
+
+=item lcfirst
+
+ our Str multi Str::lcfirst ( Str $string )
+
+Like C<lc>, but only affects the first character.
+
+=cut
+
+.sub 'lcfirst' :method
+ .local string tmps
+ .local string fchr
+ .local pmc retv
+ .local int len
+
+ retv = new 'Perl6Str'
+ tmps = self
+
+ len = length tmps
+ if len == 0 goto done
+
+ substr fchr, tmps, 0, 1
+ downcase fchr
+
+ concat retv, fchr
+ substr tmps, tmps, 1
+ concat retv, tmps
+
+ done:
+ .return(retv)
+.end
+
+
+
=item match()
=cut
@@ -643,6 +776,62 @@ Partial implementation. The :g modifier on regexps doesn't work, for example.
.return ($I0)
.end
+
+=item uc
+
+ our Str multi Str::uc ( Str $string )
+
+Returns the input string after converting each character to its uppercase
+form, if lowercase. This is not a Unicode "titlecase" operation, but a
+full "uppercase".
+
+=cut
+
+.sub 'uc' :method :multi(_)
+ .local string tmps
+ .local pmc retv
+
+ tmps = self
+ upcase tmps
+
+ retv = new 'Perl6Str'
+ retv = tmps
+
+ .return(retv)
+.end
+
+=item ucfirst
+
+ our Str multi Str::ucfirst ( Str $string )
+
+Performs a Unicode "titlecase" operation on the first character of the string.
+
+=cut
+
+.sub 'ucfirst' :method
+ .local string tmps
+ .local string fchr
+ .local pmc retv
+ .local int len
+
+ retv = new 'Perl6Str'
+ tmps = self
+
+ len = length tmps
+ if len == 0 goto done
+
+ substr fchr, tmps, 0, 1
+ upcase fchr
+
+ concat retv, fchr
+ substr tmps, tmps, 1
+ concat retv, tmps
+
+ done:
+ .return(retv)
+.end
+
+
# Local Variables:
# mode: pir
# fill-column: 100
diff --git a/languages/perl6/src/classes/Str.pir b/languages/perl6/src/classes/Str.pir
index 65d8d98..3d4a8aa 100644
--- a/languages/perl6/src/classes/Str.pir
+++ b/languages/perl6/src/classes/Str.pir
@@ -46,134 +46,6 @@ as the Perl 6 C<Str> class.
.return(retv)
.end
-.sub lc :method
- .local string tmps
- .local pmc retv
-
- tmps = self
- downcase tmps
-
- retv = new 'Perl6Str'
- retv = tmps
-
- .return(retv)
-.end
-
-.sub uc :method
- .local string tmps
- .local pmc retv
-
- tmps = self
- upcase tmps
-
- retv = new 'Perl6Str'
- retv = tmps
-
- .return(retv)
-.end
-
-.sub lcfirst :method
- .local string tmps
- .local string fchr
- .local pmc retv
- .local int len
-
- retv = new 'Perl6Str'
- tmps = self
-
- len = length tmps
- if len == 0 goto done
-
- substr fchr, tmps, 0, 1
- downcase fchr
-
- concat retv, fchr
- substr tmps, tmps, 1
- concat retv, tmps
-
- done:
- .return(retv)
-.end
-
-.sub ucfirst :method
- .local string tmps
- .local string fchr
- .local pmc retv
- .local int len
-
- retv = new 'Perl6Str'
- tmps = self
-
- len = length tmps
- if len == 0 goto done
-
- substr fchr, tmps, 0, 1
- upcase fchr
-
- concat retv, fchr
- substr tmps, tmps, 1
- concat retv, tmps
-
- done:
- .return(retv)
-.end
-
-.sub capitalize :method
- .local string tmps
- .local string fchr
- .local pmc retv
- .local int len
-
- retv = new 'Perl6Str'
- tmps = self
-
- len = length tmps
- if len == 0 goto done
-
- downcase tmps
-
- .local int pos, is_ws, is_lc
- pos = 0
- goto first_char
- next_grapheme:
- if pos == len goto done
- is_ws = is_cclass .CCLASS_WHITESPACE, tmps, pos
- if is_ws goto ws
- advance:
- pos += 1
- goto next_grapheme
- ws:
- pos += 1
- first_char:
- is_lc = is_cclass .CCLASS_LOWERCASE, tmps, pos
- unless is_lc goto advance
- $S1 = substr tmps, pos, 1
- upcase $S1
- substr tmps, pos, 1, $S1
- ## the length may have changed after replacement, so measure it again
- len = length tmps
- goto advance
- done:
- retv = tmps
- .return (retv)
-.end
-
-.sub 'chop' :method
- .local string tmps
- .local pmc retv
- .local int len
-
- retv = new 'Perl6Str'
- tmps = self
-
- len = length tmps
- if len == 0 goto done
- dec len
- substr tmps,tmps, 0, len
- done:
- retv = tmps
- .return(retv)
-.end
=item perl()
@@ -254,111 +126,6 @@ Returns the identify value.
.include 'cclass.pasm'
-=item lc
-
- our Str multi Str::lc ( Str $string )
-
-Returns the input string after converting each character to its lowercase
-form, if uppercase.
-
-=cut
-
-.sub 'lc'
- .param string a
- .local pmc s
- s = new 'Perl6Str'
- s = a
- .return s.'lc'()
-.end
-
-
-=item lcfirst
-
- our Str multi Str::lcfirst ( Str $string )
-
-Like C<lc>, but only affects the first character.
-
-=cut
-
-.sub 'lcfirst'
- .param string a
- .local pmc s
- s = new 'Perl6Str'
- s = a
- .return s.'lcfirst'()
-.end
-
-
-=item uc
-
- our Str multi Str::uc ( Str $string )
-
-Returns the input string after converting each character to its uppercase
-form, if lowercase. This is not a Unicode "titlecase" operation, but a
-full "uppercase".
-
-=cut
-
-.sub 'uc'
- .param string a
- .local pmc s
- s = new 'Perl6Str'
- s = a
- .return s.'uc'()
-.end
-
-
-=item ucfirst
-
- our Str multi Str::ucfirst ( Str $string )
-
-Performs a Unicode "titlecase" operation on the first character of the string.
-
-=cut
-
-.sub 'ucfirst'
- .param string a
- .local pmc s
- s = new 'Perl6Str'
- s = a
- .return s.'ucfirst'()
-.end
-
-
-=item capitalize
-
- our Str multi Str::capitalize ( Str $string )
-
-Has the effect of first doing an C<lc> on the entire string, then performing a
-C<s:g/(\w+)/{ucfirst $1}/> on it.
-
-=cut
-
-.sub 'capitalize'
- .param string a
- .local pmc s
- s = new 'Perl6Str'
- s = a
- .return s.'capitalize'()
-.end
-
-=item chop
-
- our Str method Str::chop ( Str $string: )
-
-Returns string with one Char removed from the end.
-
-=cut
-
-.sub 'chop'
- .param string a
- .local pmc s
- s = new 'Perl6Str'
- s = a
- .return s.'chop'()
-.end
-
-
=item infix:===
Overridden for Str.
|
From @moritzThanks, applied as r31456. |
The RT System itself - Status changed from 'new' to 'open' |
@moritz - Status changed from 'open' to 'resolved' |
From @pmichaudOn Sat, Sep 27, 2008 at 05:44:43AM -0700, Vasily Chekalkin wrote:
This section of code would be much simpler (and more efficient)
PIR has a C<chop> opcode, perhaps we should use it? Pm |
@pmichaud - Status changed from 'resolved' to 'open' |
From @bacekPatrick R. Michaud wrote:
Definitely. But I just moved code around. Should I add TODO ticket for -- |
From @pmichaudOn Mon, Sep 29, 2008 at 01:53:44AM +1000, Vasily Chekalkin wrote:
Yes, please. And these are cleanups that someone should be able Pm |
From @bacekPatrick R. Michaud wrote:
Done. #59486 and #59490 -- |
From @moritzOn Tue Sep 30 16:30:57 2008, bacek wrote:
Since that was the last thing to do in this ticket I'm closing it now. |
@moritz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#59398 (status was 'resolved')
Searchable as RT59398$
The text was updated successfully, but these errors were encountered: