Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:rakudo/rakudo
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Mar 17, 2009
2 parents b117c67 + 39b1290 commit 75cd4a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 95 deletions.
96 changes: 1 addition & 95 deletions src/builtins/any-str.pir
Expand Up @@ -23,7 +23,7 @@ the size of that file down and to emphasize their generic,
.namespace []
.sub 'onload' :anon :init :load
$P0 = get_hll_namespace ['Any']
'!EXPORT'('capitalize,chomp,chars,:d,:e,:f,index,lc,rindex,ord,substr,trim,uc,unpack', 'from'=>$P0)
'!EXPORT'('capitalize,chomp,chars,:d,:e,:f,index,lc,rindex,ord,substr,trim', 'from'=>$P0)
.end
Expand Down Expand Up @@ -982,100 +982,6 @@ 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 'Str'
retv = tmps

.return(retv)
.end

=item unpack

our List multi Str::unpack ( Str $template, Str $packval )

Takes a string and expands it out into a list of values.

=cut

.namespace['Any']
.sub 'unpack' :multi(_, _)
.param string template
.param string packval
.local pmc retv
.local int len

retv = new 'List'

len = length template
if len == 0 goto done

.local int pos
.local int packpos
pos = 0
packpos = 0

next_directive:
$S0 = substr template, pos, 1
if $S0 == 'A' goto ascii
if $S0 == 'x' goto skip
if $S0 == ' ' goto space
goto fail

ascii:
pos += 1
if pos == len goto fail
$S0 = substr template, pos, 1
$I0 = ord $S0
$I0 -= 48
$S1 = substr packval, packpos, $I0
retv.'push'($S1)
packpos += $I0
pos += 1
if pos == len goto done
goto next_directive

skip:
pos += 1
if pos == len goto fail
$S0 = substr template, pos, 1
$I0 = ord $S0
$I0 -= 48
$S1 = substr packval, packpos, $I0
packpos += $I0
pos += 1
if pos == len goto done
goto next_directive

space:
pos += 1
if pos == len goto done
goto next_directive

done:
.return(retv)

fail:
$P0 = new 'Failure'
.return ($P0)
.end

# Local Variables:
# mode: pir
# fill-column: 100
Expand Down
24 changes: 24 additions & 0 deletions src/setting/Any-str.pm
Expand Up @@ -70,6 +70,16 @@ class Any is also {
}
}
}

multi method uc() is export {
return Q:PIR {
$S0 = self
upcase $S0
$P0 = new 'Str'
$P0 = $S0
%r = $P0
}
}
our Str multi method ucfirst is export {
self gt '' ?? self.substr(0,1).uc ~ self.substr(1) !! ""
Expand All @@ -81,4 +91,18 @@ sub split($delimiter, $target) {
$target.split($delimiter);
}
sub unpack($template, $target) {
$template.trans(/\s+/ => '') ~~ / ((<[Ax]>)(\d+))* /
or return (); # unknown syntax
my $pos = 0;
return gather for $0.values -> $chunk {
my ($operation, $count) = $chunk.[0, 1];
given $chunk.[0] {
when 'A' { take $target.substr($pos, $count); }
when 'x' { } # just skip
}
$pos += $count;
}
}
# vim: ft=perl6

0 comments on commit 75cd4a8

Please sign in to comment.