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

Changeset 3442

Show
Ignore:
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
  • trunk/tango/io/FilePath.d

    r3412 r3442  
    357357        final FilePath replace (char from, char to) 
    358358        { 
    359                 foreach (inout char c; path) 
    360                          if (c is from) 
    361                              c = to; 
     359                .replace (path, from, to); 
    362360                return this; 
    363361        } 
     
    378376        final FilePath standard () 
    379377        { 
    380                 return replace ('\\', '/'); 
     378                .standard (path); 
     379                return this; 
    381380        } 
    382381 
     
    393392        final FilePath native () 
    394393        { 
    395                 version (Win32) 
    396                          return replace ('/', '\\'); 
    397                      else 
    398                         return this; 
     394                .native (path); 
     395                return this; 
    399396        } 
    400397 
  • trunk/tango/io/Path.d

    r3413 r3442  
    10841084} 
    10851085 
     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 
     1099final 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 
     1114final 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 
     1127package 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 
    10861135 
    10871136/*******************************************************************************