@@ -119,6 +119,130 @@ let string_of_bsb_dev_include i =
119
119
120
120
121
121
let reset () = dir_index := 0
122
+ end
123
+ module Ext_bytes : sig
124
+ #1 " ext_bytes.mli"
125
+ (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
126
+ *
127
+ * This program is free software: you can redistribute it and/or modify
128
+ * it under the terms of the GNU Lesser General Public License as published by
129
+ * the Free Software Foundation, either version 3 of the License, or
130
+ * (at your option) any later version.
131
+ *
132
+ * In addition to the permissions granted to you by the LGPL, you may combine
133
+ * or link a "work that uses the Library" with a publicly distributed version
134
+ * of this file to produce a combined library or application, then distribute
135
+ * that combined work under the terms of your choosing, with no requirement
136
+ * to comply with the obligations normally placed on you by section 4 of the
137
+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
138
+ * should you choose to use a later version).
139
+ *
140
+ * This program is distributed in the hope that it will be useful,
141
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
142
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
143
+ * GNU Lesser General Public License for more details.
144
+ *
145
+ * You should have received a copy of the GNU Lesser General Public License
146
+ * along with this program; if not, write to the Free Software
147
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
148
+
149
+
150
+
151
+
152
+
153
+ external unsafe_blit_string : string -> int -> bytes -> int -> int -> unit
154
+ = " caml_blit_string"
155
+
156
+ " noalloc"
157
+
158
+
159
+
160
+
161
+ (* * Port the {!Bytes.escaped} from trunk to make it not locale sensitive *)
162
+
163
+ val escaped : bytes -> bytes
164
+
165
+ end = struct
166
+ #1 " ext_bytes.ml"
167
+ (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
168
+ *
169
+ * This program is free software: you can redistribute it and/or modify
170
+ * it under the terms of the GNU Lesser General Public License as published by
171
+ * the Free Software Foundation, either version 3 of the License, or
172
+ * (at your option) any later version.
173
+ *
174
+ * In addition to the permissions granted to you by the LGPL, you may combine
175
+ * or link a "work that uses the Library" with a publicly distributed version
176
+ * of this file to produce a combined library or application, then distribute
177
+ * that combined work under the terms of your choosing, with no requirement
178
+ * to comply with the obligations normally placed on you by section 4 of the
179
+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
180
+ * should you choose to use a later version).
181
+ *
182
+ * This program is distributed in the hope that it will be useful,
183
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
184
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
185
+ * GNU Lesser General Public License for more details.
186
+ *
187
+ * You should have received a copy of the GNU Lesser General Public License
188
+ * along with this program; if not, write to the Free Software
189
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+ external unsafe_blit_string : string -> int -> bytes -> int -> int -> unit
198
+ = " caml_blit_string"
199
+
200
+ " noalloc"
201
+
202
+
203
+ external char_code : char -> int = " %identity"
204
+ external char_chr : int -> char = " %identity"
205
+
206
+ let escaped s =
207
+ let n = Pervasives. ref 0 in
208
+ for i = 0 to Bytes. length s - 1 do
209
+ n := ! n +
210
+ (match Bytes. unsafe_get s i with
211
+ | '"' | '\\' | '\n' | '\t' | '\r' | '\b' -> 2
212
+ | ' ' .. '~' -> 1
213
+ | _ -> 4 )
214
+ done ;
215
+ if ! n = Bytes. length s then Bytes. copy s else begin
216
+ let s' = Bytes. create ! n in
217
+ n := 0 ;
218
+ for i = 0 to Bytes. length s - 1 do
219
+ begin match Bytes. unsafe_get s i with
220
+ | ('"' | '\\' ) as c ->
221
+ Bytes. unsafe_set s' ! n '\\' ; incr n; Bytes. unsafe_set s' ! n c
222
+ | '\n' ->
223
+ Bytes. unsafe_set s' ! n '\\' ; incr n; Bytes. unsafe_set s' ! n 'n'
224
+ | '\t' ->
225
+ Bytes. unsafe_set s' ! n '\\' ; incr n; Bytes. unsafe_set s' ! n 't'
226
+ | '\r' ->
227
+ Bytes. unsafe_set s' ! n '\\' ; incr n; Bytes. unsafe_set s' ! n 'r'
228
+ | '\b' ->
229
+ Bytes. unsafe_set s' ! n '\\' ; incr n; Bytes. unsafe_set s' ! n 'b'
230
+ | (' ' .. '~' ) as c -> Bytes. unsafe_set s' ! n c
231
+ | c ->
232
+ let a = char_code c in
233
+ Bytes. unsafe_set s' ! n '\\' ;
234
+ incr n;
235
+ Bytes. unsafe_set s' ! n (char_chr (48 + a / 100 ));
236
+ incr n;
237
+ Bytes. unsafe_set s' ! n (char_chr (48 + (a / 10 ) mod 10 ));
238
+ incr n;
239
+ Bytes. unsafe_set s' ! n (char_chr (48 + a mod 10 ));
240
+ end ;
241
+ incr n
242
+ done ;
243
+ s'
244
+ end
245
+
122
246
end
123
247
module Ext_buffer : sig
124
248
#1 " ext_buffer.mli"
@@ -311,7 +435,8 @@ let resize b more =
311
435
this tricky function that is slow anyway. *)
312
436
Bytes. blit b.buffer 0 new_buffer 0 b.position;
313
437
b.buffer < - new_buffer;
314
- b.length < - ! new_len
438
+ b.length < - ! new_len ;
439
+ assert (b.position + more < = b.length)
315
440
316
441
let add_char b c =
317
442
let pos = b.position in
@@ -324,7 +449,7 @@ let add_substring b s offset len =
324
449
then invalid_arg " Ext_buffer.add_substring/add_subbytes" ;
325
450
let new_position = b.position + len in
326
451
if new_position > b.length then resize b len;
327
- Bytes. blit_string s offset b.buffer b.position len;
452
+ Ext_bytes. unsafe_blit_string s offset b.buffer b.position len;
328
453
b.position < - new_position
329
454
330
455
@@ -335,7 +460,7 @@ let add_string b s =
335
460
let len = String. length s in
336
461
let new_position = b.position + len in
337
462
if new_position > b.length then resize b len;
338
- Bytes. blit_string s 0 b.buffer b.position len;
463
+ Ext_bytes. unsafe_blit_string s 0 b.buffer b.position len;
339
464
b.position < - new_position
340
465
341
466
(* TODO: micro-optimzie *)
@@ -345,7 +470,7 @@ let add_string_char b s c =
345
470
let new_position = b.position + len in
346
471
if new_position > b.length then resize b len;
347
472
let b_buffer = b.buffer in
348
- Bytes. blit_string s 0 b_buffer b.position s_len;
473
+ Ext_bytes. unsafe_blit_string s 0 b_buffer b.position s_len;
349
474
Bytes. unsafe_set b_buffer (new_position - 1 ) c;
350
475
b.position < - new_position
351
476
@@ -357,7 +482,7 @@ let add_char_string b c s =
357
482
let b_buffer = b.buffer in
358
483
let b_position = b.position in
359
484
Bytes. unsafe_set b_buffer b_position c ;
360
- Bytes. blit_string s 0 b_buffer (b_position + 1 ) s_len;
485
+ Ext_bytes. unsafe_blit_string s 0 b_buffer (b_position + 1 ) s_len;
361
486
b.position < - new_position
362
487
363
488
@@ -2047,130 +2172,6 @@ let write_file f content =
2047
2172
output_string oc content
2048
2173
end
2049
2174
2050
- end
2051
- module Ext_bytes : sig
2052
- #1 " ext_bytes.mli"
2053
- (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2054
- *
2055
- * This program is free software: you can redistribute it and/or modify
2056
- * it under the terms of the GNU Lesser General Public License as published by
2057
- * the Free Software Foundation, either version 3 of the License, or
2058
- * (at your option) any later version.
2059
- *
2060
- * In addition to the permissions granted to you by the LGPL, you may combine
2061
- * or link a "work that uses the Library" with a publicly distributed version
2062
- * of this file to produce a combined library or application, then distribute
2063
- * that combined work under the terms of your choosing, with no requirement
2064
- * to comply with the obligations normally placed on you by section 4 of the
2065
- * LGPL version 3 (or the corresponding section of a later version of the LGPL
2066
- * should you choose to use a later version).
2067
- *
2068
- * This program is distributed in the hope that it will be useful,
2069
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2070
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2071
- * GNU Lesser General Public License for more details.
2072
- *
2073
- * You should have received a copy of the GNU Lesser General Public License
2074
- * along with this program; if not, write to the Free Software
2075
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2076
-
2077
-
2078
-
2079
-
2080
-
2081
- external unsafe_blit_string : string -> int -> bytes -> int -> int -> unit
2082
- = " caml_blit_string"
2083
-
2084
- " noalloc"
2085
-
2086
-
2087
-
2088
-
2089
- (* * Port the {!Bytes.escaped} from trunk to make it not locale sensitive *)
2090
-
2091
- val escaped : bytes -> bytes
2092
-
2093
- end = struct
2094
- #1 " ext_bytes.ml"
2095
- (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2096
- *
2097
- * This program is free software: you can redistribute it and/or modify
2098
- * it under the terms of the GNU Lesser General Public License as published by
2099
- * the Free Software Foundation, either version 3 of the License, or
2100
- * (at your option) any later version.
2101
- *
2102
- * In addition to the permissions granted to you by the LGPL, you may combine
2103
- * or link a "work that uses the Library" with a publicly distributed version
2104
- * of this file to produce a combined library or application, then distribute
2105
- * that combined work under the terms of your choosing, with no requirement
2106
- * to comply with the obligations normally placed on you by section 4 of the
2107
- * LGPL version 3 (or the corresponding section of a later version of the LGPL
2108
- * should you choose to use a later version).
2109
- *
2110
- * This program is distributed in the hope that it will be useful,
2111
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2112
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2113
- * GNU Lesser General Public License for more details.
2114
- *
2115
- * You should have received a copy of the GNU Lesser General Public License
2116
- * along with this program; if not, write to the Free Software
2117
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2118
-
2119
-
2120
-
2121
-
2122
-
2123
-
2124
-
2125
- external unsafe_blit_string : string -> int -> bytes -> int -> int -> unit
2126
- = " caml_blit_string"
2127
-
2128
- " noalloc"
2129
-
2130
-
2131
- external char_code : char -> int = " %identity"
2132
- external char_chr : int -> char = " %identity"
2133
-
2134
- let escaped s =
2135
- let n = Pervasives. ref 0 in
2136
- for i = 0 to Bytes. length s - 1 do
2137
- n := ! n +
2138
- (match Bytes. unsafe_get s i with
2139
- | '"' | '\\' | '\n' | '\t' | '\r' | '\b' -> 2
2140
- | ' ' .. '~' -> 1
2141
- | _ -> 4 )
2142
- done ;
2143
- if ! n = Bytes. length s then Bytes. copy s else begin
2144
- let s' = Bytes. create ! n in
2145
- n := 0 ;
2146
- for i = 0 to Bytes. length s - 1 do
2147
- begin match Bytes. unsafe_get s i with
2148
- | ('"' | '\\' ) as c ->
2149
- Bytes. unsafe_set s' ! n '\\' ; incr n; Bytes. unsafe_set s' ! n c
2150
- | '\n' ->
2151
- Bytes. unsafe_set s' ! n '\\' ; incr n; Bytes. unsafe_set s' ! n 'n'
2152
- | '\t' ->
2153
- Bytes. unsafe_set s' ! n '\\' ; incr n; Bytes. unsafe_set s' ! n 't'
2154
- | '\r' ->
2155
- Bytes. unsafe_set s' ! n '\\' ; incr n; Bytes. unsafe_set s' ! n 'r'
2156
- | '\b' ->
2157
- Bytes. unsafe_set s' ! n '\\' ; incr n; Bytes. unsafe_set s' ! n 'b'
2158
- | (' ' .. '~' ) as c -> Bytes. unsafe_set s' ! n c
2159
- | c ->
2160
- let a = char_code c in
2161
- Bytes. unsafe_set s' ! n '\\' ;
2162
- incr n;
2163
- Bytes. unsafe_set s' ! n (char_chr (48 + a / 100 ));
2164
- incr n;
2165
- Bytes. unsafe_set s' ! n (char_chr (48 + (a / 10 ) mod 10 ));
2166
- incr n;
2167
- Bytes. unsafe_set s' ! n (char_chr (48 + a mod 10 ));
2168
- end ;
2169
- incr n
2170
- done ;
2171
- s'
2172
- end
2173
-
2174
2175
end
2175
2176
module Ext_char : sig
2176
2177
#1 " ext_char.mli"
0 commit comments