Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1097: tango.text.Util.d.diff

File tango.text.Util.d.diff, 12.4 kB (added by Krox, 4 months ago)

text.Util.d.diff

  • tango/text/Util.d

    old new  
    105105 
    106106T[] trim(T) (T[] source) 
    107107{ 
    108         T*   head = source.ptr, 
    109              tail = head + source.length; 
     108        size_t head = 0; 
     109        size_t tail = source.length; 
    110110 
    111         while (head < tail && isSpace(*head)) 
    112                ++head; 
     111        while (head < tail && isSpace(source[head])) 
     112                ++head; 
    113113 
    114         while (tail > head && isSpace(*(tail-1))) 
    115                --tail; 
     114        while (tail > head && isSpace(source[tail-1])) 
     115                --tail; 
    116116 
    117         return head [0 .. tail - head]; 
     117        return source [head .. tail]; 
    118118} 
    119119 
    120120/****************************************************************************** 
     
    126126 
    127127T[] triml(T) (T[] source) 
    128128{ 
    129         T*   head = source.ptr, 
    130              tail = head + source.length; 
     129        size_t head = 0; 
    131130 
    132         while (head < tail && isSpace(*head)) 
     131        while (head < source.length && isSpace(source[head])) 
    133132               ++head; 
    134133 
    135         return head [0 .. tail - head]; 
     134        return source [head .. $]; 
    136135} 
    137136 
    138137/****************************************************************************** 
     
    144143 
    145144T[] trimr(T) (T[] source) 
    146145{ 
    147         T*   head = source.ptr, 
    148              tail = head + source.length; 
     146        size_t tail = source.length; 
    149147 
    150         while (tail > head && isSpace(*(tail-1))) 
     148        while (tail > 0 && isSpace(source[tail-1])) 
    151149               --tail; 
    152150 
    153         return head [0 .. tail - head]; 
     151        return source [0 .. tail]; 
    154152} 
    155153 
    156154/****************************************************************************** 
     
    162160 
    163161T[] strip(T) (T[] source, T match) 
    164162{ 
    165         T*   head = source.ptr, 
    166              tail = head + source.length; 
     163        size_t head = 0; 
     164        size_t tail = source.length; 
    167165 
    168         while (head < tail && *head is match) 
    169                ++head; 
     166        while (head < tail && source[head] is match) 
     167                ++head; 
    170168 
    171         while (tail > head && *(tail-1) is match) 
    172                --tail; 
     169        while (tail > head && source[tail-1] is match) 
     170                --tail; 
    173171 
    174         return head [0 .. tail - head]; 
     172        return source [head .. tail]; 
    175173} 
    176174 
    177175/****************************************************************************** 
     
    183181 
    184182T[] stripl(T) (T[] source, T match) 
    185183{ 
    186         T*   head = source.ptr, 
    187              tail = head + source.length; 
     184        size_t head = 0; 
    188185 
    189         while (head < tail && *head is match) 
    190                ++head; 
     186        while (head < source.length && source[head] is match) 
     187                ++head; 
    191188 
    192         return head [0 .. tail - head]; 
     189        return source [head .. $]; 
    193190} 
    194191 
    195192/****************************************************************************** 
     
    201198 
    202199T[] stripr(T) (T[] source, T match) 
    203200{ 
    204         T*   head = source.ptr, 
    205              tail = head + source.length; 
     201        size_t tail = source.length; 
    206202 
    207         while (tail > head && *(tail-1) is match) 
    208                --tail; 
     203        while (tail > 0 && source[tail-1] is match) 
     204                --tail; 
    209205 
    210         return head [0 .. tail - head]; 
     206        return source [0 .. tail]; 
    211207} 
    212208 
    213209/****************************************************************************** 
     
    304300 
    305301******************************************************************************/ 
    306302 
    307 uint locate(T, U=uint) (T[] source, T match, U start=0) 
     303size_t locate(T, U=size_t) (T[] source, T match, U start=0) 
    308304{return locate!(T) (source, match, start);} 
    309305 
    310 uint locate(T) (T[] source, T match, uint start=0) 
     306size_t locate(T) (T[] source, T match, size_t start=0) 
    311307{ 
    312308        if (start > source.length) 
    313309            start = source.length; 
     
    324320 
    325321******************************************************************************/ 
    326322 
    327 uint locatePrior(T, U=uint) (T[] source, T match, U start=uint.max) 
     323size_t locatePrior(T, U=size_t) (T[] source, T match, U start=U.max) 
    328324{return locatePrior!(T)(source, match, start);} 
    329325 
    330 uint locatePrior(T) (T[] source, T match, uint start=uint.max) 
     326size_t locatePrior(T) (T[] source, T match, size_t start=size_t.max) 
    331327{ 
    332328        if (start > source.length) 
    333329            start = source.length; 
     
    347343 
    348344******************************************************************************/ 
    349345 
    350 uint locatePattern(T, U=uint) (T[] source, T[] match, U start=0) 
     346size_t locatePattern(T, U=size_t) (T[] source, T[] match, U start=0) 
    351347{return locatePattern!(T) (source, match, start);} 
    352348 
    353 uint locatePattern(T) (T[] source, T[] match, uint start=0) 
     349size_t locatePattern(T) (T[] source, T[] match, size_t start=0) 
    354350{ 
    355         uint    idx; 
     351        size_t    idx; 
    356352        T*      p = source.ptr + start; 
    357         uint    extent = source.length - start - match.length + 1; 
     353        size_t    extent = source.length - start - match.length + 1; 
    358354 
    359355        if (match.length && extent <= source.length) 
    360356            while (extent) 
     
    362358                        break; 
    363359                   else 
    364360                      if (matching (p+=idx, match.ptr, match.length)) 
    365                           return p - source.ptr
     361                          return cast(size_t)(p - source.ptr)
    366362                      else 
    367363                         { 
    368364                         extent -= (idx+1); 
     
    381377 
    382378******************************************************************************/ 
    383379 
    384 uint locatePatternPrior(T, U=uint) (T[] source, T[] match, U start=uint.max) 
     380size_t locatePatternPrior(T, U=size_t) (T[] source, T[] match, U start=U.max) 
    385381{return locatePatternPrior!(T)(source, match, start);} 
    386382 
    387 uint locatePatternPrior(T) (T[] source, T[] match, uint start=uint.max) 
     383size_t locatePatternPrior(T) (T[] source, T[] match, size_t start=size_t.max) 
    388384{ 
    389385        auto len = source.length; 
    390386         
     
    507503 
    508504T[][] splitLines(T) (T[] src) 
    509505{ 
    510         int count
     506        int count = 0
    511507         
    512508        foreach (line; lines (src)) 
    513509                 ++count; 
     
    535531 
    536532T[] join(T) (T[][] src, T[] postfix=null, T[] dst=null) 
    537533{ 
    538         uint len = src.length * postfix.length; 
     534        size_t len = src.length * postfix.length; 
    539535 
    540536        foreach (segment; src) 
    541537                 len += segment.length; 
     
    570566 
    571567******************************************************************************/ 
    572568 
    573 T[] repeat(T, U=uint) (T[] src, U count, T[] dst=null) 
     569T[] repeat(T, U=size_t) (T[] src, U count, T[] dst=null) 
    574570{return repeat!(T)(src, count, dst);} 
    575571 
    576 T[] repeat(T) (T[] src, uint count, T[] dst=null) 
     572T[] repeat(T) (T[] src, size_t count, T[] dst=null) 
    577573{ 
    578         uint len = src.length * count; 
     574        size_t len = src.length * count; 
    579575        if (len is 0) 
    580576            return null; 
    581577 
     
    608604         
    609605******************************************************************************/ 
    610606 
    611 bool matching(T, U=uint) (T* s1, T* s2, U length) 
     607bool matching(T, U=size_t) (T* s1, T* s2, U length) 
    612608{return matching!(T) (s1, s2, length);} 
    613609 
    614 bool matching(T) (T* s1, T* s2, uint length) 
     610bool matching(T) (T* s1, T* s2, size_t length) 
    615611{ 
    616612        return mismatch(s1, s2, length) is length; 
    617613} 
     
    624620 
    625621******************************************************************************/ 
    626622 
    627 uint indexOf(T, U=uint) (T* str, T match, U length) 
     623size_t indexOf(T, U=size_t) (T* str, T match, U length) 
    628624{return indexOf!(T) (str, match, length);} 
    629625 
    630 uint indexOf(T) (T* str, T match, uint length) 
     626size_t indexOf(T) (T* str, T match, size_t length) 
    631627{ 
    632628        version (D_InlineAsm_X86) 
    633629        {        
     
    696692                        auto len = length; 
    697693                        for (auto p=str-1; len--;) 
    698694                             if (*++p is match) 
    699                                  return p - str
     695                                 return cast(size_t)(p - str)
    700696                        return length; 
    701697                } 
    702698        } 
     
    705701                auto len = length; 
    706702                for (auto p=str-1; len--;) 
    707703                     if (*++p is match) 
    708                          return p - str
     704                         return cast(size_t)(p - str)
    709705                return length; 
    710706        } 
    711707} 
     
    723719 
    724720******************************************************************************/ 
    725721 
    726 uint mismatch(T, U=uint) (T* s1, T* s2, U length) 
     722size_t mismatch(T, U=size_t) (T* s1, T* s2, U length) 
    727723{return mismatch!(T)(s1, s2, length);} 
    728724 
    729 uint mismatch(T) (T* s1, T* s2, uint length) 
     725size_t mismatch(T) (T* s1, T* s2, size_t length) 
    730726{ 
    731727        version (D_InlineAsm_X86) 
    732728        { 
     
    794790                        auto len = length; 
    795791                        for (auto p=s1-1; len--;) 
    796792                             if (*++p != *s2++) 
    797                                  return p - s1
     793                                 return cast(size_t)(p - s1)
    798794                        return length; 
    799795                } 
    800796        } 
     
    803799                auto len = length; 
    804800                for (auto p=s1-1; len--;) 
    805801                     if (*++p != *s2++) 
    806                          return p - s1
     802                         return cast(size_t)(p - s1)
    807803                return length; 
    808804        } 
    809805} 
     
    923919 
    924920T[] layout(T) (T[] output, T[][] layout ...) 
    925921{ 
    926         static T[] badarg   = "{index out of range}"; 
    927         static T[] toosmall = "{output buffer too small}"; 
     922        const static T[] badarg   = "{index out of range}"; 
     923        const static T[] toosmall = "{output buffer too small}"; 
    928924         
    929         int     pos, 
     925        size_t  pos, 
    930926                args; 
    931927        bool    state; 
    932928 
     
    943939                         { 
    944940                         T[] x = layout[index+1]; 
    945941 
    946                          int limit = pos + x.length; 
     942                         size_t limit = pos + x.length; 
    947943                         if (limit < output.length) 
    948944                            { 
    949945                            output [pos .. limit] = x; 
     
    985981 
    986982T[] unescape(T) (T[] src, T[] dst = null) 
    987983{ 
    988         int delta; 
     984        size_t delta; 
    989985        auto s = src.ptr; 
    990986        auto len = src.length; 
    991987 
     
    10551051 
    10561052           // copy tail too 
    10571053           d [0 .. len] = s [0 .. len]; 
    1058            return dst [0 .. (d + len) - dst.ptr]; 
     1054           return dst [0 .. cast(size_t)((d + len) - dst.ptr)]; 
    10591055           } 
    10601056        return src; 
    10611057} 
     
    10691065 
    10701066T[] unentity (T) (T[] src, T[] dst = null) 
    10711067{ 
    1072         int delta; 
     1068        size_t delta; 
    10731069        auto s = src.ptr; 
    10741070        auto len = src.length; 
    10751071 
     
    11271123 
    11281124           // copy tail too 
    11291125           d [0 .. len] = s [0 .. len]; 
    1130            return dst [0 .. (d + len) - dst.ptr]; 
     1126           return dst [0 .. cast(size_t)((d + len) - dst.ptr)]; 
    11311127           } 
    11321128        return src; 
    11331129} 
     
    12261222/// ditto 
    12271223uint jhash (void[] x, uint c = 0) 
    12281224{ 
    1229         return jhash (cast(ubyte*) x.ptr, x.length, c); 
     1225        static if (size_t.sizeof > 4) 
     1226                assert(x.length <= 0xFFFF_FFFF_UL, "jhash only works with 32 Bit"); 
     1227        return jhash (cast(ubyte*) x.ptr, cast(uint)x.length, c); 
    12301228} 
    12311229 
    12321230 
     
    12441242 
    12451243        int opApply (int delegate (inout T[] line) dg) 
    12461244        { 
    1247                 uint    ret, 
    1248                         pos, 
     1245                int     ret; 
     1246                size_t  pos, 
    12491247                        mark; 
    12501248                T[]     line; 
    12511249 
     
    12941292 
    12951293        int opApply (int delegate (inout T[] token) dg) 
    12961294        { 
    1297                 uint    ret, 
    1298                         pos, 
     1295                int     ret; 
     1296                size_t  pos, 
    12991297                        mark; 
    13001298                T[]     token; 
    13011299 
     
    13501348 
    13511349        int opApply (int delegate (inout T[] token) dg) 
    13521350        { 
    1353                 uint    ret, 
    1354                         pos, 
     1351                int     ret; 
     1352                size_t  pos, 
    13551353                        mark; 
    13561354                T[]     token; 
    13571355 
     
    14101408         
    14111409        int opApply (int delegate (inout T[] token) dg) 
    14121410        { 
    1413                 int ret, 
    1414                     mark; 
     1411                int ret; 
     1412                size_t mark; 
    14151413                T[] token; 
    14161414 
    14171415                if (set.length) 
    1418                     for (uint i=0; i < src.length; ++i) 
     1416                    for (size_t i=0; i < src.length; ++i) 
    14191417                        { 
    14201418                        T c = src[i]; 
    14211419                        if (c is '"' || c is '\'')