Ticket #1456: string-iter-remove-old-api-v6.diff

File string-iter-remove-old-api-v6.diff, 27.1 KB (added by nwellnhof, 12 years ago)
  • include/parrot/encoding.h

    diff --git a/include/parrot/encoding.h b/include/parrot/encoding.h
    index 75055b8..67d2866 100644
    a b  
    3030 
    3131struct string_iterator_t;       /* s. parrot/string.h */ 
    3232 
    33 typedef void (*encoding_iter_init_t)(PARROT_INTERP, const STRING *src, 
    34         struct string_iterator_t *); 
    3533typedef UINTVAL (*encoding_iter_get_t)( 
    3634    PARROT_INTERP, const STRING *str, const String_iter *i, INTVAL  offset); 
    3735typedef void    (*encoding_iter_skip_t)( 
     
    5452    encoding_get_bytes_t                get_bytes; 
    5553    encoding_codepoints_t               codepoints; 
    5654    encoding_bytes_t                    bytes; 
    57     encoding_iter_init_t                iter_init; 
    5855    encoding_find_cclass_t              find_cclass; 
    5956    encoding_hash_t                     hash; 
    6057    encoding_iter_get_t                 iter_get; 
     
    223220    ((src)->encoding)->codepoints((i), (src)) 
    224221#define ENCODING_BYTES(i, src) \ 
    225222    ((src)->encoding)->bytes((i), (src)) 
    226 #define ENCODING_ITER_INIT(i, src, iter) \ 
    227     ((src)->encoding)->iter_init((i), (src), (iter)) 
    228223#define ENCODING_FIND_CCLASS(i, src, typetable, flags, pos, end) \ 
    229224    ((src)->encoding)->find_cclass((i), (src), (typetable), (flags), (pos), (end)) 
    230225#define ENCODING_HASH(i, src, seed) \ 
  • include/parrot/string.h

    diff --git a/include/parrot/string.h b/include/parrot/string.h
    index 7d87f8e..ddd9254 100644
    a b  
    2929 
    3030/* String iterator */ 
    3131typedef struct string_iterator_t { 
    32     const STRING *str; 
    3332    UINTVAL bytepos; 
    3433    UINTVAL charpos; 
    35     UINTVAL (*get_and_advance)(PARROT_INTERP, struct string_iterator_t *i); 
    36     void (*set_and_advance)(PARROT_INTERP, struct string_iterator_t *i, UINTVAL c); 
    37     void (*set_position)(PARROT_INTERP, struct string_iterator_t *i, UINTVAL pos); 
    3834} String_iter; 
    3935 
    4036#define STRING_ITER_INIT(i, iter) \ 
  • src/string/encoding/fixed_8.c

    diff --git a/src/string/encoding/fixed_8.c b/src/string/encoding/fixed_8.c
    index 13448f4..7733d87 100644
    a b  
    4141        __attribute__nonnull__(2) 
    4242        __attribute__nonnull__(3); 
    4343 
    44 static UINTVAL fixed8_get_next(PARROT_INTERP, ARGMOD(String_iter *iter)) 
    45         __attribute__nonnull__(1) 
    46         __attribute__nonnull__(2) 
    47         FUNC_MODIFIES(*iter); 
    48  
    4944static UINTVAL fixed8_iter_get(PARROT_INTERP, 
    5045    ARGIN(const STRING *str), 
    5146    ARGIN(const String_iter *iter), 
     
    8883        __attribute__nonnull__(3) 
    8984        FUNC_MODIFIES(*iter); 
    9085 
    91 static void fixed8_set_next(PARROT_INTERP, 
    92     ARGMOD(String_iter *iter), 
    93     UINTVAL c) 
    94         __attribute__nonnull__(1) 
    95         __attribute__nonnull__(2) 
    96         FUNC_MODIFIES(*iter); 
    97  
    98 static void fixed8_set_position(SHIM_INTERP, 
    99     ARGMOD(String_iter *iter), 
    100     UINTVAL pos) 
    101         __attribute__nonnull__(2) 
    102         FUNC_MODIFIES(*iter); 
    103  
    10486static size_t fixed_8_hash(SHIM_INTERP, 
    10587    ARGIN(const STRING *s), 
    10688    size_t hashval) 
     
    137119        __attribute__nonnull__(1) 
    138120        __attribute__nonnull__(2); 
    139121 
    140 static void iter_init(SHIM_INTERP, 
    141     ARGIN(const STRING *src), 
    142     ARGOUT(String_iter *iter)) 
    143         __attribute__nonnull__(2) 
    144         __attribute__nonnull__(3) 
    145         FUNC_MODIFIES(*iter); 
    146  
    147122static void set_byte(PARROT_INTERP, 
    148123    ARGIN(const STRING *source_string), 
    149124    UINTVAL offset, 
     
    164139#define ASSERT_ARGS_find_cclass __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    165140       PARROT_ASSERT_ARG(s) \ 
    166141    , PARROT_ASSERT_ARG(typetable)) 
    167 #define ASSERT_ARGS_fixed8_get_next __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    168        PARROT_ASSERT_ARG(interp) \ 
    169     , PARROT_ASSERT_ARG(iter)) 
    170142#define ASSERT_ARGS_fixed8_iter_get __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    171143       PARROT_ASSERT_ARG(interp) \ 
    172144    , PARROT_ASSERT_ARG(str) \ 
     
    185157#define ASSERT_ARGS_fixed8_iter_skip __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    186158       PARROT_ASSERT_ARG(str) \ 
    187159    , PARROT_ASSERT_ARG(iter)) 
    188 #define ASSERT_ARGS_fixed8_set_next __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    189        PARROT_ASSERT_ARG(interp) \ 
    190     , PARROT_ASSERT_ARG(iter)) 
    191 #define ASSERT_ARGS_fixed8_set_position __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    192        PARROT_ASSERT_ARG(iter)) 
    193160#define ASSERT_ARGS_fixed_8_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    194161       PARROT_ASSERT_ARG(s)) 
    195162#define ASSERT_ARGS_get_byte __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
     
    203170#define ASSERT_ARGS_get_codepoints __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    204171       PARROT_ASSERT_ARG(interp) \ 
    205172    , PARROT_ASSERT_ARG(source_string)) 
    206 #define ASSERT_ARGS_iter_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    207        PARROT_ASSERT_ARG(src) \ 
    208     , PARROT_ASSERT_ARG(iter)) 
    209173#define ASSERT_ARGS_set_byte __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    210174       PARROT_ASSERT_ARG(interp) \ 
    211175    , PARROT_ASSERT_ARG(source_string)) 
     
    540504 
    541505/* 
    542506 
    543 =item C<static UINTVAL fixed8_get_next(PARROT_INTERP, String_iter *iter)> 
    544  
    545 Moves the string iterator C<i> to the next codepoint. 
    546  
    547 =cut 
    548  
    549 */ 
    550  
    551 static UINTVAL 
    552 fixed8_get_next(PARROT_INTERP, ARGMOD(String_iter *iter)) 
    553 { 
    554     ASSERT_ARGS(fixed8_get_next) 
    555     const UINTVAL c = get_byte(interp, iter->str, iter->charpos++); 
    556     iter->bytepos++; 
    557     return c; 
    558 } 
    559  
    560 /* 
    561  
    562 =item C<static void fixed8_set_next(PARROT_INTERP, String_iter *iter, UINTVAL 
    563 c)> 
    564  
    565 With the string iterator C<i>, appends the codepoint C<c> and advances to the 
    566 next position in the string. 
    567  
    568 =cut 
    569  
    570 */ 
    571  
    572 static void 
    573 fixed8_set_next(PARROT_INTERP, ARGMOD(String_iter *iter), UINTVAL c) 
    574 { 
    575     ASSERT_ARGS(fixed8_set_next) 
    576     set_byte(interp, iter->str, iter->charpos++, c); 
    577     iter->bytepos++; 
    578 } 
    579  
    580 /* 
    581  
    582 =item C<static void fixed8_set_position(PARROT_INTERP, String_iter *iter, 
    583 UINTVAL pos)> 
    584  
    585 Moves the string iterator C<i> to the position C<n> in the string. 
    586  
    587 =cut 
    588  
    589 */ 
    590  
    591 static void 
    592 fixed8_set_position(SHIM_INTERP, ARGMOD(String_iter *iter), UINTVAL pos) 
    593 { 
    594     ASSERT_ARGS(fixed8_set_position) 
    595     iter->bytepos = iter->charpos = pos; 
    596     PARROT_ASSERT(pos <= Buffer_buflen(iter->str)); 
    597 } 
    598  
    599  
    600 /* 
    601  
    602 =item C<static void iter_init(PARROT_INTERP, const STRING *src, String_iter 
    603 *iter)> 
    604  
    605 Initializes for string C<src> the string iterator C<iter>. 
    606  
    607 =cut 
    608  
    609 */ 
    610  
    611 static void 
    612 iter_init(SHIM_INTERP, ARGIN(const STRING *src), ARGOUT(String_iter *iter)) 
    613 { 
    614     ASSERT_ARGS(iter_init) 
    615     iter->str             = src; 
    616     iter->bytepos         = iter->charpos        = 0; 
    617     iter->get_and_advance = fixed8_get_next; 
    618     iter->set_and_advance = fixed8_set_next; 
    619     iter->set_position    = fixed8_set_position; 
    620 } 
    621  
    622  
    623 /* 
    624  
    625507=item C<static size_t fixed_8_hash(PARROT_INTERP, const STRING *s, size_t 
    626508hashval)> 
    627509 
     
    674556        get_bytes, 
    675557        codepoints, 
    676558        bytes, 
    677         iter_init, 
    678559        find_cclass, 
    679560        fixed_8_hash, 
    680561        fixed8_iter_get, 
  • src/string/encoding/ucs2.c

    diff --git a/src/string/encoding/ucs2.c b/src/string/encoding/ucs2.c
    index 5136d16..3b60fde 100644
    a b  
    8484        __attribute__nonnull__(1) 
    8585        __attribute__nonnull__(2); 
    8686 
    87 static void iter_init(PARROT_INTERP, 
    88     ARGIN(const STRING *src), 
    89     ARGOUT(String_iter *iter)) 
    90         __attribute__nonnull__(1) 
    91         __attribute__nonnull__(2) 
    92         __attribute__nonnull__(3) 
    93         FUNC_MODIFIES(*iter); 
    94  
    9587static void set_byte(PARROT_INTERP, 
    9688    SHIM(const STRING *src), 
    9789    SHIM(UINTVAL offset), 
     
    10496        __attribute__nonnull__(1) 
    10597        __attribute__nonnull__(2); 
    10698 
    107 static UINTVAL ucs2_decode_and_advance(SHIM_INTERP, ARGMOD(String_iter *i)) 
    108         __attribute__nonnull__(2) 
    109         FUNC_MODIFIES(*i); 
    110  
    111 static void ucs2_encode_and_advance(SHIM_INTERP, 
    112     ARGMOD(String_iter *i), 
    113     UINTVAL c) 
    114         __attribute__nonnull__(2) 
    115         FUNC_MODIFIES(*i); 
    116  
    11799static size_t ucs2_hash(PARROT_INTERP, 
    118100    ARGIN(const STRING *s), 
    119101    size_t hashval) 
     
    164146        __attribute__nonnull__(3) 
    165147        FUNC_MODIFIES(*i); 
    166148 
    167 static void ucs2_set_position(SHIM_INTERP, 
    168     ARGMOD(String_iter *i), 
    169     UINTVAL n) 
    170         __attribute__nonnull__(2) 
    171         FUNC_MODIFIES(*i); 
    172  
    173149#define ASSERT_ARGS_bytes __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    174150       PARROT_ASSERT_ARG(src)) 
    175151#define ASSERT_ARGS_codepoints __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
     
    189165#define ASSERT_ARGS_get_codepoints __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    190166       PARROT_ASSERT_ARG(interp) \ 
    191167    , PARROT_ASSERT_ARG(src)) 
    192 #define ASSERT_ARGS_iter_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    193        PARROT_ASSERT_ARG(interp) \ 
    194     , PARROT_ASSERT_ARG(src) \ 
    195     , PARROT_ASSERT_ARG(iter)) 
    196168#define ASSERT_ARGS_set_byte __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    197169       PARROT_ASSERT_ARG(interp)) 
    198170#define ASSERT_ARGS_to_encoding __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    199171       PARROT_ASSERT_ARG(interp) \ 
    200172    , PARROT_ASSERT_ARG(src)) 
    201 #define ASSERT_ARGS_ucs2_decode_and_advance __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    202        PARROT_ASSERT_ARG(i)) 
    203 #define ASSERT_ARGS_ucs2_encode_and_advance __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    204        PARROT_ASSERT_ARG(i)) 
    205173#define ASSERT_ARGS_ucs2_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    206174       PARROT_ASSERT_ARG(interp) \ 
    207175    , PARROT_ASSERT_ARG(s)) 
     
    225193       PARROT_ASSERT_ARG(interp) \ 
    226194    , PARROT_ASSERT_ARG(str) \ 
    227195    , PARROT_ASSERT_ARG(i)) 
    228 #define ASSERT_ARGS_ucs2_set_position __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    229        PARROT_ASSERT_ARG(i)) 
    230196/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */ 
    231197/* HEADERIZER END: static */ 
    232198 
     
    609575 
    610576/* 
    611577 
    612 =item C<static UINTVAL ucs2_decode_and_advance(PARROT_INTERP, String_iter *i)> 
    613  
    614 Moves the string iterator C<i> to the next UCS-2 codepoint. 
    615  
    616 =cut 
    617  
    618 */ 
    619  
    620 static UINTVAL 
    621 ucs2_decode_and_advance(SHIM_INTERP, ARGMOD(String_iter *i)) 
    622 { 
    623     ASSERT_ARGS(ucs2_decode_and_advance) 
    624  
    625 #if PARROT_HAS_ICU 
    626     const UChar * const s = (const UChar*) i->str->strstart; 
    627     size_t pos = i->bytepos / sizeof (UChar); 
    628  
    629     /* TODO either make sure that we don't go past end or use SAFE 
    630      *      iter versions 
    631      */ 
    632     const UChar c = s[pos++]; 
    633     i->charpos++; 
    634     i->bytepos = pos * sizeof (UChar); 
    635     return c; 
    636 #else 
    637     /* This function must never be called if compiled without ICU. 
    638      * See TT #557 
    639      */ 
    640     PARROT_ASSERT(0); 
    641     UNUSED(i); 
    642     return (UINTVAL)0; /* Stop the static analyzers from panicing */ 
    643 #endif 
    644 } 
    645  
    646 /* 
    647  
    648 =item C<static void ucs2_encode_and_advance(PARROT_INTERP, String_iter *i, 
    649 UINTVAL c)> 
    650  
    651 With the string iterator C<i>, appends the codepoint C<c> and advances to the 
    652 next position in the string. 
    653  
    654 =cut 
    655  
    656 */ 
    657  
    658 static void 
    659 ucs2_encode_and_advance(SHIM_INTERP, ARGMOD(String_iter *i), UINTVAL c) 
    660 { 
    661     ASSERT_ARGS(ucs2_encode_and_advance) 
    662  
    663 #if PARROT_HAS_ICU 
    664     UChar    *s = (UChar*) i->str->strstart; 
    665     UINTVAL pos = i->bytepos / sizeof (UChar); 
    666     s[pos++]    = (UChar)c; 
    667     i->charpos++; 
    668     i->bytepos = pos * sizeof (UChar); 
    669 #else 
    670     /* This function must never be called if compiled without ICU. 
    671      * See TT #557 
    672      */ 
    673     UNUSED(i); 
    674     UNUSED(c); 
    675     PARROT_ASSERT(0); 
    676 #endif 
    677 } 
    678  
    679 /* 
    680  
    681578=item C<static size_t ucs2_hash(PARROT_INTERP, const STRING *s, size_t hashval)> 
    682579 
    683580Returns the hashed value of the string, given a seed in hashval. 
     
    710607#endif 
    711608} 
    712609 
    713  
    714 /* 
    715  
    716 =item C<static void ucs2_set_position(PARROT_INTERP, String_iter *i, UINTVAL n)> 
    717  
    718 Moves the string iterator C<i> to the position C<n> in the string. 
    719  
    720 =cut 
    721  
    722 */ 
    723  
    724 static void 
    725 ucs2_set_position(SHIM_INTERP, ARGMOD(String_iter *i), UINTVAL n) 
    726 { 
    727     ASSERT_ARGS(ucs2_set_position) 
    728  
    729 #if PARROT_HAS_ICU 
    730     i->charpos = n; 
    731     i->bytepos = n * sizeof (UChar); 
    732 #else 
    733     /* This function must never be called if compiled without ICU. 
    734      * See TT #557 
    735      */ 
    736     UNUSED(i); 
    737     UNUSED(n); 
    738     PARROT_ASSERT(0); 
    739 #endif 
    740 } 
    741  
    742  
    743 /* 
    744  
    745 =item C<static void iter_init(PARROT_INTERP, const STRING *src, String_iter 
    746 *iter)> 
    747  
    748 Initializes for string C<src> the string iterator C<iter>. 
    749  
    750 =cut 
    751  
    752 */ 
    753  
    754 static void 
    755 iter_init(PARROT_INTERP, ARGIN(const STRING *src), ARGOUT(String_iter *iter)) 
    756 { 
    757     ASSERT_ARGS(iter_init) 
    758 #if PARROT_HAS_ICU 
    759     UNUSED(interp); 
    760     iter->str             = src; 
    761     iter->bytepos         = 0; 
    762     iter->charpos         = 0; 
    763     iter->get_and_advance = ucs2_decode_and_advance; 
    764     iter->set_and_advance = ucs2_encode_and_advance; 
    765     iter->set_position    = ucs2_set_position; 
    766 #else 
    767     UNUSED(src); 
    768     UNUSED(iter); 
    769     no_ICU_lib(interp); 
    770 #endif 
    771 } 
    772  
    773610/* 
    774611 
    775612=item C<void Parrot_encoding_ucs2_init(PARROT_INTERP)> 
     
    797634        get_bytes, 
    798635        codepoints, 
    799636        bytes, 
    800         iter_init, 
    801637        find_cclass, 
    802638        ucs2_hash, 
    803639        ucs2_iter_get, 
  • src/string/encoding/utf16.c

    diff --git a/src/string/encoding/utf16.c b/src/string/encoding/utf16.c
    index 6df6e96..73fa10f 100644
    a b  
    7575        __attribute__nonnull__(1) 
    7676        __attribute__nonnull__(2); 
    7777 
    78 static void iter_init(PARROT_INTERP, 
    79     ARGIN(const STRING *src), 
    80     ARGOUT(String_iter *iter)) 
    81         __attribute__nonnull__(1) 
    82         __attribute__nonnull__(2) 
    83         __attribute__nonnull__(3) 
    84         FUNC_MODIFIES(*iter); 
    85  
    8678static void set_byte(PARROT_INTERP, 
    8779    ARGIN(const STRING *src), 
    8880    UINTVAL offset, 
     
    9688        __attribute__nonnull__(1) 
    9789        __attribute__nonnull__(2); 
    9890 
    99 PARROT_WARN_UNUSED_RESULT 
    100 static UINTVAL utf16_decode_and_advance(SHIM_INTERP, ARGMOD(String_iter *i)) 
    101         __attribute__nonnull__(2) 
    102         FUNC_MODIFIES(*i); 
    103  
    104 static void utf16_encode_and_advance(SHIM_INTERP, 
    105     ARGMOD(String_iter *i), 
    106     UINTVAL c) 
    107         __attribute__nonnull__(2) 
    108         FUNC_MODIFIES(*i); 
    109  
    11091static UINTVAL utf16_iter_get(PARROT_INTERP, 
    11192    ARGIN(const STRING *str), 
    11293    ARGIN(const String_iter *i), 
     
    152133        __attribute__nonnull__(3) 
    153134        FUNC_MODIFIES(*i); 
    154135 
    155 static void utf16_set_position(SHIM_INTERP, 
    156     ARGMOD(String_iter *i), 
    157     UINTVAL n) 
    158         __attribute__nonnull__(2) 
    159         FUNC_MODIFIES(*i); 
    160  
    161136#define ASSERT_ARGS_bytes __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    162137       PARROT_ASSERT_ARG(src)) 
    163138#define ASSERT_ARGS_codepoints __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
     
    178153#define ASSERT_ARGS_get_codepoints __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    179154       PARROT_ASSERT_ARG(interp) \ 
    180155    , PARROT_ASSERT_ARG(src)) 
    181 #define ASSERT_ARGS_iter_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    182        PARROT_ASSERT_ARG(interp) \ 
    183     , PARROT_ASSERT_ARG(src) \ 
    184     , PARROT_ASSERT_ARG(iter)) 
    185156#define ASSERT_ARGS_set_byte __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    186157       PARROT_ASSERT_ARG(interp) \ 
    187158    , PARROT_ASSERT_ARG(src)) 
    188159#define ASSERT_ARGS_to_encoding __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    189160       PARROT_ASSERT_ARG(interp) \ 
    190161    , PARROT_ASSERT_ARG(src)) 
    191 #define ASSERT_ARGS_utf16_decode_and_advance __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    192        PARROT_ASSERT_ARG(i)) 
    193 #define ASSERT_ARGS_utf16_encode_and_advance __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    194        PARROT_ASSERT_ARG(i)) 
    195162#define ASSERT_ARGS_utf16_iter_get __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    196163       PARROT_ASSERT_ARG(interp) \ 
    197164    , PARROT_ASSERT_ARG(str) \ 
     
    212179       PARROT_ASSERT_ARG(interp) \ 
    213180    , PARROT_ASSERT_ARG(str) \ 
    214181    , PARROT_ASSERT_ARG(i)) 
    215 #define ASSERT_ARGS_utf16_set_position __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    216        PARROT_ASSERT_ARG(i)) 
    217182/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */ 
    218183/* HEADERIZER END: static */ 
    219184 
     
    717682#endif 
    718683} 
    719684 
    720 #if PARROT_HAS_ICU 
    721 /* 
    722  
    723 =item C<static UINTVAL utf16_decode_and_advance(PARROT_INTERP, String_iter *i)> 
    724  
    725 Moves the string iterator C<i> to the next UTF-16 codepoint. 
    726  
    727 =cut 
    728  
    729 */ 
    730  
    731 PARROT_WARN_UNUSED_RESULT 
    732 static UINTVAL 
    733 utf16_decode_and_advance(SHIM_INTERP, ARGMOD(String_iter *i)) 
    734 { 
    735     ASSERT_ARGS(utf16_decode_and_advance) 
    736     const UChar * const s = (const UChar*) i->str->strstart; 
    737     UINTVAL pos = i->bytepos / sizeof (UChar); 
    738     UINTVAL c; 
    739  
    740     /* TODO either make sure that we don't go past end or use SAFE 
    741      *      iter versions 
    742      */ 
    743     U16_NEXT_UNSAFE(s, pos, c); 
    744     i->charpos++; 
    745     i->bytepos = pos * sizeof (UChar); 
    746     return c; 
    747 } 
    748  
    749 /* 
    750  
    751 =item C<static void utf16_encode_and_advance(PARROT_INTERP, String_iter *i, 
    752 UINTVAL c)> 
    753  
    754 With the string iterator C<i>, appends the codepoint C<c> and advances to the 
    755 next position in the string. 
    756  
    757 =cut 
    758  
    759 */ 
    760  
    761 static void 
    762 utf16_encode_and_advance(SHIM_INTERP, ARGMOD(String_iter *i), UINTVAL c) 
    763 { 
    764     ASSERT_ARGS(utf16_encode_and_advance) 
    765     UChar * const s = (UChar*) i->str->strstart; 
    766     UINTVAL pos = i->bytepos / sizeof (UChar); 
    767     U16_APPEND_UNSAFE(s, pos, c); 
    768     i->charpos++; 
    769     i->bytepos = pos * sizeof (UChar); 
    770 } 
    771  
    772 /* 
    773  
    774 =item C<static void utf16_set_position(PARROT_INTERP, String_iter *i, UINTVAL 
    775 n)> 
    776  
    777 Moves the string iterator C<i> to the position C<n> in the string. 
    778  
    779 =cut 
    780  
    781 */ 
    782  
    783 static void 
    784 utf16_set_position(SHIM_INTERP, ARGMOD(String_iter *i), UINTVAL n) 
    785 { 
    786     ASSERT_ARGS(utf16_set_position) 
    787     UChar * const s = (UChar*) i->str->strstart; 
    788     UINTVAL pos; 
    789     pos = 0; 
    790     U16_FWD_N_UNSAFE(s, pos, n); 
    791     i->charpos = n; 
    792     i->bytepos = pos * sizeof (UChar); 
    793 } 
    794  
    795 #endif 
    796  
    797 /* 
    798  
    799 =item C<static void iter_init(PARROT_INTERP, const STRING *src, String_iter 
    800 *iter)> 
    801  
    802 Initializes for string C<src> the string iterator C<iter>. 
    803  
    804 =cut 
    805  
    806 */ 
    807  
    808 static void 
    809 iter_init(PARROT_INTERP, ARGIN(const STRING *src), ARGOUT(String_iter *iter)) 
    810 { 
    811     ASSERT_ARGS(iter_init) 
    812     iter->str = src; 
    813     iter->bytepos = iter->charpos = 0; 
    814 #if PARROT_HAS_ICU 
    815     UNUSED(interp); 
    816     iter->get_and_advance = utf16_decode_and_advance; 
    817     iter->set_and_advance = utf16_encode_and_advance; 
    818     iter->set_position =    utf16_set_position; 
    819 #else 
    820     Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR, 
    821         "no ICU lib loaded"); 
    822 #endif 
    823 } 
    824  
    825685/* 
    826686 
    827687=item C<void Parrot_encoding_utf16_init(PARROT_INTERP)> 
     
    849709        get_bytes, 
    850710        codepoints, 
    851711        bytes, 
    852         iter_init, 
    853712        find_cclass, 
    854713        NULL, 
    855714        utf16_iter_get, 
  • src/string/encoding/utf8.c

    diff --git a/src/string/encoding/utf8.c b/src/string/encoding/utf8.c
    index 55e1753..e929397 100644
    a b  
    7272        __attribute__nonnull__(1) 
    7373        __attribute__nonnull__(2); 
    7474 
    75 static void iter_init(SHIM_INTERP, 
    76     ARGIN(const STRING *src), 
    77     ARGOUT(String_iter *iter)) 
    78         __attribute__nonnull__(2) 
    79         __attribute__nonnull__(3) 
    80         FUNC_MODIFIES(*iter); 
    81  
    8275static void set_byte(PARROT_INTERP, 
    8376    ARGIN(const STRING *src), 
    8477    UINTVAL offset, 
     
    10194        __attribute__nonnull__(1) 
    10295        __attribute__nonnull__(2); 
    10396 
    104 static UINTVAL utf8_decode_and_advance(PARROT_INTERP, 
    105     ARGMOD(String_iter *i)) 
    106         __attribute__nonnull__(1) 
    107         __attribute__nonnull__(2) 
    108         FUNC_MODIFIES(*i); 
    109  
    11097PARROT_CANNOT_RETURN_NULL 
    11198static void * utf8_encode(PARROT_INTERP, ARGIN(void *ptr), UINTVAL c) 
    11299        __attribute__nonnull__(1) 
    113100        __attribute__nonnull__(2); 
    114101 
    115 static void utf8_encode_and_advance(PARROT_INTERP, 
    116     ARGMOD(String_iter *i), 
    117     UINTVAL c) 
    118         __attribute__nonnull__(1) 
    119         __attribute__nonnull__(2) 
    120         FUNC_MODIFIES(*i); 
    121  
    122102static UINTVAL utf8_iter_get(PARROT_INTERP, 
    123103    ARGIN(const STRING *str), 
    124104    ARGIN(const String_iter *i), 
     
    161141        __attribute__nonnull__(3) 
    162142        FUNC_MODIFIES(*i); 
    163143 
    164 static void utf8_set_position(SHIM_INTERP, 
    165     ARGMOD(String_iter *i), 
    166     UINTVAL pos) 
    167         __attribute__nonnull__(2) 
    168         FUNC_MODIFIES(*i); 
    169  
    170144PARROT_WARN_UNUSED_RESULT 
    171145PARROT_CANNOT_RETURN_NULL 
    172146static const void * utf8_skip_backward(ARGIN(const void *ptr), UINTVAL n) 
     
    194168#define ASSERT_ARGS_get_codepoints __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    195169       PARROT_ASSERT_ARG(interp) \ 
    196170    , PARROT_ASSERT_ARG(src)) 
    197 #define ASSERT_ARGS_iter_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    198        PARROT_ASSERT_ARG(src) \ 
    199     , PARROT_ASSERT_ARG(iter)) 
    200171#define ASSERT_ARGS_set_byte __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    201172       PARROT_ASSERT_ARG(interp) \ 
    202173    , PARROT_ASSERT_ARG(src)) 
     
    209180#define ASSERT_ARGS_utf8_decode __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    210181       PARROT_ASSERT_ARG(interp) \ 
    211182    , PARROT_ASSERT_ARG(ptr)) 
    212 #define ASSERT_ARGS_utf8_decode_and_advance __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    213        PARROT_ASSERT_ARG(interp) \ 
    214     , PARROT_ASSERT_ARG(i)) 
    215183#define ASSERT_ARGS_utf8_encode __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    216184       PARROT_ASSERT_ARG(interp) \ 
    217185    , PARROT_ASSERT_ARG(ptr)) 
    218 #define ASSERT_ARGS_utf8_encode_and_advance __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    219        PARROT_ASSERT_ARG(interp) \ 
    220     , PARROT_ASSERT_ARG(i)) 
    221186#define ASSERT_ARGS_utf8_iter_get __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    222187       PARROT_ASSERT_ARG(interp) \ 
    223188    , PARROT_ASSERT_ARG(str) \ 
     
    236201#define ASSERT_ARGS_utf8_iter_skip __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    237202       PARROT_ASSERT_ARG(str) \ 
    238203    , PARROT_ASSERT_ARG(i)) 
    239 #define ASSERT_ARGS_utf8_set_position __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    240        PARROT_ASSERT_ARG(i)) 
    241204#define ASSERT_ARGS_utf8_skip_backward __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    242205       PARROT_ASSERT_ARG(ptr)) 
    243206#define ASSERT_ARGS_utf8_skip_forward __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
     
    634597    i->bytepos = (const char *)u8ptr - (const char *)str->strstart; 
    635598} 
    636599 
    637 /* 
    638  
    639 =item C<static UINTVAL utf8_decode_and_advance(PARROT_INTERP, String_iter *i)> 
    640  
    641 The UTF-8 implementation of the string iterator's C<get_and_advance> 
    642 function. 
    643  
    644 =cut 
    645  
    646 */ 
    647  
    648 static UINTVAL 
    649 utf8_decode_and_advance(PARROT_INTERP, ARGMOD(String_iter *i)) 
    650 { 
    651     ASSERT_ARGS(utf8_decode_and_advance) 
    652     const utf8_t *u8ptr = (utf8_t *)((char *)i->str->strstart + i->bytepos); 
    653     UINTVAL c = *u8ptr; 
    654  
    655     if (UTF8_IS_START(c)) { 
    656         UINTVAL len = UTF8SKIP(u8ptr); 
    657  
    658         c &= UTF8_START_MASK(len); 
    659         i->bytepos += len; 
    660         for (len--; len; len--) { 
    661             u8ptr++; 
    662  
    663             if (!UTF8_IS_CONTINUATION(*u8ptr)) 
    664                 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_UTF8, 
    665                     "Malformed UTF-8 string\n"); 
    666  
    667             c = UTF8_ACCUMULATE(c, *u8ptr); 
    668         } 
    669  
    670         if (UNICODE_IS_SURROGATE(c)) 
    671             Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_UTF8, 
    672                 "Surrogate in UTF-8 string\n"); 
    673     } 
    674     else if (!UNICODE_IS_INVARIANT(c)) { 
    675         Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_UTF8, 
    676             "Malformed UTF-8 string\n"); 
    677     } 
    678     else { 
    679         i->bytepos++; 
    680     } 
    681  
    682     i->charpos++; 
    683     return c; 
    684 } 
    685  
    686 /* 
    687  
    688 =item C<static void utf8_encode_and_advance(PARROT_INTERP, String_iter *i, 
    689 UINTVAL c)> 
    690  
    691 The UTF-8 implementation of the string iterator's C<set_and_advance> 
    692 function. 
    693  
    694 =cut 
    695  
    696 */ 
    697  
    698 static void 
    699 utf8_encode_and_advance(PARROT_INTERP, ARGMOD(String_iter *i), UINTVAL c) 
    700 { 
    701     ASSERT_ARGS(utf8_encode_and_advance) 
    702     const STRING * const s = i->str; 
    703     unsigned char * const pos = (unsigned char *)s->strstart + i->bytepos; 
    704     unsigned char * const new_pos = (unsigned char *)utf8_encode(interp, pos, c); 
    705  
    706     i->bytepos += (new_pos - pos); 
    707     /* XXX possible buffer overrun exception? */ 
    708     PARROT_ASSERT(i->bytepos <= Buffer_buflen(s)); 
    709     i->charpos++; 
    710 } 
    711  
    712 /* 
    713  
    714 =item C<static void utf8_set_position(PARROT_INTERP, String_iter *i, UINTVAL 
    715 pos)> 
    716  
    717 The UTF-8 implementation of the string iterator's C<set_position> 
    718 function. 
    719  
    720 =cut 
    721  
    722 */ 
    723  
    724 static void 
    725 utf8_set_position(SHIM_INTERP, ARGMOD(String_iter *i), UINTVAL pos) 
    726 { 
    727     ASSERT_ARGS(utf8_set_position) 
    728     const utf8_t *u8ptr = (const utf8_t *)i->str->strstart; 
    729  
    730     /* start from last known charpos, if we can */ 
    731     if (i->charpos <= pos) { 
    732         const UINTVAL old_pos = pos; 
    733         pos       -= i->charpos; 
    734         u8ptr     += i->bytepos; 
    735         i->charpos = old_pos; 
    736     } 
    737     else 
    738         i->charpos = pos; 
    739  
    740     while (pos-- > 0) 
    741         u8ptr += UTF8SKIP(u8ptr); 
    742  
    743     i->bytepos = (const char *)u8ptr - (const char *)i->str->strstart; 
    744 } 
    745  
    746600 
    747601/* 
    748602 
     
    1026880 
    1027881/* 
    1028882 
    1029 =item C<static void iter_init(PARROT_INTERP, const STRING *src, String_iter 
    1030 *iter)> 
    1031  
    1032 Initializes for string C<src> the string iterator C<iter>. 
    1033  
    1034 =cut 
    1035  
    1036 */ 
    1037  
    1038 static void 
    1039 iter_init(SHIM_INTERP, ARGIN(const STRING *src), ARGOUT(String_iter *iter)) 
    1040 { 
    1041     ASSERT_ARGS(iter_init) 
    1042     iter->str             = src; 
    1043     iter->bytepos         = 0; 
    1044     iter->charpos         = 0; 
    1045     iter->get_and_advance = utf8_decode_and_advance; 
    1046     iter->set_and_advance = utf8_encode_and_advance; 
    1047     iter->set_position    = utf8_set_position; 
    1048 } 
    1049  
    1050 /* 
    1051  
    1052883=item C<void Parrot_encoding_utf8_init(PARROT_INTERP)> 
    1053884 
    1054885Initializes the UTF-8 encoding. 
     
    1074905        get_bytes, 
    1075906        codepoints, 
    1076907        bytes, 
    1077         iter_init, 
    1078908        find_cclass, 
    1079909        NULL, 
    1080910        utf8_iter_get,