Skip to content

Commit e7f0524

Browse files
committed
plotgitsch: trim lines for CR characters
Sometimes line endings on Windows are with CR LF instead of simply LF. fixes #56
1 parent 25c14ff commit e7f0524

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

plotkicadsch/src/kicadDiff.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ let is_suffix ~suffix s =
2525
(String.equal (String.sub s ~pos:(String.length s - suff_length) ~len:suff_length) suffix)
2626
;;
2727

28+
let trim_cr l = if is_suffix ~suffix:"\r" l then String.sub ~pos:0 ~len:(String.length l - 1) l else l
29+
;;
30+
2831
module FSPainter (S : SchPainter) (F : Simple_FS) : sig
2932
val find_schematics : unit -> (string list * string) list Lwt.t
3033

@@ -36,7 +39,9 @@ end = struct
3639
let find_schematics () = F.list_files (is_suffix ~suffix:".sch")
3740

3841
let process_file initctx filename =
39-
let parse c l = S.parse_line l c in
42+
let parse c l =
43+
let trimmed_line = trim_cr l in
44+
S.parse_line trimmed_line c in
4045
let%lwt init = initctx in
4146
F.get_content filename
4247
>|= fun ctt ->
@@ -48,11 +53,14 @@ end = struct
4853
F.list_files (is_suffix ~suffix:"-cache.lib") >|= List.map ~f:fst
4954

5055
let read_libs initial_ctx lib_list =
56+
let add_lib ctx l =
57+
let trimmed_line = trim_cr l in
58+
S.add_lib trimmed_line ctx in
5159
Lwt_list.fold_left_s
5260
(fun c l ->
5361
F.get_content l
5462
>|= String.split_on_char ~sep:'\n'
55-
>|= List.fold_left ~f:(fun ctxt l -> S.add_lib l ctxt) ~init:c )
63+
>|= List.fold_left ~f:add_lib ~init:c)
5664
initial_ctx lib_list
5765

5866
let context_from from_ctx =

0 commit comments

Comments
 (0)