 |
Changeset 3414
- Timestamp:
- 04/05/08 19:00:30
(3 months ago)
- Author:
- larsivi
- Message:
Removed possibility to specify normalization of slashes.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3402 |
r3414 |
|
| 26 | 26 | <segment>/../ in path is removed |
|---|
| 27 | 27 | |
|---|
| 28 | | Unless normSlash is set to false, all slashes will be converted |
|---|
| 29 | | to the systems path separator character. |
|---|
| | 28 | On Windows, \ will be converted to / prior to normalization. |
|---|
| 30 | 29 | |
|---|
| 31 | 30 | Note that any number of ../ segments at the front is ignored, |
|---|
| … | … | |
| 35 | 34 | be fully normalized. |
|---|
| 36 | 35 | |
|---|
| 37 | | Throws: Exception if the root separator is followed by .. |
|---|
| | 36 | Throws: IllegalArgumentException if the root separator is followed by .. |
|---|
| 38 | 37 | |
|---|
| 39 | 38 | Examples: |
|---|
| … | … | |
| 44 | 43 | *******************************************************************************/ |
|---|
| 45 | 44 | |
|---|
| 46 | | char[] normalize(char[] path, bool normSlash = true) |
|---|
| 47 | | { |
|---|
| | 45 | char[] normalize(char[] path) |
|---|
| | 46 | { |
|---|
| | 47 | |
|---|
| | 48 | version (Windows) { |
|---|
| 48 | 49 | /* |
|---|
| 49 | 50 | Internal helper to patch slashes |
|---|
| … | … | |
| 58 | 59 | return path; |
|---|
| 59 | 60 | } |
|---|
| | 61 | } |
|---|
| 60 | 62 | |
|---|
| 61 | 63 | /* |
|---|
| … | … | |
| 113 | 115 | else if (path[start..start+2] == "..") { |
|---|
| 114 | 116 | // found /.. sequence |
|---|
| 115 | | version (Win32) { |
|---|
| | 117 | version (Windows) { |
|---|
| 116 | 118 | if (start == 3 && path[1] == '/') { // absolute, X:/.. |
|---|
| 117 | | throw new IllegalArgumentException("PathUtil :: Invalid absolute path, root can not be followed by .."); |
|---|
| | 119 | throw new IllegalArgumentException("PathUtil :: Invalid absolute path, root can't be followed by .."); |
|---|
| 118 | 120 | } |
|---|
| 119 | 121 | |
|---|
| … | … | |
| 121 | 123 | else { |
|---|
| 122 | 124 | if (start == 1) { // absolute |
|---|
| 123 | | throw new IllegalArgumentException("PathUtil :: Invalid absolute path, root separator can not be followed by .."); |
|---|
| | 125 | throw new IllegalArgumentException("PathUtil :: Invalid absolute path, root separator can't be followed by .."); |
|---|
| 124 | 126 | } |
|---|
| 125 | 127 | } |
|---|
| … | … | |
| 177 | 179 | |
|---|
| 178 | 180 | char[] normpath = path.dup; |
|---|
| 179 | | if (normSlash) { |
|---|
| 180 | | normpath = normalizeSlashes(normpath); |
|---|
| 181 | | } |
|---|
| | 181 | version (Windows) { |
|---|
| | 182 | normpath = normalizeSlashes(normpath); |
|---|
| | 183 | } |
|---|
| 182 | 184 | |
|---|
| 183 | 185 | // if path starts with ./, remove all subsequent instances |
|---|
| … | … | |
| 228 | 230 | assert (normalize ("d/") == "d/"); |
|---|
| 229 | 231 | |
|---|
| | 232 | version (Windows) { |
|---|
| 230 | 233 | assert (normalize ("\\foo\\..\\john") == "/john"); |
|---|
| 231 | 234 | assert (normalize ("foo\\..\\john") == "john"); |
|---|
| … | … | |
| 240 | 243 | assert (normalize ("..\\..\\foo\\bar") == "../../foo/bar"); |
|---|
| 241 | 244 | assert (normalize ("..\\..\\..\\foo\\bar") == "../../../foo/bar"); |
|---|
| | 245 | } |
|---|
| 242 | 246 | } |
|---|
| 243 | 247 | } |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic