[commit: packages/filepath] master: Refactor: break instead of span and 3x reverse (4283661)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 11:33:57 UTC 2015


Repository : ssh://git@git.haskell.org/filepath

On branch  : master
Link       : http://git.haskell.org/packages/filepath.git/commitdiff/428366140210c616c1bbfb9a5bf6c31114c6c8b2

>---------------------------------------------------------------

commit 428366140210c616c1bbfb9a5bf6c31114c6c8b2
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date:   Sun Sep 14 23:45:40 2014 +0200

    Refactor: break instead of span and 3x reverse
    
    This works because pathSeparators can only occur at the end of splitPath
    elements. h is passed a pathElement without separators.
    
    Add a test to show that superfluous (and a weird combination of)
    pathSeparators are still preserved. This function does not normalise
    pathSeparators, otherwise it could be simplified further.


>---------------------------------------------------------------

428366140210c616c1bbfb9a5bf6c31114c6c8b2
 System/FilePath/Internal.hs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs
index 7220804..e8cf9a4 100644
--- a/System/FilePath/Internal.hs
+++ b/System/FilePath/Internal.hs
@@ -824,6 +824,7 @@ isValid path =
 -- > isValid (makeValid x)
 -- > isValid x ==> makeValid x == x
 -- > makeValid "" == "_"
+-- > Windows: makeValid "c:\\already\\/valid" == "c:\\already\\/valid"
 -- > Windows: makeValid "c:\\test:of_test" == "c:\\test_of_test"
 -- > Windows: makeValid "test*" == "test_"
 -- > Windows: makeValid "c:\\test\\nul" == "c:\\test\\nul_"
@@ -843,8 +844,8 @@ makeValid path = joinDrive drv $ validElements $ validChars pth
             | otherwise = x
 
         validElements x = joinPath $ map g $ splitPath x
-        g x = h (reverse b) ++ reverse a
-            where (a,b) = span isPathSeparator $ reverse x
+        g x = h a ++ b
+            where (a,b) = break isPathSeparator x
         h x = if map toUpper a `elem` badElements then a ++ "_" <.> b else x
             where (a,b) = splitExtensions x
 



More information about the ghc-commits mailing list