Changeset 1212

Show
Ignore:
Timestamp:
07/04/09 03:14:33 (3 years ago)
Author:
andrei
Message:

minor

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/regex.d

    r1111 r1212  
    15171517} 
    15181518 
    1519 /***************************** 
     1519/** 
    15201520$(D RegexMatch) is the type returned by a call to $(D match). It 
    15211521stores the matching state and can be inspected and iterated. 
     
    15711571    } 
    15721572     
     1573    // ref auto opSlice() 
     1574    // { 
     1575    //     return this; 
     1576    // } 
     1577 
    15731578/** 
    15741579Range primitives that allow incremental matching against a string. 
     
    15931598--- 
    15941599 */ 
    1595  
    1596     ref auto opSlice() 
    1597     { 
    1598         return this; 
    1599     } 
    1600  
    16011600    bool empty() const 
    16021601    { 
     
    26622661            { 
    26632662            case '&': 
    2664                 result ~= input[pmatch[0].startIdx .. pmatch[0].endIdx]; 
     2663                result ~= to!string( 
     2664                    input[pmatch[0].startIdx .. pmatch[0].endIdx]); 
    26652665                break; 
    26662666 
     
    26752675                        if (j <= engine.re_nsub && pmatch[j].startIdx 
    26762676                                != pmatch[j].endIdx) 
    2677                             result ~= 
    2678                                 input[pmatch[j].startIdx .. pmatch[j].endIdx]
     2677                            result ~= to!string 
     2678                                (input[pmatch[j].startIdx .. pmatch[j].endIdx])
    26792679                        break; 
    26802680                    } 
     
    29172917    { 
    29182918        _input = input; 
    2919         _match = match(_input, separator); 
     2919        if (_input.empty) 
     2920        { 
     2921            // there is nothing to match at all, make _offset > 0 
     2922            _offset = 1; 
     2923        } 
     2924        else 
     2925        { 
     2926            _match = match(_input, separator); 
     2927        } 
    29202928    } 
    29212929 
     
    29342942    { 
    29352943        //write("[");scope(success) writeln("]"); 
    2936         assert(_offset <= _match.pre.length 
     2944        assert(!empty && _offset <= _match.pre.length 
    29372945                && _match.pre.length <= _input.length); 
    29382946        return _input[_offset .. min($, _match.pre.length)]; 
     
    29412949    bool empty() 
    29422950    { 
    2943         return _offset >= _input.length; 
     2951        return _offset > _input.length; 
    29442952    } 
    29452953 
     
    29512959        { 
    29522960            // No more separators, work is done here 
    2953             _offset = _input.length
     2961            _offset = _input.length + 1
    29542962        } 
    29552963        else 
     
    29752983    auto s1 = ", abc, de,  fg, hi, "; 
    29762984    auto sp1 = splitter(s1, regex(", *")); 
    2977     auto w1 = ["", "abc", "de", "fg", "hi"]; 
     2985    auto w1 = ["", "abc", "de", "fg", "hi", ""]; 
    29782986    assert(equal(sp1, w1[])); 
    29792987 
     
    29892997    char[] s1 = ", abc, de,  fg, hi, ".dup; 
    29902998    auto sp2 = splitter(s1, regex(", *")); 
     2999} 
     3000 
     3001String[] split(String)(String input, Regex!(char) rx) 
     3002{ 
     3003    Appender!(String[]) a; 
     3004    foreach (e; splitter(input, rx)) 
     3005    { 
     3006        a.put(e); 
     3007    } 
     3008    return a.data; 
     3009} 
     3010 
     3011unittest 
     3012{ 
     3013    auto s1 = ", abc, de,  fg, hi, "; 
     3014    auto w1 = ["", "abc", "de", "fg", "hi", ""]; 
     3015    assert(equal(split(s1, regex(", *")), w1[])); 
    29913016} 
    29923017