Changeset 446 for branches/thune

Show
Ignore:
Timestamp:
08/08/07 03:54:30 (16 months ago)
Author:
krobillard
Message:

last & match support slice!.

Files:
1 modified

Legend:

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

    r431 r446  
    16281628        { 
    16291629            UBinary* bin = ur_bin(tos); 
    1630             if( (bin->used - tos->series.it) < 1 ) 
     1630            int n = bin->used; 
     1631            if( (n - tos->series.it) < 1 ) 
    16311632                break; 
     1633            --n; 
     1634            if( ur_encoding(tos) == UR_ENC_UTF16 ) 
     1635                ur_int(tos) = bin->ptr.u16[ n ]; 
     1636            else 
     1637                ur_int(tos) = bin->ptr.c[ n ]; 
    16321638            ur_initType( tos, UT_CHAR ); 
    1633             ur_int(tos) = bin->ptr.c[ bin->used - 1 ]; 
    16341639        } 
    16351640            return; 
     
    16481653        /* 
    16491654        case UT_COORD: 
    1650             orResult( UT_INTEGER, tos->coord[ tos->argc ] ); 
     1655            ur_int(tos) = tos->coord.elem[ tos->coord.len - 1 ]; 
     1656            ur_initType( tos, UT_INT ); 
    16511657            return; 
    16521658 
     
    16541660            break; 
    16551661        */ 
     1662 
     1663        case UT_SLICE: 
     1664            switch( ur_sliceDT(tos) ) 
     1665            { 
     1666                case UT_STRING: 
     1667                { 
     1668                    UBinary* bin = ur_bin(tos); 
     1669                    UIndex n = ur_sliceEnd( tos, bin ); 
     1670                    if( (n - tos->series.it) < 1 ) 
     1671                        break; 
     1672                    --n; 
     1673                    if( ur_encoding(tos) == UR_ENC_UTF16 ) 
     1674                        ur_int(tos) = bin->ptr.u16[ n ]; 
     1675                    else 
     1676                        ur_int(tos) = bin->ptr.c[ n ]; 
     1677                    ur_initType( tos, UT_CHAR ); 
     1678                } 
     1679                    return; 
     1680 
     1681                case UT_BINARY: 
     1682                { 
     1683                    UBinary* bin = ur_bin(tos); 
     1684                    UIndex n = ur_sliceEnd( tos, bin ); 
     1685                    if( (n - tos->series.it) < 1 ) 
     1686                        break; 
     1687                    ur_initType( tos, UT_INT ); 
     1688                    ur_int(tos) = bin->ptr.b[ n - 1 ]; 
     1689                } 
     1690                    return; 
     1691 
     1692                default: 
     1693                    ur_throwErr( UR_ERR_DATATYPE, 
     1694                                 "FIXME: last not implemented for %s slice", 
     1695                                 ur_typeName( ur_sliceDT(tos) ) ); 
     1696                    return; 
     1697            } 
     1698            break; 
    16561699 
    16571700        case UT_VECTOR: 
     
    29412984 
    29422985 
     2986/** 
     2987  Returns sit where match is complete or zero if string starting with sit 
     2988  does not match all of pattern pit to pend. 
     2989*/ 
     2990static const char* ur_match1( const char* sit, const char* send, 
     2991                              const char* pit, const char* pend ) 
     2992{ 
     2993    while( pit != pend ) 
     2994    { 
     2995        if( sit == send ) 
     2996            return 0; 
     2997        if( *sit != *pit ) 
     2998            return 0; 
     2999        ++sit; 
     3000        ++pit; 
     3001    } 
     3002    return sit; 
     3003} 
     3004 
     3005 
    29433006/* 
    29443007  (series value -- series) 
     
    29563019        case UT_STRING: 
    29573020        { 
    2958             int found; 
    2959             UString* s1 = ur_bin(res); 
    2960  
    29613021            if( ur_is(tos, UT_CHAR) ) 
    29623022            { 
     
    29733033            else if( ur_is(tos, UT_STRING) || ur_is(tos, UT_BINARY) ) 
    29743034            { 
    2975                 UString* s2 = ur_bin(tos); 
    2976                 if( s2->used ) 
    2977                 { 
    2978                     found = ur_matchString( s1, res->series.it, 
    2979                                             s2, tos->series.it ); 
    2980                     if( found ) 
    2981                     { 
    2982                         res->series.it = found; 
    2983                         return; 
    2984                     } 
    2985                 } 
     3035                goto match_bytes; 
     3036            } 
     3037            else if( ur_is(tos, UT_SLICE) && 
     3038                    ((ur_sliceDT(res) == UT_STRING) || 
     3039                     (ur_sliceDT(res) == UT_BINARY)) ) 
     3040            { 
     3041                goto match_bytes; 
    29863042            } 
    29873043        } 
     
    30043060        } 
    30053061            goto ret_none; 
     3062 
     3063        case UT_SLICE: 
     3064            if( ((ur_sliceDT(res) == UT_STRING) || 
     3065                 (ur_sliceDT(res) == UT_BINARY)) && 
     3066                (ur_is(tos, UT_STRING) || ur_is(tos, UT_BINARY)) ) 
     3067                goto match_bytes; 
     3068            goto ret_none; 
    30063069    } 
    30073070 
     
    30133076    ur_initType(res, UT_NONE); 
    30143077    return; 
     3078 
     3079match_bytes: 
     3080    { 
     3081        const char* eom; 
     3082        char* pA; 
     3083        char* pB; 
     3084        char* sA; 
     3085        char* sB; 
     3086 
     3087        ur_seriesMem( ut, res, &sA, &sB ); 
     3088        ur_seriesMem( ut, tos, &pA, &pB ); 
     3089 
     3090        eom = ur_match1( sA, sB, pA, pB ); 
     3091        if( eom ) 
     3092        { 
     3093            res->series.it += eom - sA; 
     3094            return; 
     3095        } 
     3096    } 
     3097    goto ret_none; 
    30153098} 
    30163099