 |
Changeset 3442
- Timestamp:
- 04/18/08 00:36:21
(8 months ago)
- Author:
- kris
- Message:
fixes # 1025 :: added standard() and native to Path.d
Thanks to baxxismo
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3412 |
r3442 |
|
| 357 | 357 | final FilePath replace (char from, char to) |
|---|
| 358 | 358 | { |
|---|
| 359 | | foreach (inout char c; path) |
|---|
| 360 | | if (c is from) |
|---|
| 361 | | c = to; |
|---|
| | 359 | .replace (path, from, to); |
|---|
| 362 | 360 | return this; |
|---|
| 363 | 361 | } |
|---|
| … | … | |
| 378 | 376 | final FilePath standard () |
|---|
| 379 | 377 | { |
|---|
| 380 | | return replace ('\\', '/'); |
|---|
| | 378 | .standard (path); |
|---|
| | 379 | return this; |
|---|
| 381 | 380 | } |
|---|
| 382 | 381 | |
|---|
| … | … | |
| 393 | 392 | final FilePath native () |
|---|
| 394 | 393 | { |
|---|
| 395 | | version (Win32) |
|---|
| 396 | | return replace ('/', '\\'); |
|---|
| 397 | | else |
|---|
| 398 | | return this; |
|---|
| | 394 | .native (path); |
|---|
| | 395 | return this; |
|---|
| 399 | 396 | } |
|---|
| 400 | 397 | |
|---|
| r3413 |
r3442 |
|
| 1084 | 1084 | } |
|---|
| 1085 | 1085 | |
|---|
| | 1086 | /******************************************************************************* |
|---|
| | 1087 | |
|---|
| | 1088 | Convert path separators to a standard format, using '/' as |
|---|
| | 1089 | the path separator. This is compatible with URI and all of |
|---|
| | 1090 | the contemporary O/S which Tango supports. Known exceptions |
|---|
| | 1091 | include the Windows command-line processor, which considers |
|---|
| | 1092 | '/' characters to be switches instead. Use the native() |
|---|
| | 1093 | method to support that. |
|---|
| | 1094 | |
|---|
| | 1095 | Note: mutates the provided path. |
|---|
| | 1096 | |
|---|
| | 1097 | *******************************************************************************/ |
|---|
| | 1098 | |
|---|
| | 1099 | final char[] standard (char[] path) |
|---|
| | 1100 | { |
|---|
| | 1101 | return replace (path, '\\', '/'); |
|---|
| | 1102 | } |
|---|
| | 1103 | |
|---|
| | 1104 | /******************************************************************************* |
|---|
| | 1105 | |
|---|
| | 1106 | Convert to native O/S path separators where that is required, |
|---|
| | 1107 | such as when dealing with the Windows command-line. |
|---|
| | 1108 | |
|---|
| | 1109 | Note: mutates the provided path. Use this pattern to obtain a |
|---|
| | 1110 | copy instead: native(path.dup); |
|---|
| | 1111 | |
|---|
| | 1112 | *******************************************************************************/ |
|---|
| | 1113 | |
|---|
| | 1114 | final char[] native (char[] path) |
|---|
| | 1115 | { |
|---|
| | 1116 | version (Win32) |
|---|
| | 1117 | replace (path, '/', '\\'); |
|---|
| | 1118 | return path; |
|---|
| | 1119 | } |
|---|
| | 1120 | |
|---|
| | 1121 | /******************************************************************************* |
|---|
| | 1122 | |
|---|
| | 1123 | Replace all path 'from' instances with 'to' |
|---|
| | 1124 | |
|---|
| | 1125 | *******************************************************************************/ |
|---|
| | 1126 | |
|---|
| | 1127 | package char[] replace (char[] path, char from, char to) |
|---|
| | 1128 | { |
|---|
| | 1129 | foreach (inout char c; path) |
|---|
| | 1130 | if (c is from) |
|---|
| | 1131 | c = to; |
|---|
| | 1132 | return path; |
|---|
| | 1133 | } |
|---|
| | 1134 | |
|---|
| 1086 | 1135 | |
|---|
| 1087 | 1136 | /******************************************************************************* |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic