Last active
January 29, 2018 20:19
-
-
Save BlinkyStitt/c9fa3135b8baca50ae79d36417fd9254 to your computer and use it in GitHub Desktop.
unison whitespace backport to 2.40.102. Credit to https://github.com/bcpierce00/unison/pull/121
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ubase/util.ml b/src/ubase/util.ml | |
index 7376799..1231eb6 100644 | |
--- a/ubase/util.ml | |
+++ b/src/ubase/util.ml | |
@@ -399,15 +399,25 @@ let rec trimWhitespace s = | |
else | |
s | |
-let splitIntoWords (s:string) (c:char) = | |
- let rec inword acc start pos = | |
- if pos >= String.length(s) || s.[pos] = c then | |
- betweenwords ((String.sub s start (pos-start)) :: acc) pos | |
- else inword acc start (pos+1) | |
+let splitIntoWords ?esc:(e='\\') (s:string) (c:char) = | |
+ let rec inword acc eacc start pos = | |
+ if pos >= String.length s || s.[pos] = c then | |
+ let word = | |
+ String.concat "" (Safelist.rev (String.sub s start (pos-start)::eacc)) in | |
+ betweenwords (word::acc) pos | |
+ else if s.[pos] = e then inescape acc eacc start pos | |
+ else inword acc eacc start (pos+1) | |
+ and inescape acc eacc start pos = | |
+ let eword = String.sub s start (pos-start) in | |
+ if pos+1 >= String.length s | |
+ then inword acc (eword::eacc) (pos+1) (pos+1) (* ignore final esc *) | |
+ else (* take any following char *) | |
+ let echar = String.make 1 (String.get s (pos+1)) in | |
+ inword acc (echar::eword::eacc) (pos+2) (pos+2) | |
and betweenwords acc pos = | |
- if pos >= (String.length s) then (Safelist.rev acc) | |
+ if pos >= String.length s then (Safelist.rev acc) | |
else if s.[pos]=c then betweenwords acc (pos+1) | |
- else inword acc pos pos | |
+ else inword acc [] pos pos | |
in betweenwords [] 0 | |
let rec splitIntoWordsByString s sep = | |
diff --git a/ubase/util.mli b/src/ubase/util.mli | |
index d4bd8f7..d7409c8 100644 | |
--- a/ubase/util.mli | |
+++ b/src/ubase/util.mli | |
@@ -55,7 +55,7 @@ val replacesubstrings : string -> (string * string) list -> string | |
val concatmap : string -> ('a -> string) -> 'a list -> string | |
val removeTrailingCR : string -> string | |
val trimWhitespace : string -> string | |
-val splitIntoWords : string -> char -> string list | |
+val splitIntoWords : ?esc:char -> string -> char -> string list | |
val splitIntoWordsByString : string -> string -> string list | |
val padto : int -> string -> string | |
diff --git a/src/main.ml b/src/main.ml | |
index d2f5648..01f8d61 100644 | |
--- a/main.ml | |
+++ b/src/main.ml | |
@@ -135,7 +135,7 @@ let init() = begin | |
(* Print version if requested *) | |
if Util.StringMap.mem versionPrefName argv then begin | |
- Printf.printf "%s version %s\n" Uutil.myName Uutil.myVersion; | |
+ Printf.printf "%s version %s-uber\n" Uutil.myName Uutil.myVersion; | |
exit 0 | |
end; | |
diff --git a/src/strings.ml b/src/strings.ml | |
index 4a65623..47b6705 100644 | |
--- a/strings.ml | |
+++ b/src/strings.ml | |
@@ -4,7 +4,7 @@ | |
let docs = | |
("about", ("About Unison", | |
"Unison File Synchronizer\n\ | |
- Version 2.40.102\n\ | |
+ Version 2.40.102-uber\n\ | |
\n\ | |
")) | |
:: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment