develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35553 - in branches/strings/pseudocode: . t

From:
simon
Date:
January 14, 2009 13:33
Subject:
[svn:parrot] r35553 - in branches/strings/pseudocode: . t
Message ID:
20090114213257.BA8E6CB9AE@x12.develooper.com
Author: simon
Date: Wed Jan 14 13:32:56 2009
New Revision: 35553

Modified:
   branches/strings/pseudocode/ParrotString.pm
   branches/strings/pseudocode/t/create.t

Log:
Finish copying the function signatures into the Perl code, now time to implement them all.


Modified: branches/strings/pseudocode/ParrotString.pm
==============================================================================
--- branches/strings/pseudocode/ParrotString.pm	(original)
+++ branches/strings/pseudocode/ParrotString.pm	Wed Jan 14 13:32:56 2009
@@ -22,18 +22,13 @@
 class ParrotEncoding::UTF32  {  };
 class ParrotEncoding::EBCDIC {  };
 class ParrotEncoding::Byte   {
-    method string_iterate ($str, $callback, $parameter) {
+    method string_grapheme_iterate ($str, $callback, $parameter) {
         for (0..$str.bufused-1) {
             $callback($str.buffer.[$_], $parameter);
         }
     }
 };
 
-sub Parrot_string_grapheme_copy ($src, $dst) { ... } 
-
-sub Parrot_string_set($src, $dst) { 
-    return Parrot_string_reuse_COW($src, $dst); # Isn't it?
-} 
 
 ## COW stuff
 sub Parrot_string_new_COW($src) { ... }
@@ -45,6 +40,9 @@
     $src.flags +&= +^ StringCOW;
     return $src;
 }
+sub Parrot_string_set($src, $dst) { 
+    return Parrot_string_reuse_COW($src, $dst); # Isn't it?
+} 
 
 ## String operations
 
@@ -77,9 +75,26 @@
     }
 }
 
-sub Parrot_string_length($str) {
+sub Parrot_string_grapheme_length($str) {
     # This code written funny to be a bit more C-like
     my $data = 0; my $callback = sub ($char, $data is rw) { $data++ };
-    $str.encoding.string_iterate($str, $callback, $data);
+    $str.encoding.string_grapheme_iterate($str, $callback, $data);
     return $data;
 }
+
+sub Parrot_string_byte_length($str) { return $str.strlen }
+
+sub Parrot_string_index($str, $index) { ... }
+sub Parrot_string_grapheme_index($str, $index) { ... }
+sub Parrot_string_find_substr($str, $substr) { ... }
+
+sub Parrot_string_copy($src, $dst) { ... }
+sub Parrot_string_grapheme_copy ($src, $dst) { ... } 
+sub Parrot_string_repeat($src, $reps) { ... }
+sub Parrot_string_substr($src, $offset, $len) { ... }
+sub Parrot_string_grapheme_substr($src, $offset, $len) { ... }
+sub Parrot_string_replace($src, $offset, $len, $replacement) { ... }
+sub Parrot_string_grapheme_replace($src, $offset, $len, $replacement) { ... }
+sub Parrot_string_chopn($src, $count) { ... }
+sub Parrot_string_chopn_inplace($src, $count) { ... }
+sub Parrot_string_grapheme_chopn($src, $count) { ... }

Modified: branches/strings/pseudocode/t/create.t
==============================================================================
--- branches/strings/pseudocode/t/create.t	(original)
+++ branches/strings/pseudocode/t/create.t	Wed Jan 14 13:32:56 2009
@@ -1,7 +1,8 @@
 use Test;
 use ParrotString;
-plan 2;
+plan 3;
 
 my $str = Parrot_string_new_init("abcdef", 4, ParrotCharset::ASCII, ParrotEncoding::Byte);
 ok($str.charset ~~ ParrotCharset::ASCII, "Charset set properly");
-is(Parrot_string_length($str), 4, "String length correct");
+is(Parrot_string_grapheme_length($str), 4, "String length correct");
+is(Parrot_string_byte_length($str), 4, "String length correct");



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About