aboutsummaryrefslogtreecommitdiff
path: root/ide/ideutils.ml
diff options
context:
space:
mode:
authorPierre-Marie Pédrot2016-08-17 16:17:17 +0200
committerPierre-Marie Pédrot2016-08-17 16:17:17 +0200
commit13fb26d615cdb03a4c4841c20b108deab2de60b3 (patch)
tree55f86d47695ee2071d1f886ce70ad7eec6a1e866 /ide/ideutils.ml
parent3fd0b8ad700bd77aabdd3f3f33b13ba5e93d8bc8 (diff)
parentbc7ffd368789cb82bb8fc8b642b3de870b92c897 (diff)
Merge branch 'v8.6'
Diffstat (limited to 'ide/ideutils.ml')
-rw-r--r--ide/ideutils.ml24
1 files changed, 19 insertions, 5 deletions
diff --git a/ide/ideutils.ml b/ide/ideutils.ml
index f0698a54a3..fe69be9e48 100644
--- a/ide/ideutils.ml
+++ b/ide/ideutils.ml
@@ -112,6 +112,24 @@ let try_convert s =
"(* Fatal error: wrong encoding in input. \
Please choose a correct encoding in the preference panel.*)";;
+let export file_name s =
+ let oc = open_out_bin file_name in
+ let ending = line_ending#get in
+ let is_windows = ref false in
+ for i = 0 to String.length s - 1 do
+ match s.[i] with
+ | '\r' -> is_windows := true
+ | '\n' ->
+ begin match ending with
+ | `DEFAULT ->
+ if !is_windows then (output_char oc '\r'; output_char oc '\n')
+ else output_char oc '\n'
+ | `WINDOWS -> output_char oc '\r'; output_char oc '\n'
+ | `UNIX -> output_char oc '\n'
+ end
+ | c -> output_char oc c
+ done;
+ close_out oc
let try_export file_name s =
let s =
@@ -134,11 +152,7 @@ let try_export file_name s =
Minilib.log ("Error ("^str^") in transcoding: falling back to UTF-8");
s
in
- try
- let oc = open_out file_name in
- output_string oc s;
- close_out oc;
- true
+ try export file_name s; true
with e -> Minilib.log (Printexc.to_string e);false
type timer = { run : ms:int -> callback:(unit->bool) -> unit;