forked from pmichaud/pmtcl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
break out [string] in anticipation of implementing the rest of the en…
…semble command.
- Loading branch information
Showing
4 changed files
with
45 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
our sub string($cmd, *@args) { | ||
if $cmd eq 'toupper' { | ||
return pir::upcase(@args[0]); | ||
} elsif $cmd eq 'compare' { | ||
@args.shift; # assuming -nocase here. | ||
my $s1 := pir::upcase(@args[0]); | ||
my $s2 := pir::upcase(@args[1]); | ||
if ($s1 eq $s2) { | ||
return 0; | ||
} elsif ($s1 lt $s2) { | ||
return -1; | ||
} else { | ||
return 1; | ||
} | ||
} | ||
} | ||
|
||
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 | ||
}; | ||
} | ||
} |