cvsuser 05/02/21 02:05:22
Modified: classes string.pmc
t/pmc string.t
Log:
add 2 missing string methods
Revision Changes Path
1.7 +20 -1 parrot/classes/string.pmc
Index: string.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/string.pmc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- string.pmc 12 Jan 2005 11:42:06 -0000 1.6
+++ string.pmc 21 Feb 2005 10:05:16 -0000 1.7
@@ -1,6 +1,6 @@
/*
Copyright: 2003 The Perl Foundation. All Rights Reserved.
-$Id: string.pmc,v 1.6 2005/01/12 11:42:06 leo Exp $
+$Id: string.pmc,v 1.7 2005/02/21 10:05:16 leo Exp $
=head1 NAME
@@ -625,6 +625,14 @@
Returns the integer value (ord) at C<*key>.
+=item C<void set_string_keyed(PMC *key, STRING *val)>
+
+Replace the string at C<key> with C<value>.
+
+=item C<void set_integer_keyed(PMC *key, INTVAL val)>
+
+Replace the string at C<key> with the chr of C<value>.
+
=cut
*/
@@ -641,6 +649,17 @@
return string_ord(INTERP, s, key_integer(INTERP, key));
}
+ void set_string_keyed(PMC* key, STRING *value) {
+ STRING *s = PMC_str_val(SELF);
+ INTVAL len = string_length(INTERP, value);
+ string_replace(INTERP, s, key_integer(INTERP, key), len, value, NULL);
+ }
+
+ void set_integer_keyed(PMC* key, INTVAL value) {
+ STRING *s = PMC_str_val(SELF);
+ STRING *c = string_chr(INTERP, (UINTVAL) value);
+ string_replace(INTERP, s, key_integer(INTERP, key), 1, c, NULL);
+ }
/*
=back
1.6 +22 -2 parrot/t/pmc/string.t
Index: string.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/string.t,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- string.t 31 Dec 2004 21:26:50 -0000 1.5
+++ string.t 21 Feb 2005 10:05:21 -0000 1.6
@@ -1,6 +1,6 @@
#! perl -w
# Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-# $Id: string.t,v 1.5 2004/12/31 21:26:50 scog Exp $
+# $Id: string.t,v 1.6 2005/02/21 10:05:21 leo Exp $
=head1 NAME
@@ -16,7 +16,7 @@
=cut
-use Parrot::Test tests => 32;
+use Parrot::Test tests => 34;
use Test::More; # Included for skip().
my $fp_equality_macro = <<'ENDOFMACRO';
@@ -1146,3 +1146,23 @@
CODE
Tacitus
OUTPUT
+
+output_is( <<'CODE', <<OUTPUT, "set P[x], i");
+ new P0, .String
+ set P0, "abcdef\n"
+ set P0[2], 65
+ print P0
+ end
+CODE
+abAdef
+OUTPUT
+
+output_is( <<'CODE', <<OUTPUT, "set P[x], s");
+ new P0, .String
+ set P0, "abcdef\n"
+ set P0[2], "AB"
+ print P0
+ end
+CODE
+abABef
+OUTPUT