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 105 105 106 106 T[] trim(T) (T[] source) 107 107 { 108 T* head = source.ptr,109 tail = head +source.length;108 size_t head = 0; 109 size_t tail = source.length; 110 110 111 while (head < tail && isSpace( *head))112 ++head;111 while (head < tail && isSpace(source[head])) 112 ++head; 113 113 114 while (tail > head && isSpace( *(tail-1)))115 --tail;114 while (tail > head && isSpace(source[tail-1])) 115 --tail; 116 116 117 return head [0 .. tail - head];117 return source [head .. tail]; 118 118 } 119 119 120 120 /****************************************************************************** … … 126 126 127 127 T[] triml(T) (T[] source) 128 128 { 129 T* head = source.ptr, 130 tail = head + source.length; 129 size_t head = 0; 131 130 132 while (head < tail && isSpace(*head))131 while (head < source.length && isSpace(source[head])) 133 132 ++head; 134 133 135 return head [0 .. tail - head];134 return source [head .. $]; 136 135 } 137 136 138 137 /****************************************************************************** … … 144 143 145 144 T[] trimr(T) (T[] source) 146 145 { 147 T* head = source.ptr, 148 tail = head + source.length; 146 size_t tail = source.length; 149 147 150 while (tail > head && isSpace(*(tail-1)))148 while (tail > 0 && isSpace(source[tail-1])) 151 149 --tail; 152 150 153 return head [0 .. tail - head];151 return source [0 .. tail]; 154 152 } 155 153 156 154 /****************************************************************************** … … 162 160 163 161 T[] strip(T) (T[] source, T match) 164 162 { 165 T* head = source.ptr,166 tail = head +source.length;163 size_t head = 0; 164 size_t tail = source.length; 167 165 168 while (head < tail && *headis match)169 ++head;166 while (head < tail && source[head] is match) 167 ++head; 170 168 171 while (tail > head && *(tail-1)is match)172 --tail;169 while (tail > head && source[tail-1] is match) 170 --tail; 173 171 174 return head [0 .. tail - head];172 return source [head .. tail]; 175 173 } 176 174 177 175 /****************************************************************************** … … 183 181 184 182 T[] stripl(T) (T[] source, T match) 185 183 { 186 T* head = source.ptr, 187 tail = head + source.length; 184 size_t head = 0; 188 185 189 while (head < tail && *headis match)190 ++head;186 while (head < source.length && source[head] is match) 187 ++head; 191 188 192 return head [0 .. tail - head];189 return source [head .. $]; 193 190 } 194 191 195 192 /****************************************************************************** … … 201 198 202 199 T[] stripr(T) (T[] source, T match) 203 200 { 204 T* head = source.ptr, 205 tail = head + source.length; 201 size_t tail = source.length; 206 202 207 while (tail > head && *(tail-1)is match)208 --tail;203 while (tail > 0 && source[tail-1] is match) 204 --tail; 209 205 210 return head [0 .. tail - head];206 return source [0 .. tail]; 211 207 } 212 208 213 209 /****************************************************************************** … … 304 300 305 301 ******************************************************************************/ 306 302 307 uint locate(T, U=uint) (T[] source, T match, U start=0)303 size_t locate(T, U=size_t) (T[] source, T match, U start=0) 308 304 {return locate!(T) (source, match, start);} 309 305 310 uint locate(T) (T[] source, T match, uint start=0)306 size_t locate(T) (T[] source, T match, size_t start=0) 311 307 { 312 308 if (start > source.length) 313 309 start = source.length; … … 324 320 325 321 ******************************************************************************/ 326 322 327 uint locatePrior(T, U=uint) (T[] source, T match, U start=uint.max)323 size_t locatePrior(T, U=size_t) (T[] source, T match, U start=U.max) 328 324 {return locatePrior!(T)(source, match, start);} 329 325 330 uint locatePrior(T) (T[] source, T match, uint start=uint.max)326 size_t locatePrior(T) (T[] source, T match, size_t start=size_t.max) 331 327 { 332 328 if (start > source.length) 333 329 start = source.length; … … 347 343 348 344 ******************************************************************************/ 349 345 350 uint locatePattern(T, U=uint) (T[] source, T[] match, U start=0)346 size_t locatePattern(T, U=size_t) (T[] source, T[] match, U start=0) 351 347 {return locatePattern!(T) (source, match, start);} 352 348 353 uint locatePattern(T) (T[] source, T[] match, uint start=0)349 size_t locatePattern(T) (T[] source, T[] match, size_t start=0) 354 350 { 355 uint idx;351 size_t idx; 356 352 T* p = source.ptr + start; 357 uint extent = source.length - start - match.length + 1;353 size_t extent = source.length - start - match.length + 1; 358 354 359 355 if (match.length && extent <= source.length) 360 356 while (extent) … … 362 358 break; 363 359 else 364 360 if (matching (p+=idx, match.ptr, match.length)) 365 return p - source.ptr;361 return cast(size_t)(p - source.ptr); 366 362 else 367 363 { 368 364 extent -= (idx+1); … … 381 377 382 378 ******************************************************************************/ 383 379 384 uint locatePatternPrior(T, U=uint) (T[] source, T[] match, U start=uint.max)380 size_t locatePatternPrior(T, U=size_t) (T[] source, T[] match, U start=U.max) 385 381 {return locatePatternPrior!(T)(source, match, start);} 386 382 387 uint locatePatternPrior(T) (T[] source, T[] match, uint start=uint.max)383 size_t locatePatternPrior(T) (T[] source, T[] match, size_t start=size_t.max) 388 384 { 389 385 auto len = source.length; 390 386 … … 507 503 508 504 T[][] splitLines(T) (T[] src) 509 505 { 510 int count ;506 int count = 0; 511 507 512 508 foreach (line; lines (src)) 513 509 ++count; … … 535 531 536 532 T[] join(T) (T[][] src, T[] postfix=null, T[] dst=null) 537 533 { 538 uint len = src.length * postfix.length;534 size_t len = src.length * postfix.length; 539 535 540 536 foreach (segment; src) 541 537 len += segment.length; … … 570 566 571 567 ******************************************************************************/ 572 568 573 T[] repeat(T, U= uint) (T[] src, U count, T[] dst=null)569 T[] repeat(T, U=size_t) (T[] src, U count, T[] dst=null) 574 570 {return repeat!(T)(src, count, dst);} 575 571 576 T[] repeat(T) (T[] src, uint count, T[] dst=null)572 T[] repeat(T) (T[] src, size_t count, T[] dst=null) 577 573 { 578 uint len = src.length * count;574 size_t len = src.length * count; 579 575 if (len is 0) 580 576 return null; 581 577 … … 608 604 609 605 ******************************************************************************/ 610 606 611 bool matching(T, U= uint) (T* s1, T* s2, U length)607 bool matching(T, U=size_t) (T* s1, T* s2, U length) 612 608 {return matching!(T) (s1, s2, length);} 613 609 614 bool matching(T) (T* s1, T* s2, uint length)610 bool matching(T) (T* s1, T* s2, size_t length) 615 611 { 616 612 return mismatch(s1, s2, length) is length; 617 613 } … … 624 620 625 621 ******************************************************************************/ 626 622 627 uint indexOf(T, U=uint) (T* str, T match, U length)623 size_t indexOf(T, U=size_t) (T* str, T match, U length) 628 624 {return indexOf!(T) (str, match, length);} 629 625 630 uint indexOf(T) (T* str, T match, uint length)626 size_t indexOf(T) (T* str, T match, size_t length) 631 627 { 632 628 version (D_InlineAsm_X86) 633 629 { … … 696 692 auto len = length; 697 693 for (auto p=str-1; len--;) 698 694 if (*++p is match) 699 return p - str;695 return cast(size_t)(p - str); 700 696 return length; 701 697 } 702 698 } … … 705 701 auto len = length; 706 702 for (auto p=str-1; len--;) 707 703 if (*++p is match) 708 return p - str;704 return cast(size_t)(p - str); 709 705 return length; 710 706 } 711 707 } … … 723 719 724 720 ******************************************************************************/ 725 721 726 uint mismatch(T, U=uint) (T* s1, T* s2, U length)722 size_t mismatch(T, U=size_t) (T* s1, T* s2, U length) 727 723 {return mismatch!(T)(s1, s2, length);} 728 724 729 uint mismatch(T) (T* s1, T* s2, uint length)725 size_t mismatch(T) (T* s1, T* s2, size_t length) 730 726 { 731 727 version (D_InlineAsm_X86) 732 728 { … … 794 790 auto len = length; 795 791 for (auto p=s1-1; len--;) 796 792 if (*++p != *s2++) 797 return p - s1;793 return cast(size_t)(p - s1); 798 794 return length; 799 795 } 800 796 } … … 803 799 auto len = length; 804 800 for (auto p=s1-1; len--;) 805 801 if (*++p != *s2++) 806 return p - s1;802 return cast(size_t)(p - s1); 807 803 return length; 808 804 } 809 805 } … … 923 919 924 920 T[] layout(T) (T[] output, T[][] layout ...) 925 921 { 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}"; 928 924 929 intpos,925 size_t pos, 930 926 args; 931 927 bool state; 932 928 … … 943 939 { 944 940 T[] x = layout[index+1]; 945 941 946 int limit = pos + x.length;942 size_t limit = pos + x.length; 947 943 if (limit < output.length) 948 944 { 949 945 output [pos .. limit] = x; … … 985 981 986 982 T[] unescape(T) (T[] src, T[] dst = null) 987 983 { 988 int delta;984 size_t delta; 989 985 auto s = src.ptr; 990 986 auto len = src.length; 991 987 … … 1055 1051 1056 1052 // copy tail too 1057 1053 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)]; 1059 1055 } 1060 1056 return src; 1061 1057 } … … 1069 1065 1070 1066 T[] unentity (T) (T[] src, T[] dst = null) 1071 1067 { 1072 int delta;1068 size_t delta; 1073 1069 auto s = src.ptr; 1074 1070 auto len = src.length; 1075 1071 … … 1127 1123 1128 1124 // copy tail too 1129 1125 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)]; 1131 1127 } 1132 1128 return src; 1133 1129 } … … 1226 1222 /// ditto 1227 1223 uint jhash (void[] x, uint c = 0) 1228 1224 { 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); 1230 1228 } 1231 1229 1232 1230 … … 1244 1242 1245 1243 int opApply (int delegate (inout T[] line) dg) 1246 1244 { 1247 uint ret,1248 pos,1245 int ret; 1246 size_t pos, 1249 1247 mark; 1250 1248 T[] line; 1251 1249 … … 1294 1292 1295 1293 int opApply (int delegate (inout T[] token) dg) 1296 1294 { 1297 uint ret,1298 pos,1295 int ret; 1296 size_t pos, 1299 1297 mark; 1300 1298 T[] token; 1301 1299 … … 1350 1348 1351 1349 int opApply (int delegate (inout T[] token) dg) 1352 1350 { 1353 uint ret,1354 pos,1351 int ret; 1352 size_t pos, 1355 1353 mark; 1356 1354 T[] token; 1357 1355 … … 1410 1408 1411 1409 int opApply (int delegate (inout T[] token) dg) 1412 1410 { 1413 int ret ,1414 mark;1411 int ret; 1412 size_t mark; 1415 1413 T[] token; 1416 1414 1417 1415 if (set.length) 1418 for ( uint i=0; i < src.length; ++i)1416 for (size_t i=0; i < src.length; ++i) 1419 1417 { 1420 1418 T c = src[i]; 1421 1419 if (c is '"' || c is '\'')










