cvsuser 05/04/06 03:27:56
Modified: charset ascii.c ascii.h binary.c binary.h unicode.c
classes integer.pmc
include/parrot charset.h
src string.c
Log:
mixed_cs_index
Revision Changes Path
1.19 +39 -6 parrot/charset/ascii.c
Index: ascii.c
===================================================================
RCS file: /cvs/public/parrot/charset/ascii.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ascii.c 2 Mar 2005 13:47:28 -0000 1.18
+++ ascii.c 6 Apr 2005 10:27:51 -0000 1.19
@@ -331,14 +331,47 @@
}
INTVAL
-ascii_cs_index(Interp *interpreter, const STRING *source_string,
- const STRING *search_string, UINTVAL offset)
+mixed_cs_index(Interp *interpreter, STRING *src, STRING *search, UINTVAL
offs)
+{
+ String_iter src_iter, search_iter;
+ UINTVAL c1, c2, len;
+ INTVAL start;
+
+ ENCODING_ITER_INIT(interpreter, src, &src_iter);
+ src_iter.set_position(interpreter, &src_iter, offs);
+ ENCODING_ITER_INIT(interpreter, search, &search_iter);
+ len = search->strlen;
+
+ start = -1;
+ for (; len && offs < src->strlen; ++offs) {
+ c1 = src_iter.get_and_advance(interpreter, &src_iter);
+ c2 = search_iter.get_and_advance(interpreter, &search_iter);
+ if (c1 == c2) {
+ --len;
+ if (start == -1)
+ start = offs;
+ }
+ else {
+ len = search->strlen;
+ start = -1;
+ search_iter.set_position(interpreter, &search_iter, 0);
+ }
+ }
+ if (len == 0)
+ return start;
+ return -1;
+}
+
+INTVAL
+ascii_cs_index(Interp *interpreter, STRING *source_string,
+ STRING *search_string, UINTVAL offset)
{
UINTVAL base_size, search_size;
char *base, *search;
INTVAL retval;
if (source_string->charset != search_string->charset) {
- internal_exception(UNIMPLEMENTED, "Cross-charset index not
supported");
+ return mixed_cs_index(interpreter, source_string, search_string,
+ offset);
}
assert(source_string->encoding == Parrot_fixed_8_encoding_ptr);
@@ -348,8 +381,8 @@
}
INTVAL
-ascii_cs_rindex(Interp *interpreter, const STRING *source_string,
- const STRING *search_string, UINTVAL offset) {
+ascii_cs_rindex(Interp *interpreter, STRING *source_string,
+ STRING *search_string, UINTVAL offset) {
UINTVAL base_size, search_size;
char *base, *search;
INTVAL retval;
1.13 +6 -5 parrot/charset/ascii.h
Index: ascii.h
===================================================================
RCS file: /cvs/public/parrot/charset/ascii.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ascii.h 2 Mar 2005 09:03:25 -0000 1.12
+++ ascii.h 6 Apr 2005 10:27:51 -0000 1.13
@@ -34,13 +34,14 @@
UINTVAL offset, const unsigned char *typetable);
INTVAL ascii_compare(Interp *, STRING *lhs, STRING *rhs);
INTVAL ascii_compare(Interp *, STRING *lhs, STRING *rhs);
-INTVAL ascii_cs_index(Interp *, const STRING *source_string,
- const STRING *search_string, UINTVAL offset);
-INTVAL ascii_cs_rindex(Interp *, const STRING *source_string,
- const STRING *search_string, UINTVAL offset);
+INTVAL ascii_cs_index(Interp *, STRING *source_string,
+ STRING *search_string, UINTVAL offset);
+INTVAL ascii_cs_rindex(Interp *, STRING *source_string,
+ STRING *search_string, UINTVAL offset);
size_t ascii_compute_hash(Interp *, STRING *source_string);
STRING * ascii_to_unicode(Interp *, STRING *source_string, STRING *dest);
STRING * ascii_to_charset(Interp *, STRING *src, CHARSET *new_cs, STRING
*dest);
+INTVAL mixed_cs_index(Interp *, STRING *src, STRING *search, UINTVAL offs);
static void compose(Interp *, STRING *source_string);
static void decompose(Interp *, STRING *source_string);
1.12 +5 -5 parrot/charset/binary.c
Index: binary.c
===================================================================
RCS file: /cvs/public/parrot/charset/binary.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- binary.c 1 Mar 2005 17:25:44 -0000 1.11
+++ binary.c 6 Apr 2005 10:27:51 -0000 1.12
@@ -116,15 +116,15 @@
}
static INTVAL
-cs_index(Interp *interpreter, const STRING *source_string,
- const STRING *search_string, UINTVAL offset)
+cs_index(Interp *interpreter, STRING *source_string,
+ STRING *search_string, UINTVAL offset)
{
return -1;
}
static INTVAL
-cs_rindex(Interp *interpreter, const STRING *source_string,
- const STRING *search_string, UINTVAL offset)
+cs_rindex(Interp *interpreter, STRING *source_string,
+ STRING *search_string, UINTVAL offset)
{
return -1;
}
1.8 +1 -3 parrot/charset/binary.h
Index: binary.h
===================================================================
RCS file: /cvs/public/parrot/charset/binary.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- binary.h 1 Mar 2005 14:19:45 -0000 1.7
+++ binary.h 6 Apr 2005 10:27:51 -0000 1.8
@@ -22,8 +22,6 @@
static void downcase_first(Interp *, STRING *source_string);
static void titlecase_first(Interp *, STRING *source_string);
static INTVAL compare(Interp *, STRING *lhs, STRING *rhs);
-static INTVAL cs_index(Interp *, const STRING *source_string, const STRING
*search_string, UINTVAL offset);
-static INTVAL cs_rindex(Interp *, const STRING *source_string, const STRING
*search_string, UINTVAL offset);
static UINTVAL validate(Interp *, STRING *source_string);
static INTVAL is_wordchar(Interp *, STRING *source_string, UINTVAL offset);
static INTVAL find_wordchar(Interp *, STRING *source_string, UINTVAL offset);
1.6 +5 -11 parrot/charset/unicode.c
Index: unicode.c
===================================================================
RCS file: /cvs/public/parrot/charset/unicode.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- unicode.c 4 Apr 2005 08:12:09 -0000 1.5
+++ unicode.c 6 Apr 2005 10:27:51 -0000 1.6
@@ -16,6 +16,7 @@
#include "parrot/parrot.h"
#include "unicode.h"
+#include "ascii.h"
#ifdef EXCEPTION
# undef EXCEPTION
@@ -149,17 +150,10 @@
return 0;
}
-static INTVAL
-cs_index(Interp *interpreter, const STRING *source_string,
- const STRING *search_string, UINTVAL offset)
-{
- UNIMPL;
- return 0;
-}
static INTVAL
-cs_rindex(Interp *interpreter, const STRING *source_string,
- const STRING *search_string, UINTVAL offset)
+cs_rindex(Interp *interpreter, STRING *source_string,
+ STRING *search_string, UINTVAL offset)
{
UNIMPL;
return 0;
@@ -336,7 +330,7 @@
downcase_first,
titlecase_first,
compare,
- cs_index,
+ mixed_cs_index,
cs_rindex,
validate,
is_wordchar,
1.27 +3 -2 parrot/classes/integer.pmc
Index: integer.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/integer.pmc,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- integer.pmc 5 Apr 2005 16:02:26 -0000 1.26
+++ integer.pmc 6 Apr 2005 10:27:54 -0000 1.27
@@ -410,7 +410,8 @@
*/
void add_int (INTVAL b, PMC* dest) {
- INTVAL a = PMC_int_val(SELF);
+ /* INTVAL a = PMC_int_val(SELF); */
+ INTVAL a = VTABLE_get_integer(INTERP, SELF);
INTVAL c = a + b;
if ((c^a) >= 0 || (c^b) >= 0)
VTABLE_set_integer_native(INTERP, dest, c);
1.12 +3 -3 parrot/include/parrot/charset.h
Index: charset.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/charset.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- charset.h 2 Mar 2005 09:03:29 -0000 1.11
+++ charset.h 6 Apr 2005 10:27:55 -0000 1.12
@@ -52,8 +52,8 @@
typedef void (*charset_downcase_first_t)(Interp *, STRING *source_string);
typedef void (*charset_titlecase_first_t)(Interp *, STRING *source_string);
typedef INTVAL (*charset_compare_t)(Interp *, STRING *lhs, STRING *rhs);
-typedef INTVAL (*charset_index_t)(Interp *, const STRING *source_string,
const STRING *search_string, UINTVAL offset);
-typedef INTVAL (*charset_rindex_t)(Interp *, const STRING *source_string,
const STRING *search_string, UINTVAL offset);
+typedef INTVAL (*charset_index_t)(Interp *, STRING *source_string, STRING
*search_string, UINTVAL offset);
+typedef INTVAL (*charset_rindex_t)(Interp *, STRING *source_string, STRING
*search_string, UINTVAL offset);
typedef UINTVAL (*charset_validate_t)(Interp *, STRING *source_string);
typedef INTVAL (*charset_is_wordchar_t)(Interp *, STRING *source_string,
UINTVAL offset);
typedef INTVAL (*charset_find_wordchar_t)(Interp *, STRING *source_string,
UINTVAL offset);
1.247 +5 -2 parrot/src/string.c
Index: string.c
===================================================================
RCS file: /cvs/public/parrot/src/string.c,v
retrieving revision 1.246
retrieving revision 1.247
diff -u -r1.246 -r1.247
--- string.c 5 Apr 2005 08:34:24 -0000 1.246
+++ string.c 6 Apr 2005 10:27:56 -0000 1.247
@@ -766,6 +766,7 @@
string_str_index(Interp *interpreter, const STRING *s,
const STRING *s2, UINTVAL start)
{
+ STRING *src, *search;
union {
const void * __c_ptr;
void * __ptr;
@@ -778,8 +779,10 @@
saneify_string(s);
saneify_string(s2);
+ src = const_cast(s);
+ search = const_cast(s2);
- return CHARSET_INDEX(interpreter, s, s2, start);
+ return CHARSET_INDEX(interpreter, src, search, start);
}
/*