Author: simon
Date: Tue Jan 27 14:57:17 2009
New Revision: 36070
Modified:
branches/strings/pseudocode/ParrotEncoding/ParrotNative.pm
branches/strings/pseudocode/ParrotString.pm
Log:
First stab at char indexing of NFG strings.
Modified: branches/strings/pseudocode/ParrotEncoding/ParrotNative.pm
==============================================================================
--- branches/strings/pseudocode/ParrotEncoding/ParrotNative.pm (original)
+++ branches/strings/pseudocode/ParrotEncoding/ParrotNative.pm Tue Jan 27 14:57:17 2009
@@ -42,7 +42,20 @@
# graphemes and graphemes are composed of multiple characters -
# this could be improved with caching later but we will
# 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) {
Modified: branches/strings/pseudocode/ParrotString.pm
==============================================================================
--- branches/strings/pseudocode/ParrotString.pm (original)
+++ branches/strings/pseudocode/ParrotString.pm Tue Jan 27 14:57:17 2009
@@ -124,8 +124,11 @@
sub Parrot_string_character_equal($one, $two) {
my $l = Parrot_string_length($one);
return 0 if $l != Parrot_string_length($two);
- for (0.. $l-1) {
- return 0 if Parrot_string_index($one, $_) != Parrot_string_index($two, $_);
+ for (0.. $l-1) -> $char {
+ 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;
}