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

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

    diff --git a/include/parrot/encoding.h b/include/parrot/encoding.h
    index 5965ad6..0aa07f9 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; 
     
    224221    ((src)->encoding)->codepoints((i), (src)) 
    225222#define ENCODING_BYTES(i, src) \ 
    226223    ((src)->encoding)->bytes((i), (src)) 
    227 #define ENCODING_ITER_INIT(i, src, iter) \ 
    228     ((src)->encoding)->iter_init((i), (src), (iter)) 
    229224#define ENCODING_FIND_CCLASS(i, src, typetable, flags, pos, end) \ 
    230225    ((src)->encoding)->find_cclass((i), (src), (typetable), (flags), (pos), (end)) 
    231226#define ENCODING_HASH(i, src, seed) \ 
  • include/parrot/string.h

    diff --git a/include/parrot/string.h b/include/parrot/string.h
    index d02f5c1..55df3c3 100644
    a b  
    3030 
    3131/* String iterator */ 
    3232typedef struct string_iterator_t { 
    33     const STRING *str; 
    3433    UINTVAL bytepos; 
    3534    UINTVAL charpos; 
    36     UINTVAL (*get_and_advance)(PARROT_INTERP, struct string_iterator_t *i); 
    37     void (*set_and_advance)(PARROT_INTERP, struct string_iterator_t *i, UINTVAL c); 
    38     void (*set_position)(PARROT_INTERP, struct string_iterator_t *i, UINTVAL pos); 
    3935} String_iter; 
    4036 
    4137#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 ec51147..be45421 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 *src), 
    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(src)) 
    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(src)) 
     
    537501 
    538502/* 
    539503 
    540 =item C<static UINTVAL fixed8_get_next(PARROT_INTERP, String_iter *iter)> 
    541  
    542 Moves the string iterator C<i> to the next codepoint. 
    543  
    544 =cut 
    545  
    546 */ 
    547  
    548 static UINTVAL 
    549 fixed8_get_next(PARROT_INTERP, ARGMOD(String_iter *iter)) 
    550 { 
    551     ASSERT_ARGS(fixed8_get_next) 
    552     const UINTVAL c = get_byte(interp, iter->str, iter->charpos++); 
    553     ++iter->bytepos; 
    554     return c; 
    555 } 
    556  
    557 /* 
    558  
    559 =item C<static void fixed8_set_next(PARROT_INTERP, String_iter *iter, UINTVAL 
    560 c)> 
    561  
    562 With the string iterator C<i>, appends the codepoint C<c> and advances to the 
    563 next position in the string. 
    564  
    565 =cut 
    566  
    567 */ 
    568  
    569 static void 
    570 fixed8_set_next(PARROT_INTERP, ARGMOD(String_iter *iter), UINTVAL c) 
    571 { 
    572     ASSERT_ARGS(fixed8_set_next) 
    573     set_byte(interp, iter->str, iter->charpos++, c); 
    574     ++iter->bytepos; 
    575 } 
    576  
    577 /* 
    578  
    579 =item C<static void fixed8_set_position(PARROT_INTERP, String_iter *iter, 
    580 UINTVAL pos)> 
    581  
    582 Moves the string iterator C<i> to the position C<n> in the string. 
    583  
    584 =cut 
    585  
    586 */ 
    587  
    588 static void 
    589 fixed8_set_position(SHIM_INTERP, ARGMOD(String_iter *iter), UINTVAL pos) 
    590 { 
    591     ASSERT_ARGS(fixed8_set_position) 
    592     iter->bytepos = iter->charpos = pos; 
    593     PARROT_ASSERT(pos <= Buffer_buflen(iter->str)); 
    594 } 
    595  
    596  
    597 /* 
    598  
    599 =item C<static void iter_init(PARROT_INTERP, const STRING *src, String_iter 
    600 *iter)> 
    601  
    602 Initializes for string C<src> the string iterator C<iter>. 
    603  
    604 =cut 
    605  
    606 */ 
    607  
    608 static void 
    609 iter_init(SHIM_INTERP, ARGIN(const STRING *src), ARGOUT(String_iter *iter)) 
    610 { 
    611     ASSERT_ARGS(iter_init) 
    612     iter->str             = src; 
    613     iter->bytepos         = iter->charpos        = 0; 
    614     iter->get_and_advance = fixed8_get_next; 
    615     iter->set_and_advance = fixed8_set_next; 
    616     iter->set_position    = fixed8_set_position; 
    617 } 
    618  
    619  
    620 /* 
    621  
    622504=item C<static size_t fixed_8_hash(PARROT_INTERP, const STRING *s, size_t 
    623505hashval)> 
    624506 
     
    671553        get_bytes, 
    672554        codepoints, 
    673555        bytes, 
    674         iter_init, 
    675556        find_cclass, 
    676557        fixed_8_hash, 
    677558        fixed8_iter_get, 
  • src/string/encoding/ucs2.c

    diff --git a/src/string/encoding/ucs2.c b/src/string/encoding/ucs2.c
    index 6e2ec93..2f91bd5 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/ucs4.c

    diff --git a/src/string/encoding/ucs4.c b/src/string/encoding/ucs4.c
    index e4d0409..462cc96 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 ucs4_decode_and_advance(PARROT_INTERP, 
    108     ARGMOD(String_iter *i)) 
    109         __attribute__nonnull__(1) 
    110         __attribute__nonnull__(2) 
    111         FUNC_MODIFIES(*i); 
    112  
    113 static void ucs4_encode_and_advance(PARROT_INTERP, 
    114     ARGMOD(String_iter *i), 
    115     UINTVAL c) 
    116         __attribute__nonnull__(1) 
    117         __attribute__nonnull__(2) 
    118         FUNC_MODIFIES(*i); 
    119  
    12099static size_t ucs4_hash(PARROT_INTERP, 
    121100    ARGIN(const STRING *s), 
    122101    size_t hashval) 
     
    167146        __attribute__nonnull__(3) 
    168147        FUNC_MODIFIES(*i); 
    169148 
    170 static void ucs4_set_position(PARROT_INTERP, 
    171     ARGMOD(String_iter *i), 
    172     UINTVAL n) 
    173         __attribute__nonnull__(1) 
    174         __attribute__nonnull__(2) 
    175         FUNC_MODIFIES(*i); 
    176  
    177149#define ASSERT_ARGS_bytes __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    178150       PARROT_ASSERT_ARG(src)) 
    179151#define ASSERT_ARGS_codepoints __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
     
    193165#define ASSERT_ARGS_get_codepoints __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    194166       PARROT_ASSERT_ARG(interp) \ 
    195167    , PARROT_ASSERT_ARG(src)) 
    196 #define ASSERT_ARGS_iter_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    197        PARROT_ASSERT_ARG(interp) \ 
    198     , PARROT_ASSERT_ARG(src) \ 
    199     , PARROT_ASSERT_ARG(iter)) 
    200168#define ASSERT_ARGS_set_byte __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    201169       PARROT_ASSERT_ARG(interp)) 
    202170#define ASSERT_ARGS_to_encoding __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    203171       PARROT_ASSERT_ARG(interp) \ 
    204172    , PARROT_ASSERT_ARG(src)) 
    205 #define ASSERT_ARGS_ucs4_decode_and_advance __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    206        PARROT_ASSERT_ARG(interp) \ 
    207     , PARROT_ASSERT_ARG(i)) 
    208 #define ASSERT_ARGS_ucs4_encode_and_advance __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    209        PARROT_ASSERT_ARG(interp) \ 
    210     , PARROT_ASSERT_ARG(i)) 
    211173#define ASSERT_ARGS_ucs4_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    212174       PARROT_ASSERT_ARG(interp) \ 
    213175    , PARROT_ASSERT_ARG(s)) 
     
    231193       PARROT_ASSERT_ARG(interp) \ 
    232194    , PARROT_ASSERT_ARG(str) \ 
    233195    , PARROT_ASSERT_ARG(i)) 
    234 #define ASSERT_ARGS_ucs4_set_position __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    235        PARROT_ASSERT_ARG(interp) \ 
    236     , PARROT_ASSERT_ARG(i)) 
    237196/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */ 
    238197/* HEADERIZER END: static */ 
    239198 
     
    611570#endif 
    612571} 
    613572 
    614 /* 
    615  
    616 =item C<static UINTVAL ucs4_decode_and_advance(PARROT_INTERP, String_iter *i)> 
    617  
    618 Moves the string iterator C<i> to the next UCS-4 codepoint. 
    619  
    620 =cut 
    621  
    622 */ 
    623  
    624 static UINTVAL 
    625 ucs4_decode_and_advance(PARROT_INTERP, ARGMOD(String_iter *i)) 
    626 { 
    627     ASSERT_ARGS(ucs4_decode_and_advance) 
    628 #if PARROT_HAS_ICU 
    629     const UChar32 * const s = (const UChar32 *) i->str->strstart; 
    630     size_t pos              = i->bytepos / sizeof (UChar32); 
    631     const UChar32         c = s[pos++]; 
    632     ++i->charpos; 
    633     i->bytepos = pos * sizeof (UChar32); 
    634     return c; 
    635 #else 
    636     UNUSED(i); 
    637     no_ICU_lib(interp); 
    638 #endif 
    639 } 
    640  
    641 /* 
    642  
    643 =item C<static void ucs4_encode_and_advance(PARROT_INTERP, String_iter *i, 
    644 UINTVAL c)> 
    645  
    646 With the string iterator C<i>, appends the codepoint C<c> and advances to the 
    647 next position in the string. 
    648  
    649 =cut 
    650  
    651 */ 
    652  
    653 static void 
    654 ucs4_encode_and_advance(PARROT_INTERP, ARGMOD(String_iter *i), UINTVAL c) 
    655 { 
    656     ASSERT_ARGS(ucs4_encode_and_advance) 
    657 #if PARROT_HAS_ICU 
    658     UChar32 *s   = (UChar32 *) i->str->strstart; 
    659     size_t   pos = i->bytepos / sizeof (UChar32); 
    660     s[pos++] = (UChar32) c; 
    661     ++i->charpos; 
    662     i->bytepos = pos * sizeof (UChar32); 
    663 #else 
    664     UNUSED(i); 
    665     no_ICU_lib(interp); 
    666 #endif 
    667 } 
    668  
    669573#if PARROT_HAS_ICU 
    670574/* 
    671575 
     
    696600 
    697601/* 
    698602 
    699 =item C<static void ucs4_set_position(PARROT_INTERP, String_iter *i, UINTVAL n)> 
    700  
    701 Moves the string iterator C<i> to the position C<n> in the string. 
    702  
    703 =cut 
    704  
    705 */ 
    706  
    707 static void 
    708 ucs4_set_position(PARROT_INTERP, ARGMOD(String_iter *i), UINTVAL n) 
    709 { 
    710     ASSERT_ARGS(ucs4_set_position) 
    711 #if PARROT_HAS_ICU 
    712     i->charpos = n; 
    713     i->bytepos = n * sizeof (UChar32); 
    714 #else 
    715     UNUSED(i); 
    716     UNUSED(n); 
    717     no_ICU_lib(interp); 
    718 #endif 
    719 } 
    720  
    721  
    722 /* 
    723  
    724 =item C<static void iter_init(PARROT_INTERP, const STRING *src, String_iter 
    725 *iter)> 
    726  
    727 Initializes for string C<src> the string iterator C<iter>. 
    728  
    729 =cut 
    730  
    731 */ 
    732  
    733 static void 
    734 iter_init(PARROT_INTERP, ARGIN(const STRING *src), ARGOUT(String_iter *iter)) 
    735 { 
    736     ASSERT_ARGS(iter_init) 
    737 #if PARROT_HAS_ICU 
    738     UNUSED(interp); 
    739     iter->str             = src; 
    740     iter->bytepos         = 0; 
    741     iter->charpos         = 0; 
    742     iter->get_and_advance = ucs4_decode_and_advance; 
    743     iter->set_and_advance = ucs4_encode_and_advance; 
    744     iter->set_position    = ucs4_set_position; 
    745 #else 
    746     UNUSED(src); 
    747     UNUSED(iter); 
    748     no_ICU_lib(interp); 
    749 #endif 
    750 } 
    751  
    752 /* 
    753  
    754603=item C<void Parrot_encoding_ucs4_init(PARROT_INTERP)> 
    755604 
    756605Initializes the UCS-4 encoding. 
     
    776625        get_bytes, 
    777626        codepoints, 
    778627        bytes, 
    779         iter_init, 
    780628        find_cclass, 
    781629#if PARROT_HAS_ICU 
    782630        ucs4_hash, 
  • src/string/encoding/utf16.c

    diff --git a/src/string/encoding/utf16.c b/src/string/encoding/utf16.c
    index 2570de5..d43bcdf 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 
     
    726691#endif 
    727692} 
    728693 
    729 #if PARROT_HAS_ICU 
    730 /* 
    731  
    732 =item C<static UINTVAL utf16_decode_and_advance(PARROT_INTERP, String_iter *i)> 
    733  
    734 Moves the string iterator C<i> to the next UTF-16 codepoint. 
    735  
    736 =cut 
    737  
    738 */ 
    739  
    740 PARROT_WARN_UNUSED_RESULT 
    741 static UINTVAL 
    742 utf16_decode_and_advance(SHIM_INTERP, ARGMOD(String_iter *i)) 
    743 { 
    744     ASSERT_ARGS(utf16_decode_and_advance) 
    745     const UChar * const s = (const UChar*) i->str->strstart; 
    746     UINTVAL pos = i->bytepos / sizeof (UChar); 
    747     UINTVAL c; 
    748  
    749     /* TODO either make sure that we don't go past end or use SAFE 
    750      *      iter versions 
    751      */ 
    752     U16_NEXT_UNSAFE(s, pos, c); 
    753     ++i->charpos; 
    754     i->bytepos = pos * sizeof (UChar); 
    755     return c; 
    756 } 
    757  
    758 /* 
    759  
    760 =item C<static void utf16_encode_and_advance(PARROT_INTERP, String_iter *i, 
    761 UINTVAL c)> 
    762  
    763 With the string iterator C<i>, appends the codepoint C<c> and advances to the 
    764 next position in the string. 
    765  
    766 =cut 
    767  
    768 */ 
    769  
    770 static void 
    771 utf16_encode_and_advance(SHIM_INTERP, ARGMOD(String_iter *i), UINTVAL c) 
    772 { 
    773     ASSERT_ARGS(utf16_encode_and_advance) 
    774     UChar * const s = (UChar*) i->str->strstart; 
    775     UINTVAL pos = i->bytepos / sizeof (UChar); 
    776     U16_APPEND_UNSAFE(s, pos, c); 
    777     ++i->charpos; 
    778     i->bytepos = pos * sizeof (UChar); 
    779 } 
    780  
    781 /* 
    782  
    783 =item C<static void utf16_set_position(PARROT_INTERP, String_iter *i, UINTVAL 
    784 n)> 
    785  
    786 Moves the string iterator C<i> to the position C<n> in the string. 
    787  
    788 =cut 
    789  
    790 */ 
    791  
    792 static void 
    793 utf16_set_position(SHIM_INTERP, ARGMOD(String_iter *i), UINTVAL n) 
    794 { 
    795     ASSERT_ARGS(utf16_set_position) 
    796     UChar * const s = (UChar*) i->str->strstart; 
    797     UINTVAL pos; 
    798     pos = 0; 
    799     U16_FWD_N_UNSAFE(s, pos, n); 
    800     i->charpos = n; 
    801     i->bytepos = pos * sizeof (UChar); 
    802 } 
    803  
    804 #endif 
    805  
    806 /* 
    807  
    808 =item C<static void iter_init(PARROT_INTERP, const STRING *src, String_iter 
    809 *iter)> 
    810  
    811 Initializes for string C<src> the string iterator C<iter>. 
    812  
    813 =cut 
    814  
    815 */ 
    816  
    817 static void 
    818 iter_init(PARROT_INTERP, ARGIN(const STRING *src), ARGOUT(String_iter *iter)) 
    819 { 
    820     ASSERT_ARGS(iter_init) 
    821     iter->str = src; 
    822     iter->bytepos = iter->charpos = 0; 
    823 #if PARROT_HAS_ICU 
    824     UNUSED(interp); 
    825     iter->get_and_advance = utf16_decode_and_advance; 
    826     iter->set_and_advance = utf16_encode_and_advance; 
    827     iter->set_position =    utf16_set_position; 
    828 #else 
    829     Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR, 
    830         "no ICU lib loaded"); 
    831 #endif 
    832 } 
    833  
    834694/* 
    835695 
    836696=item C<void Parrot_encoding_utf16_init(PARROT_INTERP)> 
     
    858718        get_bytes, 
    859719        codepoints, 
    860720        bytes, 
    861         iter_init, 
    862721        find_cclass, 
    863722        NULL, 
    864723        utf16_iter_get, 
  • src/string/encoding/utf8.c

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