cvsuser     03/11/15 07:30:46

  Modified:    encodings dbcs.c utf8.c
               include/parrot string.h string_funcs.h
               src      string.c
  Log:
  Implement string iterator in string_str_index_multibyte
  
  Revision  Changes    Path
  1.4       +2 -2      parrot/encodings/dbcs.c
  
  Index: dbcs.c
  ===================================================================
  RCS file: /cvs/public/parrot/encodings/dbcs.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- dbcs.c    15 Nov 2003 11:11:20 -0000      1.3
  +++ dbcs.c    15 Nov 2003 15:30:40 -0000      1.4
  @@ -1,7 +1,7 @@
   /* dbcs.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: dbcs.c,v 1.3 2003/11/15 11:11:20 petergibbs Exp $
  + *     $Id: dbcs.c,v 1.4 2003/11/15 15:30:40 petergibbs Exp $
    *  Overview:
    *     This defines the DBCS encoding routines.
    *  Data Structure and Algorithms:
  @@ -109,7 +109,7 @@
   static void
   dbcs_set_position(struct string_iterator_t *i, Parrot_Int pos)
   {
  -    const byte_t *bptr = (char *)i->str->strstart;
  +    const byte_t *bptr = (byte_t *)i->str->strstart;
   
       i->charpos = pos;
       while (pos--) {
  
  
  
  1.17      +2 -2      parrot/encodings/utf8.c
  
  Index: utf8.c
  ===================================================================
  RCS file: /cvs/public/parrot/encodings/utf8.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -w -r1.16 -r1.17
  --- utf8.c    15 Nov 2003 11:11:20 -0000      1.16
  +++ utf8.c    15 Nov 2003 15:30:41 -0000      1.17
  @@ -1,7 +1,7 @@
   /* utf8.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: utf8.c,v 1.16 2003/11/15 11:11:20 petergibbs Exp $
  + *     $Id: utf8.c,v 1.17 2003/11/15 15:30:41 petergibbs Exp $
    *  Overview:
    *     This defines the UTF-8 encoding routines.
    *  Data Structure and Algorithms:
  @@ -171,7 +171,7 @@
   static void
   utf8_set_position(struct string_iterator_t *i, Parrot_Int pos)
   {
  -    const utf8_t *u8ptr = (char *)i->str->strstart;
  +    const utf8_t *u8ptr = (utf8_t *)i->str->strstart;
   
       i->charpos = pos;
       while (pos-- > 0) {
  
  
  
  1.57      +2 -2      parrot/include/parrot/string.h
  
  Index: string.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/string.h,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -w -r1.56 -r1.57
  --- string.h  15 Nov 2003 11:11:24 -0000      1.56
  +++ string.h  15 Nov 2003 15:30:43 -0000      1.57
  @@ -1,7 +1,7 @@
   /* string.h
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: string.h,v 1.56 2003/11/15 11:11:24 petergibbs Exp $
  + *     $Id: string.h,v 1.57 2003/11/15 15:30:43 petergibbs Exp $
    *  Overview:
    *     This is the api header for the string subsystem
    *  Data Structure and Algorithms:
  @@ -37,7 +37,7 @@
   
   /* String iterator */
   typedef struct string_iterator_t {
  -    String *str;
  +    const String *str;
       UINTVAL bytepos;
       UINTVAL charpos;
       UINTVAL (*decode_and_advance)(struct string_iterator_t *i);
  
  
  
  1.32      +2 -2      parrot/include/parrot/string_funcs.h
  
  Index: string_funcs.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/string_funcs.h,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -w -r1.31 -r1.32
  --- string_funcs.h    15 Nov 2003 11:11:24 -0000      1.31
  +++ string_funcs.h    15 Nov 2003 15:30:43 -0000      1.32
  @@ -1,7 +1,7 @@
   /* string_funcs.h
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: string_funcs.h,v 1.31 2003/11/15 11:11:24 petergibbs Exp $
  + *     $Id: string_funcs.h,v 1.32 2003/11/15 15:30:43 petergibbs Exp $
    *  Overview:
    *     This is the api header for the string subsystem
    *  Data Structure and Algorithms:
  @@ -69,7 +69,7 @@
                  STRING *s2, STRING **dest);
   STRING *string_bitwise_xor(struct Parrot_Interp *interpreter, STRING *s1,
                  STRING *s2, STRING **dest);
  -void string_iterator_init(struct string_iterator_t *i, STRING *s);
  +void string_iterator_init(struct string_iterator_t *i, const STRING *s);
   UINTVAL string_decode_and_advance(struct string_iterator_t *i);
   
   #endif
  
  
  
  1.160     +27 -24    parrot/src/string.c
  
  Index: string.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/string.c,v
  retrieving revision 1.159
  retrieving revision 1.160
  diff -u -w -r1.159 -r1.160
  --- string.c  15 Nov 2003 11:11:27 -0000      1.159
  +++ string.c  15 Nov 2003 15:30:46 -0000      1.160
  @@ -1,7 +1,7 @@
   /* string.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: string.c,v 1.159 2003/11/15 11:11:27 petergibbs Exp $
  + *     $Id: string.c,v 1.160 2003/11/15 15:30:46 petergibbs Exp $
    *  Overview:
    *     This is the api definitions for the string subsystem
    *  Data Structure and Algorithms:
  @@ -332,32 +332,35 @@
   string_str_index_multibyte(struct Parrot_Interp *interpreter,
           const STRING *str, const STRING *find, UINTVAL start)
   {
  -    const void* const lastmatch = str->encoding->skip_backward(
  -            (char*)str->strstart + str->buflen,  find->strlen);
  -    const void* const lastfind  = find->encoding->skip_forward(
  -            find->strstart, find->strlen);
  -    const void* sp;
  -    const void* fp;
  -    const void* ip;
  -    INTVAL pos = start;
  -
  -    sp = str->encoding->skip_forward(str->strstart, start);
  -    while (sp <= lastmatch) {
  -        fp = find->strstart;
  -        ip = sp;
  -
  -        for (; fp < lastfind; fp = find->encoding->skip_forward(fp, 1),
  -                              ip =  str->encoding->skip_forward(ip, 1)) {
  -            if (find->encoding->decode(fp) != str->encoding->decode(ip))
  +    struct string_iterator_t fp;
  +    struct string_iterator_t ip;
  +    struct string_iterator_t sp;
  +    int match;
  +    UINTVAL lastmatch = str->strlen - find->strlen;
  +
  +    string_iterator_init(&sp, str);
  +    string_iterator_init(&fp, find);
  +    string_iterator_init(&ip, str);
  +    sp.set_position(&sp, start);
  +    while (sp.charpos <= lastmatch) {
  +        fp.set_position(&fp, 0);
  +        /* XXX need a function for this? */
  +        ip.charpos = sp.charpos;
  +        ip.bytepos = sp.bytepos;
  +
  +        match = 1;
  +        for (; fp.charpos < find->strlen; ) {
  +            if (fp.decode_and_advance(&fp) != ip.decode_and_advance(&ip)) {
  +                match = 0;
                   break;
           }
  -
  -        if (fp == lastfind) {
  -            return pos;
  +        }
  +        if (match) {
  +            return sp.charpos;
           }
   
  -        sp = str->encoding->skip_forward(sp, 1);
  -        pos++;
  +        /* XXX advance-only not yet implemented */
  +        sp.decode_and_advance(&sp);
       }
   
       return -1;
  @@ -1646,7 +1649,7 @@
   }
   
   void
  -string_iterator_init(struct string_iterator_t *i, STRING *s)
  +string_iterator_init(struct string_iterator_t *i, const STRING *s)
   {
       i->str = s;
       i->bytepos = 0;
  
  
  

Reply via email to