Author: leo
Date: Thu Nov 10 02:56:05 2005
New Revision: 9877
Modified:
trunk/include/parrot/string_funcs.h
trunk/ops/string.ops
trunk/src/jit_debug.c
trunk/src/jit_debug_xcoff.c
trunk/src/spf_render.c
trunk/src/string.c
trunk/t/op/string_cs.t
Log:
string improvements - chopn ATT: - API change
* fix chopn WRT inplace operations by calling unmake_COW
* unfortunately this needs an extra argument to string_chopn
* fix usage of string_chopn in tree
* append end to a test
Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h (original)
+++ trunk/include/parrot/string_funcs.h Thu Nov 10 02:56:05 2005
@@ -26,7 +26,7 @@ STRING *string_concat(Interp *, STRING *
STRING *string_append(Interp *, STRING *, STRING *, UINTVAL);
STRING *string_repeat(Interp *, const STRING *, UINTVAL,
STRING **);
-STRING *string_chopn(Interp *, STRING *, INTVAL);
+STRING *string_chopn(Interp *, STRING *, INTVAL, int in_place);
STRING *string_substr(Interp *, STRING *, INTVAL,
INTVAL, STRING **, int replace_dest);
STRING *string_replace(Interp *, STRING *, INTVAL, INTVAL,
Modified: trunk/ops/string.ops
==============================================================================
--- trunk/ops/string.ops (original)
+++ trunk/ops/string.ops Thu Nov 10 02:56:05 2005
@@ -64,22 +64,23 @@ inline op chr (out STR, in INT) :base_co
=item B<chopn>(inout STR, in INT)
+Remove $2 characters from the end of the string in $1. If $2 is negative,
+cut the string after -$2 characters.
+
=item B<chopn>(out STR, in STR, in INT)
-Remove $2 characters from the end of the string in $1. The 3-arg version
-removes $3 characters from the end of the string in $2 and returns the result
-in $1
+Removes $3 characters from the end of the string in $2 and returns the result
+in $1. If $3 is negative, cut the string after -$3 characters.
=cut
inline op chopn(inout STR, in INT) :base_core {
- (void)string_chopn(interpreter,$1, $2);
+ $1 = string_chopn(interpreter, $1, $2, 1);
goto NEXT();
}
inline op chopn(out STR, in STR, in INT) :base_core {
- $1 = string_copy(interpreter, $2);
- (void)string_chopn(interpreter, $1,$3);
+ $1 = string_chopn(interpreter, $2, $3, 0);
goto NEXT();
}
Modified: trunk/src/jit_debug.c
==============================================================================
--- trunk/src/jit_debug.c (original)
+++ trunk/src/jit_debug.c Thu Nov 10 02:56:05 2005
@@ -290,7 +290,7 @@ Parrot_jit_debug_stabs(Interp *interpret
if (interpreter->code->debugs) {
char *ext;
char *src = string_to_cstring(interpreter,
- Parrot_debug_pc_to_filename(interpreter,
+ Parrot_debug_pc_to_filename(interpreter,
interpreter->code->debugs, 0));
pasmfile = string_make(interpreter, src, strlen(src), NULL,
PObj_external_FLAG);
@@ -299,9 +299,9 @@ Parrot_jit_debug_stabs(Interp *interpret
ext = strrchr(src, '.');
if (ext && strcmp (ext, ".pasm") == 0)
- file = string_chopn(interpreter, file, 4);
+ file = string_chopn(interpreter, file, 4, 1);
else if (ext && strcmp (ext, ".imc") == 0)
- file = string_chopn(interpreter, file, 3);
+ file = string_chopn(interpreter, file, 3, 1);
else if (!ext) /* EVAL_n */
file = string_append(interpreter, file,
string_make(interpreter, ".", 1, NULL, PObj_external_FLAG),
@@ -309,7 +309,7 @@ Parrot_jit_debug_stabs(Interp *interpret
}
else {
/* chop pbc */
- file = string_chopn(interpreter, file, 3);
+ file = string_chopn(interpreter, file, 3, 1);
pasmfile = debug_file(interpreter, file, "pasm");
}
stabsfile = debug_file(interpreter, file, "stabs.s");
Modified: trunk/src/jit_debug_xcoff.c
==============================================================================
--- trunk/src/jit_debug_xcoff.c (original)
+++ trunk/src/jit_debug_xcoff.c Thu Nov 10 02:56:05 2005
@@ -258,7 +258,7 @@ Parrot_jit_debug_stabs(Interp *interpret
if (interpreter->code->debugs) {
char *ext;
char *src = string_to_cstring(interpreter,
- Parrot_debug_pc_to_filename(interpreter,
+ Parrot_debug_pc_to_filename(interpreter,
interpreter->code->debugs, 0));
pasmfile = string_make(interpreter, src, strlen(src), NULL,
PObj_external_FLAG);
@@ -267,9 +267,9 @@ Parrot_jit_debug_stabs(Interp *interpret
ext = strrchr(src, '.');
if (ext && strcmp (ext, ".pasm") == 0)
- file = string_chopn(interpreter, file, 4);
+ file = string_chopn(interpreter, file, 4, 1);
else if (ext && strcmp (ext, ".imc") == 0)
- file = string_chopn(interpreter, file, 3);
+ file = string_chopn(interpreter, file, 3, 1);
else if (!ext) /* EVAL_n */
file = string_append(interpreter, file,
string_make(interpreter, ".", 1, NULL, PObj_external_FLAG),
@@ -277,7 +277,7 @@ Parrot_jit_debug_stabs(Interp *interpret
}
else {
/* chop pbc */
- file = string_chopn(interpreter, file, 3);
+ file = string_chopn(interpreter, file, 3, 1);
pasmfile = debug_file(interpreter, file, "pasm");
}
stabsfile = debug_file(interpreter, file, "stabs.s");
Modified: trunk/src/spf_render.c
==============================================================================
--- trunk/src/spf_render.c (original)
+++ trunk/src/spf_render.c Thu Nov 10 02:56:05 2005
@@ -155,7 +155,7 @@ handle_flags(Interp *interpreter,
else {
/* string precision */
if (info->flags & FLAG_PREC && info->prec < len) {
- string_chopn(interpreter, str, -(INTVAL)(info->prec));
+ string_chopn(interpreter, str, -(INTVAL)(info->prec), 1);
len = info->prec;
}
}
@@ -182,7 +182,7 @@ handle_flags(Interp *interpreter,
string_ord(interpreter, str,0) == '+')) {
STRING *temp = 0;
string_substr(interpreter, str, 1, len-1, &temp, 0);
- string_chopn(interpreter, str, -1);
+ string_chopn(interpreter, str, -1, 1);
string_append(interpreter, str, fill, 0);
string_append(interpreter, str, temp, 0);
}
Modified: trunk/src/string.c
==============================================================================
--- trunk/src/string.c (original)
+++ trunk/src/string.c Thu Nov 10 02:56:05 2005
@@ -1269,25 +1269,33 @@ string_replace(Interp *interpreter, STRI
/*
=item C<STRING *
-string_chopn(Interp *interpreter, STRING *s, INTVAL n)>
+string_chopn(Interp *interpreter, STRING *s, INTVAL n, int in_place)>
Chops off the last C<n> characters of the specified Parrot string. If
C<n> is negative, cuts the string after C<+n> characters.
+If C<in_place> is true, the string is chopped in places, else a copy
+of the string is chopped and returned.
=cut
*/
STRING *
-string_chopn(Interp *interpreter, STRING *s, INTVAL n)
+string_chopn(Interp *interpreter, STRING *s, INTVAL n, int in_place)
{
UINTVAL new_length, uchar_size;
String_iter iter;
- /*
- * FIXME constant or external strings can't be chopped inplace
- */
+
if (!s)
return NULL;
+ if (in_place) {
+ /*
+ * constant or external strings can't be chopped inplace
+ */
+ Parrot_unmake_COW(interpreter, s);
+ }
+ else
+ s = string_copy(interpreter, s);
if (n < 0) {
new_length = -n;
Modified: trunk/t/op/string_cs.t
==============================================================================
--- trunk/t/op/string_cs.t (original)
+++ trunk/t/op/string_cs.t Thu Nov 10 02:56:05 2005
@@ -568,6 +568,7 @@ output_is( <<'CODE', <<"OUTPUT", "chopn
stringinfo I0, S1, .STRINGINFO_BUFUSED
print_item I0
print_newline
+ end
CODE
TT 2 2
OUTPUT