File tree 1 file changed +6
-28
lines changed
1 file changed +6
-28
lines changed Original file line number Diff line number Diff line change @@ -113,37 +113,15 @@ let translate_path_for_sh =
113
113
let quote_for_sh fn =
114
114
(* we lose some portability as [$'] isn't posix. This is why we prefer single
115
115
quotes when possible *)
116
- let has_single_quote = ref false in
117
- (* minimum chars for [$'']*)
118
- let posix_quote_len = ref 3 in
119
- String. iter fn ~f: (function
120
- | '\' ' ->
121
- posix_quote_len := ! posix_quote_len + 2 ;
122
- has_single_quote := true
123
- | '\\' -> posix_quote_len := ! posix_quote_len + 2
124
- | _ -> incr posix_quote_len);
125
- match ! has_single_quote with
116
+ match String. exists fn ~f: (fun c -> c = '\' ') with
126
117
| false -> " '" ^ fn ^ " '"
127
118
| true ->
128
- let len = ! posix_quote_len in
129
- let res = Bytes. create len in
130
- Bytes. set res 0 '$' ;
131
- Bytes. set res 1 '\' ';
132
- Bytes. set res (len - 1 ) '\' ';
133
- let i = ref 2 in
119
+ let buf = Buffer. create (String. length fn + 4 ) in
134
120
String. iter fn ~f: (function
135
- | '\' ' ->
136
- Bytes. set res ! i '\\' ;
137
- Bytes. set res (! i + 1 ) '\' ';
138
- i := ! i + 2
139
- | '\\' ->
140
- Bytes. set res ! i '\\' ;
141
- Bytes. set res (! i + 1 ) '\\' ;
142
- i := ! i + 2
143
- | c ->
144
- Bytes. set res ! i c;
145
- incr i);
146
- Bytes. to_string res
121
+ | '\' ' -> Buffer. add_string buf " \\ '"
122
+ | '\\' -> Buffer. add_string buf " \\\\ "
123
+ | c -> Buffer. add_char buf c);
124
+ Buffer. contents buf
147
125
148
126
let cram_stanzas lexbuf =
149
127
let rec loop acc =
You can’t perform that action at this time.
0 commit comments