Show
Ignore:
Timestamp:
06/22/07 20:53:35 (17 months ago)
Author:
krobillard
Message:

Added ur_seriesMem() & fold helper.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/thune/thread_safe/series.c

    r413 r417  
    9696 
    9797/** 
    98   Get pointers to the start and end characters of a string! or string slice!. 
     98  Get pointers to the start and end of a series or slice. 
    9999 
    100100  \returns 
    101     Pointer to UString if cell is a string! or string slice!.  
     101    Pointer to UBinary if cell is a series or slice. 
    102102    Otherwise, zero is returned. 
    103103    If the pointer is non-zero then cpA & cpB are set to point to the 
     
    105105    The character pointers will be zero if the string is empty. 
    106106*/ 
     107UBinary* ur_seriesMem( UThread* ut, const UCell* cell, 
     108                       char** cpA, char** cpB ) 
     109{ 
     110    UBinary* bin; 
     111    int end; 
     112 
     113    switch( ur_type(cell) ) 
     114    { 
     115        case UT_BINARY: 
     116            bin = ur_bin(cell); 
     117            if( ! bin->used ) 
     118                goto empty; 
     119            end = bin->used; 
     120            goto set_pointers; 
     121 
     122        case UT_STRING: 
     123            bin = ur_bin(cell); 
     124            if( ! bin->used ) 
     125                goto empty; 
     126            end = bin->used; 
     127            if( ur_encoding(cell) == UR_ENC_UTF16 ) 
     128                goto set_pointers2; 
     129            goto set_pointers; 
     130 
     131        case UT_SLICE: 
     132            if( ur_sliceDT(cell) == UT_BINARY ) 
     133            { 
     134                bin = ur_bin(cell); 
     135                if( ! bin->used ) 
     136                    goto empty; 
     137                end = ur_sliceEnd(cell, bin); 
     138                goto set_pointers; 
     139            } 
     140            else if( ur_sliceDT(cell) == UT_STRING ) 
     141            { 
     142                bin = ur_bin(cell); 
     143                if( ! bin->used ) 
     144                    goto empty; 
     145                end = ur_sliceEnd(cell, bin); 
     146                if( ur_encoding(cell) == UR_ENC_UTF16 ) 
     147                    goto set_pointers2; 
     148                goto set_pointers; 
     149            } 
     150            break; 
     151 
     152        case UT_VECTOR: 
     153            bin = ur_bin(cell); 
     154            if( ! bin->used ) 
     155                goto empty; 
     156            end = bin->used; 
     157            goto set_pointers4; 
     158    } 
     159    return 0; 
     160 
     161set_pointers: 
     162 
     163    *cpA = bin->ptr.c + cell->series.it; 
     164    *cpB = bin->ptr.c + end; 
     165    return bin; 
     166 
     167set_pointers2: 
     168 
     169    *cpA = (char*) (bin->ptr.u16 + cell->series.it); 
     170    *cpB = (char*) (bin->ptr.u16 + end); 
     171    return bin; 
     172 
     173set_pointers4: 
     174 
     175    *cpA = (char*) (bin->ptr.i + cell->series.it); 
     176    *cpB = (char*) (bin->ptr.i + end); 
     177    return bin; 
     178 
     179empty: 
     180 
     181    *cpA = *cpB = 0; 
     182    return bin; 
     183} 
     184 
     185 
     186/** 
     187  Get pointers to the start and end characters of a string! or string slice!. 
     188 
     189  \see ur_seriesMem() 
     190*/ 
    107191UString* ur_stringSlice( UThread* ut, const UCell* cell, 
    108192                         char** cpA, char** cpB ) 
    109193{ 
    110     UString* str; 
    111     int end; 
    112  
    113     if( ur_is(cell, UT_STRING) ) 
    114     { 
    115         str = ur_bin(cell); 
    116         if( ! str->used ) 
    117             goto empty; 
    118         end = str->used; 
    119  
    120 set_pointers: 
    121          
    122         if( ur_encoding(cell) == UR_ENC_UTF16 ) 
    123         { 
    124             *cpA = (char*) (str->ptr.u16 + cell->series.it); 
    125             *cpB = (char*) (str->ptr.u16 + end); 
    126         } 
    127         else 
    128         { 
    129             *cpA = str->ptr.c + cell->series.it; 
    130             *cpB = str->ptr.c + end; 
    131         } 
    132         return str; 
    133     } 
    134     else if( ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_STRING) ) 
    135     { 
    136         str = ur_bin(cell); 
    137         if( ! str->used ) 
    138             goto empty; 
    139         end = ur_sliceEnd(cell, str); 
    140         goto set_pointers; 
    141     } 
     194    if( ur_is(cell, UT_STRING) || 
     195        (ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_STRING)) ) 
     196        return ur_seriesMem( ut, cell, cpA, cpB ); 
    142197    return 0; 
    143  
    144 empty: 
    145  
    146     *cpA = *cpB = 0; 
    147     return str; 
    148198} 
    149199 
     
    152202  Get pointers to the start and end characters of a binary! or binary slice!. 
    153203 
    154   \see ur_stringSlice() 
     204  \see ur_seriesMem() 
    155205*/ 
    156206UBinary* ur_binarySlice( UThread* ut, const UCell* cell, 
    157207                         char** cpA, char** cpB ) 
    158208{ 
    159     UBinary* str; 
    160     int end; 
    161  
    162     if( ur_is(cell, UT_BINARY) ) 
    163     { 
    164         str = ur_bin(cell); 
    165         if( ! str->used ) 
    166             goto empty; 
    167         end = str->used; 
    168  
    169 set_pointers: 
    170          
    171         *cpA = str->ptr.c + cell->series.it; 
    172         *cpB = str->ptr.c + end; 
    173         return str; 
    174     } 
    175     else if( ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_BINARY) ) 
    176     { 
    177         str = ur_bin(cell); 
    178         if( ! str->used ) 
    179             goto empty; 
    180         end = ur_sliceEnd(cell, str); 
    181         goto set_pointers; 
    182     } 
     209    if( ur_is(cell, UT_BINARY) || 
     210        (ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_BINARY)) ) 
     211        return ur_seriesMem( ut, cell, cpA, cpB ); 
    183212    return 0; 
    184  
    185 empty: 
    186  
    187     *cpA = *cpB = 0; 
    188     return str; 
    189213} 
    190214 
     
    193217  Get pointers to the start and end cells of a block or paren slice!. 
    194218 
    195   \see ur_stringSlice() 
     219  \see ur_seriesMem() 
    196220*/ 
    197221UBlock* ur_blockSlice( UThread* ut, const UCell* cell,