Author: bernhard Date: Fri Jan 23 11:10:12 2009 New Revision: 35915 Modified: trunk/languages/pipp/src/common/php_string.pir trunk/languages/pipp/t/php/string.t
Log: [Pipp] implement str_replace partially Modified: trunk/languages/pipp/src/common/php_string.pir ============================================================================== --- trunk/languages/pipp/src/common/php_string.pir (original) +++ trunk/languages/pipp/src/common/php_string.pir Fri Jan 23 11:10:12 2009 @@ -443,16 +443,30 @@ =item C<mixed str_replace(mixed search, mixed replace, mixed subject [, int &replace_count])> -Replaces all occurrences of search in haystack with replace +Replaces all occurrences of search in subject with replace. -NOT IMPLEMENTED. +TODO: search and replace may be arrays. +TODO: Passing back the number of replacements in replace_count. +TODO: error and parameter checking =cut .sub 'str_replace' - not_implemented() + .param pmc search + .param pmc replace + .param pmc subject + + $S1 = subject + $S2 = search + $I2 = length $S2 + $S3 = replace + $P0 = split $S2, $S1 + $S0 = join $S3, $P0 + + .RETURN_STRING($S0) .end + =item C<string str_rot13(string str)> Perform the rot13 transform on a string Modified: trunk/languages/pipp/t/php/string.t ============================================================================== --- trunk/languages/pipp/t/php/string.t (original) +++ trunk/languages/pipp/t/php/string.t Fri Jan 23 11:10:12 2009 @@ -1,4 +1,4 @@ -# Copyright (C) 2008, The Perl Foundation. +# Copyright (C) 2008-2009, The Perl Foundation. # $Id$ =head1 NAME @@ -20,11 +20,10 @@ use strict; use warnings; - use FindBin; use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib"; -use Parrot::Test tests => 35; +use Parrot::Test tests => 36; language_output_is( 'Pipp', <<'CODE', <<'OUT', 'bin2hex' ); @@ -471,6 +470,16 @@ A1B2C3 A1B2C3 OUT +language_output_is( 'Pipp', <<'CODE', <<"OUT", 'str_replace' ); +<?php + +echo str_replace( "one", "1", "one + one = 2\n" ); + +?> +CODE +1 + 1 = 2 +OUT + # Local Variables: # mode: cperl # cperl-indent-level: 4