Navigation Menu

Skip to content

Commit

Permalink
Move string_trim into our ``private'' namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Nov 30, 2009
1 parent efe5134 commit c916eb0
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions src/PmTcl/Commands.pm
Expand Up @@ -66,9 +66,9 @@ our sub catch($code, $varname?) {


our sub concat(*@args) {
my $result := @args ?? string_trim(@args.shift) !! '';
my $result := @args ?? _tcl::string_trim(@args.shift) !! '';
while @args {
$result := $result ~ ' ' ~ string_trim(@args.shift);
$result := $result ~ ' ' ~ _tcl::string_trim(@args.shift);
}
$result;
}
Expand Down Expand Up @@ -381,29 +381,6 @@ our sub string($cmd, *@args) {
}
}

our sub string_trim($string) {
Q:PIR {
.include 'cclass.pasm'
.local string str
$P0 = find_lex '$string'
str = $P0
.local int lpos, rpos
rpos = length str
lpos = find_not_cclass .CCLASS_WHITESPACE, str, 0, rpos
rtrim_loop:
unless rpos > lpos goto rtrim_done
dec rpos
$I0 = is_cclass .CCLASS_WHITESPACE, str, rpos
if $I0 goto rtrim_loop
rtrim_done:
inc rpos
$I0 = rpos - lpos
$S0 = substr str, lpos, $I0
%r = box $S0
};
}


our sub switch ($string, *@args) {
unless @args {
pir::printerr("wrong # args: should be ``switch ?switches? string pattern body ... ?default body?''");
Expand Down Expand Up @@ -473,3 +450,27 @@ our sub while (*@args) {
our sub EXPAND($args) {
PmTcl::Grammar.parse($args, :rule<list>, :actions(PmTcl::Actions) ).ast;
}

module _tcl {
our sub string_trim($string) {
Q:PIR {
.include 'cclass.pasm'
.local string str
$P0 = find_lex '$string'
str = $P0
.local int lpos, rpos
rpos = length str
lpos = find_not_cclass .CCLASS_WHITESPACE, str, 0, rpos
rtrim_loop:
unless rpos > lpos goto rtrim_done
dec rpos
$I0 = is_cclass .CCLASS_WHITESPACE, str, rpos
if $I0 goto rtrim_loop
rtrim_done:
inc rpos
$I0 = rpos - lpos
$S0 = substr str, lpos, $I0
%r = box $S0
};
}
}

0 comments on commit c916eb0

Please sign in to comment.