Skip to content

Commit

Permalink
First stab at char indexing of NFG strings.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/branches/strings@36070 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
simon committed Jan 27, 2009
1 parent 4164b5b commit 3c3c626
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 14 additions & 1 deletion pseudocode/ParrotEncoding/ParrotNative.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,7 +42,20 @@ class ParrotEncoding::ParrotNative {
# graphemes and graphemes are composed of multiple characters - # graphemes and graphemes are composed of multiple characters -
# this could be improved with caching later but we will # this could be improved with caching later but we will
# do it the slow stupid way for now # do it the slow stupid way for now
... my $i = $index;
my $grapheme_index = 0;
my $c;
while ($i >= 0) {
my $g = self.grapheme_at_index($str, $grapheme_index++);
#say "i is "~$i~" and grapheme is "~$g.perl;
for (@( $g )) {
#say " Char is "~$_~" and i is "~$i;
return $_ if $i == 0;
$i--;
}
}
Parrot_debug_string($str);
die "char_at_index walked off the end of the string";
} }


method grapheme_at_index($str, $index) { method grapheme_at_index($str, $index) {
Expand Down
7 changes: 5 additions & 2 deletions pseudocode/ParrotString.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ sub Parrot_string_byte_equal($one, $two) {
sub Parrot_string_character_equal($one, $two) { sub Parrot_string_character_equal($one, $two) {
my $l = Parrot_string_length($one); my $l = Parrot_string_length($one);
return 0 if $l != Parrot_string_length($two); return 0 if $l != Parrot_string_length($two);
for (0.. $l-1) { for (0.. $l-1) -> $char {
return 0 if Parrot_string_index($one, $_) != Parrot_string_index($two, $_); my $savechar = 0 + $char; # Work around rakudo weirdness
my $a = Parrot_string_index($one, $char);
my $b = Parrot_string_index($two, $savechar);
return 0 if $a != $b;
} }
return 1; return 1;
} }

0 comments on commit 3c3c626

Please sign in to comment.