Skip to content

Commit

Permalink
new Pathname.normalize for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fdopen committed Apr 13, 2016
1 parent 69b2800 commit 900b18b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/pathname.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@ let rec normalize_list = function
| x :: xs -> x :: normalize_list xs

let normalize x =
let x =
if Sys.win32 = false then
x
else
let len = String.length x in
let b = Bytes.create len in
let use_bs = ref false in
for i = 0 to pred len do
match x.[i] with
| '\\' -> Bytes.set b i '/'
| c -> Bytes.set b i c
done;
if len > 1 then (
let c1 = Bytes.get b 0 in
let c2 = Bytes.get b 1 in
if c2 = ':' && c1 >= 'a' && c1 <= 'z' &&
( len = 2 || Bytes.get b 2 = '/') then
Bytes.set b 0 (Char.uppercase_ascii c1)
);
Bytes.unsafe_to_string b
in
if Glob.eval not_normal_form_re x then
let root, paths = split x in
join root (normalize_list paths)
Expand Down

0 comments on commit 900b18b

Please sign in to comment.