[svn:parrot] r46382 - in trunk: src/pmc t/pmc

plobsing at svn.parrot.org plobsing at svn.parrot.org
Fri May 7 06:34:03 UTC 2010


Author: plobsing
Date: Fri May  7 06:34:03 2010
New Revision: 46382
URL: https://trac.parrot.org/parrot/changeset/46382

Log:
update String.trans to work in immutable strings style

Modified:
   trunk/src/pmc/string.pmc
   trunk/t/pmc/string.t

Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc	Fri May  7 06:16:56 2010	(r46381)
+++ trunk/src/pmc/string.pmc	Fri May  7 06:34:03 2010	(r46382)
@@ -689,17 +689,19 @@
         unsigned char *p;
         INTVAL        *tr_data;
         INTVAL         i;
+        STRING        *dest;
 
         const INTVAL len = Parrot_str_byte_length(INTERP, src);
 
         if (!len)
-            RETURN(void);
+            RETURN(STRING src);
 
         if (src->charset != Parrot_ascii_charset_ptr)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_ENCODING,
                 "Can't translate non-ascii");
 
-        p = (unsigned char *)(src->strstart);
+        dest = Parrot_str_clone(INTERP, src);
+        p = (unsigned char *)(dest->strstart);
         /* TODO verify trans table */
 
         GETATTR_FixedIntegerArray_int_array(INTERP, table, tr_data);
@@ -709,6 +711,9 @@
             if (ch)
                 *p = ch;
         }
+
+        dest->hashval = 0; /* hash is invalid */
+        RETURN(STRING dest);
     }
 
 /*

Modified: trunk/t/pmc/string.t
==============================================================================
--- trunk/t/pmc/string.t	Fri May  7 06:16:56 2010	(r46381)
+++ trunk/t/pmc/string.t	Fri May  7 06:34:03 2010	(r46382)
@@ -20,7 +20,7 @@
 .sub main :main
     .include 'test_more.pir'
 
-    plan(166)
+    plan(167)
 
     set_or_get_strings()
     setting_integers()
@@ -814,9 +814,10 @@
     is( el, 256, 'elements' )
 
     $P0 = new ['String']
-    $P0.'trans'(s, tr_00)
+    t = $P0.'trans'(s, tr_00)
 
-    is( s, 'TAACGSTAACGS', 'trans' )
+    is( t, 'TAACGSTAACGS', 'trans' )
+    is( s, 'atugcsATUGCS', "trans doesn't touch source string")
 .end
 
 # create tr table at compile-time


More information about the parrot-commits mailing list