 |
Changeset 3727
- Timestamp:
- 07/08/08 14:47:55
(5 months ago)
- Author:
- keinfarbton
- Message:
fix compile errors
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3724 |
r3727 |
|
| 14 | 14 | author: Kris |
|---|
| 15 | 15 | |
|---|
| 16 | | FilePath combined a means of efficiently editing and extracting |
|---|
| | 16 | FilePath combined a means of efficiently editing and extracting |
|---|
| 17 | 17 | path components and of accessing the underlying file system. |
|---|
| 18 | 18 | |
|---|
| 19 | | Use module Path.d instead when you need only pedestrian access to |
|---|
| 20 | | the file-system, and are not manipulating the path components. Use |
|---|
| 21 | | FilePath for other scenarios, since it will often be notably more |
|---|
| | 19 | Use module Path.d instead when you need only pedestrian access to |
|---|
| | 20 | the file-system, and are not manipulating the path components. Use |
|---|
| | 21 | FilePath for other scenarios, since it will often be notably more |
|---|
| 22 | 22 | efficient |
|---|
| 23 | 23 | |
|---|
| … | … | |
| 60 | 60 | to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| 61 | 61 | |
|---|
| 62 | | Note also that normalization of path-separators occurs by default. |
|---|
| | 62 | Note also that normalization of path-separators occurs by default. |
|---|
| 63 | 63 | This means that the use of '\' characters will be converted into |
|---|
| 64 | 64 | '/' instead while parsing. To mutate the path into an O/S native |
|---|
| 65 | | version, use the native() method. To obtain a copy instead, use the |
|---|
| | 65 | version, use the native() method. To obtain a copy instead, use the |
|---|
| 66 | 66 | path.dup.native sequence |
|---|
| 67 | 67 | |
|---|
| … | … | |
| 123 | 123 | set (filepath); |
|---|
| 124 | 124 | } |
|---|
| 125 | | |
|---|
| | 125 | |
|---|
| 126 | 126 | /*********************************************************************** |
|---|
| 127 | 127 | |
|---|
| … | … | |
| 194 | 194 | Returns a path representing the parent of this one. This |
|---|
| 195 | 195 | will typically return the current path component, though |
|---|
| 196 | | with a special case where the name component is empty. In |
|---|
| | 196 | with a special case where the name component is empty. In |
|---|
| 197 | 197 | such cases, the path is scanned for a prior segment: |
|---|
| 198 | 198 | --- |
|---|
| … | … | |
| 347 | 347 | |
|---|
| 348 | 348 | Convert path separators to a standard format, using '/' as |
|---|
| 349 | | the path separator. This is compatible with URI and all of |
|---|
| | 349 | the path separator. This is compatible with URI and all of |
|---|
| 350 | 350 | the contemporary O/S which Tango supports. Known exceptions |
|---|
| 351 | 351 | include the Windows command-line processor, which considers |
|---|
| … | … | |
| 366 | 366 | |
|---|
| 367 | 367 | Convert to native O/S path separators where that is required, |
|---|
| 368 | | such as when dealing with the Windows command-line. |
|---|
| 369 | | |
|---|
| 370 | | Note: mutates the current path. Use this pattern to obtain a |
|---|
| | 368 | such as when dealing with the Windows command-line. |
|---|
| | 369 | |
|---|
| | 370 | Note: mutates the current path. Use this pattern to obtain a |
|---|
| 371 | 371 | copy instead: path.dup.native |
|---|
| 372 | 372 | |
|---|
| … | … | |
| 440 | 440 | /*********************************************************************** |
|---|
| 441 | 441 | |
|---|
| 442 | | Reset the content of this path, and reparse. |
|---|
| | 442 | Reset the content of this path, and reparse. |
|---|
| 443 | 443 | |
|---|
| 444 | 444 | ***********************************************************************/ |
|---|
| … | … | |
| 696 | 696 | Throws: IOException upon systen errors |
|---|
| 697 | 697 | |
|---|
| 698 | | Throws: IllegalArgumentException if a segment exists but as |
|---|
| | 698 | Throws: IllegalArgumentException if a segment exists but as |
|---|
| 699 | 699 | a file instead of a folder |
|---|
| 700 | 700 | |
|---|
| … | … | |
| 702 | 702 | |
|---|
| 703 | 703 | final FilePath create () |
|---|
| 704 | | { |
|---|
| | 704 | { |
|---|
| 705 | 705 | createPath (this.toString); |
|---|
| 706 | 706 | return this; |
|---|
| … | … | |
| 776 | 776 | Returns the time of the last modification. Accurate |
|---|
| 777 | 777 | to whatever the OS supports, and in a format dictated |
|---|
| 778 | | by the file-system. For example NTFS keeps UTC time, |
|---|
| 779 | | while FAT timestamps are based on the local time. |
|---|
| | 778 | by the file-system. For example NTFS keeps UTC time, |
|---|
| | 779 | while FAT timestamps are based on the local time. |
|---|
| 780 | 780 | |
|---|
| 781 | 781 | ***********************************************************************/ |
|---|
| … | … | |
| 790 | 790 | Returns the time of the last access. Accurate to |
|---|
| 791 | 791 | whatever the OS supports, and in a format dictated |
|---|
| 792 | | by the file-system. For example NTFS keeps UTC time, |
|---|
| | 792 | by the file-system. For example NTFS keeps UTC time, |
|---|
| 793 | 793 | while FAT timestamps are based on the local time. |
|---|
| 794 | 794 | |
|---|
| … | … | |
| 804 | 804 | Returns the time of file creation. Accurate to |
|---|
| 805 | 805 | whatever the OS supports, and in a format dictated |
|---|
| 806 | | by the file-system. For example NTFS keeps UTC time, |
|---|
| | 806 | by the file-system. For example NTFS keeps UTC time, |
|---|
| 807 | 807 | while FAT timestamps are based on the local time. |
|---|
| 808 | 808 | |
|---|
| … | … | |
| 841 | 841 | } |
|---|
| 842 | 842 | |
|---|
| 843 | | { |
|---|
| 844 | | version(Win32SansUnicode) |
|---|
| 845 | | else |
|---|
| 846 | | return s ~ "\\"w ~ ext; |
|---|
| 847 | | } |
|---|
| 848 | 843 | /*********************************************************************** |
|---|
| 849 | 844 | |
|---|
| … | … | |
| 886 | 881 | Return timestamp information |
|---|
| 887 | 882 | |
|---|
| 888 | | Timstamps are returns in a format dictated by the |
|---|
| 889 | | file-system. For example NTFS keeps UTC time, |
|---|
| | 883 | Timstamps are returns in a format dictated by the |
|---|
| | 884 | file-system. For example NTFS keeps UTC time, |
|---|
| 890 | 885 | while FAT timestamps are based on the local time |
|---|
| 891 | 886 | |
|---|
| … | … | |
| 918 | 913 | |
|---|
| 919 | 914 | final FilePath remove () |
|---|
| 920 | | { |
|---|
| | 915 | { |
|---|
| 921 | 916 | FS.remove (cString); |
|---|
| 922 | 917 | return this; |
|---|
| … | … | |
| 1198 | 1193 | assert (fp.pop == r"C:"); |
|---|
| 1199 | 1194 | assert (fp.pop == r"C:"); |
|---|
| 1200 | | |
|---|
| | 1195 | |
|---|
| 1201 | 1196 | // special case for popping empty names |
|---|
| 1202 | 1197 | fp = r"C:/home/foo/bar/john/"; |
|---|
| … | … | |
| 1400 | 1395 | assert (fp.asExt(null) == r"C:/foo/bar/test"); |
|---|
| 1401 | 1396 | assert (fp.asExt("foo") == r"C:/foo/bar/test.foo"); |
|---|
| 1402 | | +/ |
|---|
| | 1397 | +/ |
|---|
| 1403 | 1398 | } |
|---|
| 1404 | 1399 | } |
|---|
| … | … | |
| 1407 | 1402 | |
|---|
| 1408 | 1403 | debug (FilePath) |
|---|
| 1409 | | { |
|---|
| | 1404 | { |
|---|
| 1410 | 1405 | import tango.io.Console; |
|---|
| 1411 | 1406 | |
|---|
| 1412 | | void main() |
|---|
| | 1407 | void main() |
|---|
| 1413 | 1408 | { |
|---|
| 1414 | 1409 | assert (FilePath("/foo/").create.exists); |
|---|
| r3726 |
r3727 |
|
| 384 | 384 | command ~= ' '; |
|---|
| 385 | 385 | } |
|---|
| 386 | | if (contains!(char)(_args[i], ' ') || _args[i].length == 0) |
|---|
| | 386 | if (contains!(char)( cast(char[])_args[i], ' ') || _args[i].length == 0) |
|---|
| 387 | 387 | { |
|---|
| 388 | 388 | command ~= '"'; |
|---|
| 389 | | command ~= _args[i].substitute(cast(Cutf8)"\\", cast(Cutf8)"\\\\").substitute(cast(Cutf8)`"`, cast(Cutf8)`\"`); |
|---|
| | 389 | command ~= (cast(char[])_args[i]).substitute(cast(char[])"\\", cast(char[])"\\\\").substitute(cast(char[])`"`, cast(char[])`\"`); |
|---|
| 390 | 390 | command ~= '"'; |
|---|
| 391 | 391 | } |
|---|
| 392 | 392 | else |
|---|
| 393 | 393 | { |
|---|
| 394 | | command ~= _args[i].substitute("\\", "\\\\").substitute(`"`, `\"`); |
|---|
| | 394 | command ~= (cast(char[])_args[i]).substitute(cast(char[])"\\", cast(char[])"\\\\").substitute(cast(char[])`"`, cast(char[])`\"`); |
|---|
| 395 | 395 | } |
|---|
| 396 | 396 | } |
|---|
| … | … | |
| 1265 | 1265 | in |
|---|
| 1266 | 1266 | { |
|---|
| 1267 | | assert(!contains!(char)(delims, '"'), |
|---|
| | 1267 | assert(!contains!(char)(cast(char[])delims, '"'), |
|---|
| 1268 | 1268 | "The argument delimiter Cutf8 cannot contain a double quotes ('\"') character"); |
|---|
| 1269 | 1269 | } |
|---|
| … | … | |
| 1330 | 1330 | state = State.InsideQuotes; |
|---|
| 1331 | 1331 | } |
|---|
| 1332 | | else if (!contains!(char)(delims, c)) |
|---|
| | 1332 | else if (!contains!(char)(cast(char[])delims, c)) |
|---|
| 1333 | 1333 | { |
|---|
| 1334 | 1334 | start = i; |
|---|
| … | … | |
| 1357 | 1357 | state = State.InsideQuotes; |
|---|
| 1358 | 1358 | } |
|---|
| 1359 | | else if (contains!(char)(delims, c)) |
|---|
| | 1359 | else if (contains!(char)(cast(char[])delims, c)) |
|---|
| 1360 | 1360 | { |
|---|
| 1361 | 1361 | appendChunksAsArg(); |
|---|
| … | … | |
| 1496 | 1496 | char* str; |
|---|
| 1497 | 1497 | |
|---|
| 1498 | | if (!contains!(char)(filename, FileConst.PathSeparatorChar) && |
|---|
| | 1498 | if (!contains!(char)(cast(char[])filename, FileConst.PathSeparatorChar) && |
|---|
| 1499 | 1499 | (str = getenv("PATH".ptr)) !is null) |
|---|
| 1500 | 1500 | { |
|---|
| 1501 | | Cutf8[] pathList = delimit!(char)(str[0 .. strlen(str)], ":"); |
|---|
| | 1501 | auto pathList = delimit!(char)(cast(char[])str[0 .. strlen(str)], cast(char[])":"); |
|---|
| 1502 | 1502 | |
|---|
| 1503 | 1503 | foreach ( inout path; pathList) |
|---|
| r3724 |
r3727 |
|
| 262 | 262 | /****************************************************************************** |
|---|
| 263 | 263 | |
|---|
| 264 | | Replace all instances of one array with another |
|---|
| 265 | | |
|---|
| 266 | | ******************************************************************************/ |
|---|
| 267 | | |
|---|
| 268 | | const(T)[] substitute(T) (const(T)[] source, const(T)[] match, const(T)[] replacement) |
|---|
| | 264 | Replace all instances of one array with another |
|---|
| | 265 | |
|---|
| | 266 | ******************************************************************************/ |
|---|
| | 267 | |
|---|
| | 268 | T[] substitute(T) (T[] source, T[] match, T[] replacement) |
|---|
| 269 | 269 | { |
|---|
| 270 | 270 | T[] output; |
|---|
| … | … | |
| 282 | 282 | ******************************************************************************/ |
|---|
| 283 | 283 | |
|---|
| 284 | | bool contains(T) (const(T)[] source, T match) |
|---|
| | 284 | bool contains(T) (T[] source, T match) |
|---|
| 285 | 285 | { |
|---|
| 286 | 286 | return indexOf!(T) (source.ptr, match, source.length) != source.length; |
|---|
| … | … | |
| 294 | 294 | ******************************************************************************/ |
|---|
| 295 | 295 | |
|---|
| 296 | | bool containsPattern(T) (const(T)[] source, const(T)[] match) |
|---|
| | 296 | bool containsPattern(T) (T[] source, T[] match) |
|---|
| 297 | 297 | { |
|---|
| 298 | 298 | return locatePattern (source, match) != source.length; |
|---|
| … | … | |
| 308 | 308 | ******************************************************************************/ |
|---|
| 309 | 309 | |
|---|
| 310 | | uint locate(T, U=uint) (const(T)[] source, T match, U start=0) |
|---|
| | 310 | uint locate(T, U=uint) (T[] source, T match, U start=0) |
|---|
| 311 | 311 | {return locate!(T) (source, match, start);} |
|---|
| 312 | 312 | |
|---|
| 313 | | uint locate(T) (const(T)[] source, T match, uint start=0) |
|---|
| | 313 | uint locate(T) (T[] source, T match, uint start=0) |
|---|
| 314 | 314 | { |
|---|
| 315 | 315 | if (start > source.length) |
|---|
| … | … | |
| 328 | 328 | ******************************************************************************/ |
|---|
| 329 | 329 | |
|---|
| 330 | | uint locatePrior(T, U=uint) (const(T)[] source, T match, U start=uint.max) |
|---|
| | 330 | uint locatePrior(T, U=uint) (T[] source, T match, U start=uint.max) |
|---|
| 331 | 331 | {return locatePrior!(T)(source, match, start);} |
|---|
| 332 | 332 | |
|---|
| 333 | | uint locatePrior(T) (const(T)[] source, T match, uint start=uint.max) |
|---|
| | 333 | uint locatePrior(T) (T[] source, T match, uint start=uint.max) |
|---|
| 334 | 334 | { |
|---|
| 335 | 335 | if (start > source.length) |
|---|
| … | … | |
| 351 | 351 | ******************************************************************************/ |
|---|
| 352 | 352 | |
|---|
| 353 | | uint locatePattern(T, U=uint) (const(T)[] source, const(T)[] match, U start=0) |
|---|
| | 353 | uint locatePattern(T, U=uint) (T[] source, T[] match, U start=0) |
|---|
| 354 | 354 | {return locatePattern!(T) (source, match, start);} |
|---|
| 355 | 355 | |
|---|
| 356 | | uint locatePattern(T) (const(T)[] source, const(T)[] match, uint start=0) |
|---|
| | 356 | uint locatePattern(T) (T[] source, T[] match, uint start=0) |
|---|
| 357 | 357 | { |
|---|
| 358 | 358 | uint idx; |
|---|
| 359 | | const(T)* p = source.ptr + start; |
|---|
| | 359 | T* p = source.ptr + start; |
|---|
| 360 | 360 | uint extent = source.length - start - match.length + 1; |
|---|
| 361 | 361 | |
|---|
| … | … | |
| 412 | 412 | /****************************************************************************** |
|---|
| 413 | 413 | |
|---|
| 414 | | Split the provided array on the first pattern instance, and |
|---|
| 415 | | return the resultant head and tail. The pattern is excluded |
|---|
| 416 | | from the two segments. |
|---|
| | 414 | Split the provided array on the first pattern instance, and |
|---|
| | 415 | return the resultant head and tail. The pattern is excluded |
|---|
| | 416 | from the two segments. |
|---|
| 417 | 417 | |
|---|
| 418 | 418 | Where a segment is not found, tail will be null and the return |
|---|
| 419 | 419 | value will be the original array. |
|---|
| 420 | | |
|---|
| | 420 | |
|---|
| 421 | 421 | ******************************************************************************/ |
|---|
| 422 | 422 | |
|---|
| … | … | |
| 434 | 434 | /****************************************************************************** |
|---|
| 435 | 435 | |
|---|
| 436 | | Split the provided array on the last pattern instance, and |
|---|
| 437 | | return the resultant head and tail. The pattern is excluded |
|---|
| 438 | | from the two segments. |
|---|
| | 436 | Split the provided array on the last pattern instance, and |
|---|
| | 437 | return the resultant head and tail. The pattern is excluded |
|---|
| | 438 | from the two segments. |
|---|
| 439 | 439 | |
|---|
| 440 | 440 | Where a segment is not found, head will be null and the return |
|---|
| 441 | 441 | value will be the original array. |
|---|
| 442 | | |
|---|
| | 442 | |
|---|
| 443 | 443 | ******************************************************************************/ |
|---|
| 444 | 444 | |
|---|
| … | … | |
| 462 | 462 | |
|---|
| 463 | 463 | Splitting on a single delimiter is considerably faster than |
|---|
| 464 | | splitting upon a set of alternatives. |
|---|
| 465 | | |
|---|
| 466 | | Note that the src content is not duplicated by this function, |
|---|
| | 464 | splitting upon a set of alternatives. |
|---|
| | 465 | |
|---|
| | 466 | Note that the src content is not duplicated by this function, |
|---|
| 467 | 467 | but is sliced instead. |
|---|
| 468 | 468 | |
|---|
| 469 | 469 | ******************************************************************************/ |
|---|
| 470 | 470 | |
|---|
| 471 | | const(T)[][] delimit(T) (const(T)[] src, const(T)[] set) |
|---|
| 472 | | { |
|---|
| 473 | | const(T)[][] result; |
|---|
| | 471 | T[][] delimit(T) (T[] src, T[] set) |
|---|
| | 472 | { |
|---|
| | 473 | T[][] result; |
|---|
| 474 | 474 | |
|---|
| 475 | 475 | foreach (segment; delimiters!(T) (src, set)) |
|---|
| … | … | |
| 484 | 484 | excluded from each of the segments. |
|---|
| 485 | 485 | |
|---|
| 486 | | Note that the src content is not duplicated by this function, |
|---|
| | 486 | Note that the src content is not duplicated by this function, |
|---|
| 487 | 487 | but is sliced instead. |
|---|
| 488 | 488 | |
|---|
| … | … | |
| 511 | 511 | { |
|---|
| 512 | 512 | int count; |
|---|
| 513 | | |
|---|
| | 513 | |
|---|
| 514 | 514 | foreach (line; lines (src)) |
|---|
| 515 | 515 | ++count; |
|---|
| 516 | | |
|---|
| | 516 | |
|---|
| 517 | 517 | T[][] result = new T[][count]; |
|---|
| 518 | 518 | |
|---|
| … | … | |
| 526 | 526 | /****************************************************************************** |
|---|
| 527 | 527 | |
|---|
| 528 | | Combine a series of text segments together, each appended with |
|---|
| | 528 | Combine a series of text segments together, each appended with |
|---|
| 529 | 529 | a postfix pattern. An optional output buffer can be provided to |
|---|
| 530 | | avoid heap activity - it should be large enough to contain the |
|---|
| | 530 | avoid heap activity - it should be large enough to contain the |
|---|
| 531 | 531 | entire output, otherwise the heap will be used instead. |
|---|
| 532 | 532 | |
|---|
| … | … | |
| 543 | 543 | /****************************************************************************** |
|---|
| 544 | 544 | |
|---|
| 545 | | Combine a series of text segments together, each prepended with |
|---|
| 546 | | a prefix pattern. An optional output buffer can be provided to |
|---|
| 547 | | avoid heap activity - it should be large enough to contain the |
|---|
| | 545 | Combine a series of text segments together, each prepended with |
|---|
| | 546 | a prefix pattern. An optional output buffer can be provided to |
|---|
| | 547 | avoid heap activity - it should be large enough to contain the |
|---|
| 548 | 548 | entire output, otherwise the heap will be used instead. |
|---|
| 549 | 549 | |
|---|
| 550 | 550 | Note that, unlike join(), the output buffer is specified first |
|---|
| 551 | | such that a set of trailing strings can be provided. |
|---|
| | 551 | such that a set of trailing strings can be provided. |
|---|
| 552 | 552 | |
|---|
| 553 | 553 | Returns a valid slice of the output, containing the concatenated |
|---|
| … | … | |
| 569 | 569 | |
|---|
| 570 | 570 | Note that, unlike join(), the output buffer is specified first |
|---|
| 571 | | such that a set of trailing strings can be provided. |
|---|
| | 571 | such that a set of trailing strings can be provided. |
|---|
| 572 | 572 | |
|---|
| 573 | 573 | Returns a valid slice of the output, containing the concatenated |
|---|
| … | … | |
| 583 | 583 | /****************************************************************************** |
|---|
| 584 | 584 | |
|---|
| 585 | | Combine a series of text segments together, each prefixed and/or |
|---|
| 586 | | postfixed with optional strings. An optional output buffer can be |
|---|
| 587 | | provided to avoid heap activity - which should be large enough to |
|---|
| | 585 | Combine a series of text segments together, each prefixed and/or |
|---|
| | 586 | postfixed with optional strings. An optional output buffer can be |
|---|
| | 587 | provided to avoid heap activity - which should be large enough to |
|---|
| 588 | 588 | contain the entire output, otherwise the heap will be used instead. |
|---|
| 589 | 589 | |
|---|
| 590 | 590 | Note that, unlike join(), the output buffer is specified first |
|---|
| 591 | | such that a set of trailing strings can be provided. |
|---|
| | 591 | such that a set of trailing strings can be provided. |
|---|
| 592 | 592 | |
|---|
| 593 | 593 | Returns a valid slice of the output, containing the concatenated |
|---|
| … | … | |
| 598 | 598 | T[] combine(T) (T[] dst, T[] prefix, T[] postfix, T[][] src ...) |
|---|
| 599 | 599 | { |
|---|
| 600 | | uint len = src.length * prefix.length + |
|---|
| | 600 | uint len = src.length * prefix.length + |
|---|
| 601 | 601 | src.length * postfix.length; |
|---|
| 602 | 602 | |
|---|
| … | … | |
| 626 | 626 | /****************************************************************************** |
|---|
| 627 | 627 | |
|---|
| 628 | | Repeat an array for a specific number of times. An optional output |
|---|
| 629 | | buffer can be provided to avoid heap activity - it should be large |
|---|
| 630 | | enough to contain the entire output, otherwise the heap will be used |
|---|
| | 628 | Repeat an array for a specific number of times. An optional output |
|---|
| | 629 | buffer can be provided to avoid heap activity - it should be large |
|---|
| | 630 | enough to contain the entire output, otherwise the heap will be used |
|---|
| 631 | 631 | instead. |
|---|
| 632 | 632 | |
|---|
| … | … | |
| 690 | 690 | ******************************************************************************/ |
|---|
| 691 | 691 | |
|---|
| 692 | | uint indexOf(T, U=uint) (const(T)* str, T match, U length) |
|---|
| | 692 | uint indexOf(T, U=uint) (T* str, T match, U length) |
|---|
| 693 | 693 | {return indexOf!(T) (str, match, length);} |
|---|
| 694 | 694 | |
|---|
| 695 | | uint indexOf(T) (const(T)* str, T match, uint length) |
|---|
| | 695 | uint indexOf(T) (T* str, T match, uint length) |
|---|
| 696 | 696 | { |
|---|
| 697 | 697 | version (D_InlineAsm_X86) |
|---|
| … | … | |
| 939 | 939 | ******************************************************************************/ |
|---|
| 940 | 940 | |
|---|
| 941 | | PatternFruct!(T) patterns(T) (const(T)[] src, const(T)[] pattern, const(T)[] sub=null) |
|---|
| | 941 | PatternFruct!(T) patterns(T) (T[] src, T[] pattern, T[] sub=null) |
|---|
| 942 | 942 | { |
|---|
| 943 | 943 | PatternFruct!(T) elements; |
|---|
| … | … | |
| 963 | 963 | ******************************************************************************/ |
|---|
| 964 | 964 | |
|---|
| 965 | | QuoteFruct!(T) quotes(T) (const(T)[] src, const(T)[] set) |
|---|
| | 965 | QuoteFruct!(T) quotes(T) (T[] src, T[] set) |
|---|
| 966 | 966 | { |
|---|
| 967 | 967 | QuoteFruct!(T) quotes; |
|---|
| … | … | |
| 987 | 987 | *******************************************************************************/ |
|---|
| 988 | 988 | |
|---|
| 989 | | const(T)[] layout(T) ( T[] output, const(T)[][] layout ...) |
|---|
| | 989 | T[] layout(T) ( T[] output, T[][] layout ...) |
|---|
| 990 | 990 | { |
|---|
| 991 | 991 | static Cutf8 badarg = "{index out of range}"; |
|---|
| … | … | |
| 1007 | 1007 | if (index < args) |
|---|
| 1008 | 1008 | { |
|---|
| 1009 | | const(T)[] x = layout[index+1]; |
|---|
| | 1009 | T[] x = layout[index+1]; |
|---|
| 1010 | 1010 | |
|---|
| 1011 | 1011 | int limit = pos + x.length; |
|---|
| … | … | |
| 1046 | 1046 | Convert 'escaped' chars to normal ones: \t => ^t for example. |
|---|
| 1047 | 1047 | Supports \" \' \\ \a \b \f \n \r \t \v |
|---|
| 1048 | | |
|---|
| | 1048 | |
|---|
| 1049 | 1049 | ******************************************************************************/ |
|---|
| 1050 | 1050 | |
|---|
| … | … | |
| 1114 | 1114 | *d++ = '\\'; |
|---|
| 1115 | 1115 | } |
|---|
| 1116 | | *d++ = c; |
|---|
| 1117 | | len -= 2; |
|---|
| | 1116 | *d++ = c; |
|---|
| | 1117 | len -= 2; |
|---|
| 1118 | 1118 | s += 2; |
|---|
| 1119 | 1119 | } while ((delta = indexOf (s, '\\', len)) < len); |
|---|
| … | … | |
| 1130 | 1130 | |
|---|
| 1131 | 1131 | Convert entity chars to normal ones: & => ; for example. |
|---|
| 1132 | | |
|---|
| | 1132 | |
|---|
| 1133 | 1133 | ******************************************************************************/ |
|---|
| 1134 | 1134 | |
|---|
| … | … | |
| 1166 | 1166 | *d++ = '\'', token = 6; |
|---|
| 1167 | 1167 | break; |
|---|
| 1168 | | |
|---|
| | 1168 | |
|---|
| 1169 | 1169 | case 'g': |
|---|
| 1170 | 1170 | if (len > 3 && s[1..4] == "gt;") |
|---|
| 1171 | 1171 | *d++ = '>', token = 4; |
|---|
| 1172 | 1172 | break; |
|---|
| 1173 | | |
|---|
| | 1173 | |
|---|
| 1174 | 1174 | case 'l': |
|---|
| 1175 | 1175 | if (len > 3 && s[1..4] == "lt;") |
|---|
| 1176 | 1176 | *d++ = '<', token = 4; |
|---|
| 1177 | 1177 | break; |
|---|
| 1178 | | |
|---|
| | 1178 | |
|---|
| 1179 | 1179 | case 'q': |
|---|
| 1180 | 1180 | if (len > 5 && s[1..6] == "quot;") |
|---|
| … | … | |
| 1297 | 1297 | |
|---|
| 1298 | 1298 | /****************************************************************************** |
|---|
| 1299 | | |
|---|
| 1300 | | Helper fruct for iterator lines(). A fruct is a low |
|---|
| 1301 | | impact mechanism for capturing context relating to an |
|---|
| | 1299 | |
|---|
| | 1300 | Helper fruct for iterator lines(). A fruct is a low |
|---|
| | 1301 | impact mechanism for capturing context relating to an |
|---|
| 1302 | 1302 | opApply (conjunction of the names struct and foreach) |
|---|
| 1303 | | |
|---|
| | 1303 | |
|---|
| 1304 | 1304 | ******************************************************************************/ |
|---|
| 1305 | 1305 | |
|---|
| 1306 | 1306 | private struct LineFruct(T) |
|---|
| 1307 | 1307 | { |
|---|
| 1308 | | private const(T)[] src; |
|---|
| 1309 | | |
|---|
| 1310 | | int opApply (int delegate ( ref const(T)[] line) dg) |
|---|
| | 1308 | private T[] src; |
|---|
| | 1309 | |
|---|
| | 1310 | int opApply (int delegate ( ref T[] line) dg) |
|---|
| 1311 | 1311 | { |
|---|
| 1312 | 1312 | uint ret, |
|---|
| 1313 | 1313 | pos, |
|---|
| 1314 | 1314 | mark; |
|---|
| 1315 | | const(T)[] line; |
|---|
| | 1315 | T[] line; |
|---|
| 1316 | 1316 | |
|---|
| 1317 | 1317 | const T nl = '\n'; |
|---|
| … | … | |
| 1347 | 1347 | /****************************************************************************** |
|---|
| 1348 | 1348 | |
|---|
| 1349 | | Helper fruct for iterator delims(). A fruct is a low |
|---|
| 1350 | | impact mechanism for capturing context relating to an |
|---|
| | 1349 | Helper fruct for iterator delims(). A fruct is a low |
|---|
| | 1350 | impact mechanism for capturing context relating to an |
|---|
| 1351 | 1351 | opApply (conjunction of the names struct and foreach) |
|---|
| 1352 | 1352 | |
|---|
| … | … | |
| 1355 | 1355 | private struct DelimFruct(T) |
|---|
| 1356 | 1356 | { |
|---|
| 1357 | | private const(T)[] src; |
|---|
| 1358 | | private const(T)[] set; |
|---|
| 1359 | | |
|---|
| 1360 | | int opApply (int delegate (ref const(T)[] token) dg) |
|---|
| | 1357 | private T[] src; |
|---|
| | 1358 | private T[] set; |
|---|
| | 1359 | |
|---|
| | 1360 | int opApply (int delegate (ref T[] token) dg) |
|---|
| 1361 | 1361 | { |
|---|
| 1362 | 1362 | uint ret, |
|---|
| 1363 | 1363 | pos, |
|---|
| 1364 | 1364 | mark; |
|---|
| 1365 | | const(T)[] token; |
|---|
| | 1365 | T[] token; |
|---|
| 1366 | 1366 | |
|---|
| 1367 | 1367 | // optimize for single delimiter case |
|---|
| … | … | |
| 1402 | 1402 | /****************************************************************************** |
|---|
| 1403 | 1403 | |
|---|
| 1404 | | Helper fruct for iterator patterns(). A fruct is a low |
|---|
| 1405 | | impact mechanism for capturing context relating to an |
|---|
| | 1404 | Helper fruct for iterator patterns(). A fruct is a low |
|---|
| | 1405 | impact mechanism for capturing context relating to an |
|---|
| 1406 | 1406 | opApply (conjunction of the names struct and foreach) |
|---|
| 1407 | 1407 | |
|---|
| … | … | |
| 1410 | 1410 | private struct PatternFruct(T) |
|---|
| 1411 | 1411 | { |
|---|
| 1412 | | private const(T)[] src, |
|---|
| | 1412 | private T[] src, |
|---|
| 1413 | 1413 | sub, |
|---|
| 1414 | 1414 | pattern; |
|---|
| 1415 | 1415 | |
|---|
| 1416 | | int opApply (int delegate (ref const(T)[] token) dg) |
|---|
| | 1416 | int opApply (int delegate (ref T[] token) dg) |
|---|
| 1417 | 1417 | { |
|---|
| 1418 | 1418 | uint ret, |
|---|
| 1419 | 1419 | pos, |
|---|
| 1420 | 1420 | mark; |
|---|
| 1421 | | const(T)[] token; |
|---|
| | 1421 | T[] token; |
|---|
| 1422 | 1422 | |
|---|
| 1423 | 1423 | // optimize for single-element pattern |
|---|
| … | … | |
| 1463 | 1463 | /****************************************************************************** |
|---|
| 1464 | 1464 | |
|---|
| 1465 | | Helper fruct for iterator quotes(). A fruct is a low |
|---|
| 1466 | | impact mechanism for capturing context relating to an |
|---|
| | 1465 | Helper fruct for iterator quotes(). A fruct is a low |
|---|
| | 1466 | impact mechanism for capturing context relating to an |
|---|
| 1467 | 1467 | opApply (conjunction of the names struct and foreach) |
|---|
| 1468 | 1468 | |
|---|
| … | … | |
| 1471 | 1471 | private struct QuoteFruct(T) |
|---|
| 1472 | 1472 | { |
|---|
| 1473 | | private const(T)[] src; |
|---|
| 1474 | | private const(T)[] set; |
|---|
| 1475 | | |
|---|
| 1476 | | int opApply (int delegate (ref const(T)[] token) dg) |
|---|
| | 1473 | private T[] src; |
|---|
| | 1474 | private T[] set; |
|---|
| | 1475 | |
|---|
| | 1476 | int opApply (int delegate (ref T[] token) dg) |
|---|
| 1477 | 1477 | { |
|---|
| 1478 | 1478 | int ret, |
|---|
| 1479 | 1479 | mark; |
|---|
| 1480 | | const(T)[] token; |
|---|
| | 1480 | T[] token; |
|---|
| 1481 | 1481 | |
|---|
| 1482 | 1482 | if (set.length) |
|---|
| r3724 |
r3727 |
|
| 4 | 4 | |
|---|
| 5 | 5 | license: BSD style: $(LICENSE) |
|---|
| 6 | | |
|---|
| | 6 | |
|---|
| 7 | 7 | version: Initial release: Nov 2005 |
|---|
| 8 | | |
|---|
| | 8 | |
|---|
| 9 | 9 | author: Kris |
|---|
| 10 | 10 | |
|---|
| 11 | | A set of functions for converting between Cutf8 and integer |
|---|
| 12 | | values. |
|---|
| | 11 | A set of functions for converting between Cutf8 and integer |
|---|
| | 12 | values. |
|---|
| 13 | 13 | |
|---|
| 14 | 14 | Applying the D "import alias" mechanism to this module is highly |
|---|
| … | … | |
| 19 | 19 | auto i = Integer.parse ("32767"); |
|---|
| 20 | 20 | --- |
|---|
| 21 | | |
|---|
| | 21 | |
|---|
| 22 | 22 | *******************************************************************************/ |
|---|
| 23 | 23 | |
|---|
| … | … | |
| 28 | 28 | /****************************************************************************** |
|---|
| 29 | 29 | |
|---|
| 30 | | Parse an integer value from the provided 'digits' Cutf8. |
|---|
| 31 | | |
|---|
| 32 | | The Cutf8 is inspected for a sign and an optional radix |
|---|
| 33 | | prefix. A radix may be provided as an argument instead, |
|---|
| | 30 | Parse an integer value from the provided 'digits' Cutf8. |
|---|
| | 31 | |
|---|
| | 32 | The Cutf8 is inspected for a sign and an optional radix |
|---|
| | 33 | prefix. A radix may be provided as an argument instead, |
|---|
| 34 | 34 | whereupon it must match the prefix (where present). When |
|---|
| 35 | 35 | radix is set to zero, conversion will default to decimal. |
|---|
| … | … | |
| 37 | 37 | Throws an exception where the input text is not parsable |
|---|
| 38 | 38 | in its entirety. |
|---|
| 39 | | |
|---|
| | 39 | |
|---|
| 40 | 40 | ******************************************************************************/ |
|---|
| 41 | 41 | |
|---|
| … | … | |
| 53 | 53 | /****************************************************************************** |
|---|
| 54 | 54 | |
|---|
| 55 | | Parse an integer value from the provided 'digits' Cutf8. |
|---|
| 56 | | |
|---|
| 57 | | The Cutf8 is inspected for a sign and an optional radix |
|---|
| 58 | | prefix. A radix may be provided as an argument instead, |
|---|
| | 55 | Parse an integer value from the provided 'digits' Cutf8. |
|---|
| | 56 | |
|---|
| | 57 | The Cutf8 is inspected for a sign and an optional radix |
|---|
| | 58 | prefix. A radix may be provided as an argument instead, |
|---|
| 59 | 59 | whereupon it must match the prefix (where present). When |
|---|
| 60 | 60 | radix is set to zero, conversion will default to decimal. |
|---|
| … | … | |
| 62 | 62 | Throws an exception where the input text is not parsable |
|---|
| 63 | 63 | in its entirety. |
|---|
| 64 | | |
|---|
| | 64 | |
|---|
| 65 | 65 | ******************************************************************************/ |
|---|
| 66 | 66 | |
|---|
| … | … | |
| 92 | 92 | return format (tmp, i, fmt).dup; |
|---|
| 93 | 93 | } |
|---|
| 94 | | |
|---|
| | 94 | |
|---|
| 95 | 95 | /****************************************************************************** |
|---|
| 96 | 96 | |
|---|
| … | … | |
| 107 | 107 | return format (tmp, i, fmt).dup; |
|---|
| 108 | 108 | } |
|---|
| 109 | | |
|---|
| | 109 | |
|---|
| 110 | 110 | /****************************************************************************** |
|---|
| 111 | 111 | |
|---|
| … | … | |
| 122 | 122 | return format (tmp, i, fmt).dup; |
|---|
| 123 | 123 | } |
|---|
| 124 | | |
|---|
| | 124 | |
|---|
| 125 | 125 | /******************************************************************************* |
|---|
| 126 | 126 | |
|---|
| … | … | |
| 161 | 161 | *******************************************************************************/ |
|---|
| 162 | 162 | |
|---|
| 163 | | T[] format(T, U=long) (T[] dst, U i, T[] fmt = null) |
|---|
| | 163 | const(T)[] format(T, U=long) (T[] dst, U i, T[] fmt = null) |
|---|
| 164 | 164 | {return format!(T)(dst, cast(long) i, fmt);} |
|---|
| 165 | 165 | |
|---|
| 166 | | T[] format(T) (T[] dst, long i, T[] fmt = null) |
|---|
| | 166 | const(T)[] format(T) (T[] dst, long i, T[] fmt = null) |
|---|
| 167 | 167 | { |
|---|
| 168 | 168 | char pre, |
|---|
| … | … | |
| 172 | 172 | decode (fmt, type, pre, width); |
|---|
| 173 | 173 | return formatter (dst, i, type, pre, width); |
|---|
| 174 | | } |
|---|
| | 174 | } |
|---|
| 175 | 175 | |
|---|
| 176 | 176 | private void decode(T) (T[] fmt, ref char type, out char pre, out int width) |
|---|
| … | … | |
| 191 | 191 | } |
|---|
| 192 | 192 | } |
|---|
| 193 | | } |
|---|
| | 193 | } |
|---|
| 194 | 194 | |
|---|
| 195 | 195 | |
|---|
| … | … | |
| 201 | 201 | { |
|---|
| 202 | 202 | uint radix; |
|---|
| 203 | | T[] prefix; |
|---|
| 204 | | T[] numbers; |
|---|
| 205 | | } |
|---|
| 206 | | |
|---|
| 207 | | T[] formatter(T) (T[] dst, long i, char type, char pre, int width) |
|---|
| 208 | | { |
|---|
| 209 | | const T[] lower = "0123456789abcdef"; |
|---|
| 210 | | const T[] upper = "0123456789ABCDEF"; |
|---|
| 211 | | |
|---|
| | 203 | const(T)[] prefix; |
|---|
| | 204 | const(T)[] numbers; |
|---|
| | 205 | } |
|---|
| | 206 | |
|---|
| | 207 | const(T)[] formatter(T) (T[] dst, long i, char type, char pre, int width) |
|---|
| | 208 | { |
|---|
| | 209 | static const lower = cast(const(T)[])"0123456789abcdef"; |
|---|
| | 210 | static const upper = cast(const(T)[])"0123456789ABCDEF"; |
|---|
| | 211 | |
|---|
| 212 | 212 | alias _FormatterInfo!(T) Info; |
|---|
| 213 | 213 | |
|---|
| 214 | | const Info[] formats = |
|---|
| | 214 | static const Info[] formats = |
|---|
| 215 | 215 | [ |
|---|
| 216 | | {10, null, lower}, |
|---|
| 217 | | {10, "-", lower}, |
|---|
| 218 | | {10, " ", lower}, |
|---|
| 219 | | {10, "+", lower}, |
|---|
| 220 | | { 2, "0b", lower}, |
|---|
| 221 | | { 8, "0o", lower}, |
|---|
| 222 | | {16, "0x", lower}, |
|---|
| | 216 | {10, null, lower}, |
|---|
| | 217 | {10, "-", lower}, |
|---|
| | 218 | {10, " ", lower}, |
|---|
| | 219 | {10, "+", lower}, |
|---|
| | 220 | { 2, "0b", lower}, |
|---|
| | 221 | { 8, "0o", lower}, |
|---|
| | 222 | {16, "0x", lower}, |
|---|
| 223 | 223 | {16, "0X", upper}, |
|---|
| 224 | 224 | ]; |
|---|
| … | … | |
| 293 | 293 | } while ((v /= radix) && --len); |
|---|
| 294 | 294 | } |
|---|
| 295 | | |
|---|
| | 295 | |
|---|
| 296 | 296 | auto prefix = (pre is '#') ? info.prefix : null; |
|---|
| 297 | 297 | if (len > prefix.length) |
|---|
| … | … | |
| 299 | 299 | len -= prefix.length + 1; |
|---|
| 300 | 300 | |
|---|
| 301 | | // prefix number with zeros? |
|---|
| | 301 | // prefix number with zeros? |
|---|
| 302 | 302 | if (width) |
|---|
| 303 | 303 | { |
|---|
| … | … | |
| 313 | 313 | |
|---|
| 314 | 314 | // return slice of provided output buffer |
|---|
| 315 | | return dst [len .. $]; |
|---|
| | 315 | return dst [len .. $]; |
|---|
| 316 | 316 | } |
|---|
| 317 | 317 | } |
|---|
| 318 | | |
|---|
| | 318 | |
|---|
| 319 | 319 | return "{output width too small}"; |
|---|
| 320 | | } |
|---|
| 321 | | |
|---|
| 322 | | |
|---|
| 323 | | /****************************************************************************** |
|---|
| 324 | | |
|---|
| 325 | | Parse an integer value from the provided 'digits' Cutf8. |
|---|
| 326 | | |
|---|
| 327 | | The string is inspected for a sign and an optional radix |
|---|
| 328 | | prefix. A radix may be provided as an argument instead, |
|---|
| | 320 | } |
|---|
| | 321 | |
|---|
| | 322 | |
|---|
| | 323 | /****************************************************************************** |
|---|
| | 324 | |
|---|
| | 325 | Parse an integer value from the provided 'digits' Cutf8. |
|---|
| | 326 | |
|---|
| | 327 | The string is inspected for a sign and an optional radix |
|---|
| | 328 | prefix. A radix may be provided as an argument instead, |
|---|
| 329 | 329 | whereupon it must match the prefix (where present). When |
|---|
| 330 | 330 | radix is set to zero, conversion will default to decimal. |
|---|
| … | … | |
| 406 | 406 | an optional prefix, or the radix is zero, the prefix will |
|---|
| 407 | 407 | be consumed and assigned. Where the radix is non zero and |
|---|
| 408 | | does not match an explicit prefix, the latter will remain |
|---|
| | 408 | does not match an explicit prefix, the latter will remain |
|---|
| 409 | 409 | unconsumed. Otherwise, radix will default to 10. |
|---|
| 410 | 410 | |
|---|
| … | … | |
| 446 | 446 | r = 16, ++p; |
|---|
| 447 | 447 | break; |
|---|
| 448 | | |
|---|
| | 448 | |
|---|
| 449 | 449 | case 'b': |
|---|
| 450 | 450 | case 'B': |
|---|
| 451 | 451 | r = 2, ++p; |
|---|
| 452 | 452 | break; |
|---|
| 453 | | |
|---|
| | 453 | |
|---|
| 454 | 454 | case 'o': |
|---|
| 455 | 455 | case 'O': |
|---|
| 456 | 456 | r = 8, ++p; |
|---|
| 457 | 457 | break; |
|---|
| 458 | | |
|---|
| 459 | | default: |
|---|
| | 458 | |
|---|
| | 459 | default: |
|---|
| 460 | 460 | break; |
|---|
| 461 | | } |
|---|
| | 461 | } |
|---|
| 462 | 462 | |
|---|
| 463 | 463 | // default the radix to 10 |
|---|
| … | … | |
| 484 | 484 | |
|---|
| 485 | 485 | Return the parsed uint |
|---|
| 486 | | |
|---|
| | 486 | |
|---|
| 487 | 487 | ******************************************************************************/ |
|---|
| 488 | 488 | |
|---|
| … | … | |
| 507 | 507 | |
|---|
| 508 | 508 | Returns a populated slice of the provided output |
|---|
| 509 | | |
|---|
| | 509 | |
|---|
| 510 | 510 | ******************************************************************************/ |
|---|
| 511 | 511 | |
|---|
| … | … | |
| 533 | 533 | { |
|---|
| 534 | 534 | char[64] tmp; |
|---|
| 535 | | |
|---|
| | 535 | |
|---|
| 536 | 536 | assert (toInt("1") is 1); |
|---|
| 537 | 537 | assert (toLong("1") is 1); |
|---|
Download in other formats:
|
 |