Changeset 413 for branches/thune

Show
Ignore:
Timestamp:
06/16/07 22:57:19 (17 months ago)
Author:
krobillard
Message:

change now handles optional int! part.

Files:
1 modified

Legend:

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

    r393 r413  
    23662366 
    23672367/* 
    2368   (ser new -- ser) 
     2368   Returns index in dst where copy of src ends. 
     2369*/ 
     2370static UIndex _changeBytes( UBinary* dst, UIndex di, 
     2371                            UBinary* src, UIndex si, int part ) 
     2372{ 
     2373    int slen = src->used - si; 
     2374    if( slen > 0 ) 
     2375    { 
     2376        UIndex newIndex = di + slen; 
     2377 
     2378        if( (part > 0) && (part < slen) ) 
     2379        { 
     2380            part = slen - part; 
     2381 
     2382            ur_arrayReserve( dst, sizeof(char), dst->used + part ); 
     2383 
     2384            copyReverseC( dst->ptr.c + dst->used - 1, 
     2385                          dst->ptr.c + di - 1, 
     2386                          dst->ptr.c + dst->used + part - 1 ); 
     2387 
     2388            dst->used += part; 
     2389        } 
     2390        else 
     2391        { 
     2392            ur_arrayReserve( dst, sizeof(char), newIndex ); 
     2393 
     2394            if( newIndex > dst->used ) 
     2395                dst->used = newIndex; 
     2396        } 
     2397 
     2398        // TODO: Handle overwritting self when dst is src. 
     2399        memCpy( dst->ptr.c + di, 
     2400                src->ptr.c + si, slen ); 
     2401 
     2402        return newIndex; 
     2403    } 
     2404    return di; 
     2405} 
     2406 
     2407 
     2408/* 
     2409  (ser new [part] -- ser) 
    23692410*/ 
    23702411UR_CALL( uc_change ) 
    23712412{ 
    2372     UCell* a1 = ur_s_prev(tos); 
    2373  
    2374     UR_S_DROP; 
     2413    UCell* a1; 
     2414    int part = 0; 
     2415 
     2416    if( ur_is(tos, UT_INT) ) 
     2417    { 
     2418        part = ur_int(tos); 
     2419        tos = ur_s_prev(tos); 
     2420        UR_S_DROP; 
     2421    } 
     2422 
     2423    a1 = ur_s_prev(tos); 
    23752424 
    23762425    switch( ur_type(a1) ) 
     
    23792428        case UT_STRING: 
    23802429        { 
    2381             int len2; 
    23822430            UBinary* s1; 
    2383             UBinary* s2; 
    2384  
    2385             if( ur_type(tos) == UT_STRING ) 
     2431 
     2432            if( ur_is(tos, UT_STRING) ) 
    23862433            { 
    23872434                if( ur_encCharSize(tos) != 1 ) 
    23882435                    goto type_err; 
    23892436            } 
    2390             else if( ur_type(tos) != UT_BINARY ) 
     2437            else if( ! ur_is(tos, UT_BINARY) ) 
    23912438            { 
    23922439                goto type_err; 
     
    23962443            assert( a1->series.it <= s1->used ); 
    23972444 
    2398             if( ur_is(tos, UT_CHAR ) ) 
     2445            if( ur_is(tos, UT_CHAR) ) 
    23992446            { 
    24002447                if( a1->series.it == s1->used ) 
     
    24052452                s1->ptr.b[ a1->series.it ] = ur_char(tos); 
    24062453                a1->series.it += 1; 
    2407                 return; 
    2408             } 
    2409  
    2410             // TODO: Handle overwritting itself. 
    2411             assert( a1->series.n != tos->series.n ); 
    2412  
    2413             s2 = ur_bin(tos); 
    2414             assert( tos->series.it <= s2->used ); 
    2415  
    2416             len2 = s2->used - tos->series.it; 
    2417             if( len2 > 0 ) 
    2418             { 
    2419                 int newIndex; 
    2420                 newIndex = a1->series.it + len2; 
    2421 #if 0 
    2422                 if( orRefineSet(REF_CHANGE_PART) ) 
    2423                 { 
    2424                     int range; 
    2425                     UCell* rngVal = REF_CHANGE_RANGE; 
    2426  
    2427                     if( rngVal->type == UT_INTEGER ) 
    2428                         range = rngVal->integer; 
    2429                     else 
    2430                         range = rngVal->series.it - a1->series.it; 
    2431  
    2432                     if( range < len2 ) 
    2433                     { 
    2434                         if( range < 0 ) 
    2435                             range = 0; 
    2436  
    2437                         range = len2 - range; 
    2438  
    2439                         ur_arrayReserve( s1, sizeof(char), 
    2440                                         s1->used + range ); 
    2441  
    2442                         copyReverseC(s1->ptr.c + s1->used - 1, 
    2443                                      s1->ptr.c + a1->series.it - 1, 
    2444                                      s1->ptr.c + s1->used + range - 1); 
    2445  
    2446                         s1->used += range; 
    2447                         goto str_copy; 
    2448                     } 
    2449                 } 
    2450 #endif 
    2451                 ur_arrayReserve( s1, sizeof(char), newIndex ); 
    2452  
    2453                 if( newIndex > s1->used ) 
    2454                     s1->used = newIndex; 
    2455 //str_copy: 
    2456                 memCpy( s1->ptr.c + a1->series.it, 
    2457                         s2->ptr.c + tos->series.it, len2 ); 
    2458  
    2459                 // Result. 
    2460                 a1->series.it = newIndex; 
    2461                 return; 
    2462             } 
     2454            } 
     2455            else 
     2456            { 
     2457                a1->series.it = _changeBytes( s1, a1->series.it, 
     2458                                              ur_bin(tos), tos->series.it, 
     2459                                              part ); 
     2460            } 
     2461            UR_S_DROP; 
    24632462        } 
    24642463            return;