Skip to content

Commit 1908565

Browse files
committed
Remove uses of Str.
1 parent da986a5 commit 1908565

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

jscomp/gentype/Annotation.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ and structureCheckAnnotation ~checkAnnotation (structure : Typedtree.structure)
231231
structure.str_items
232232
|> List.exists (structureItemCheckAnnotation ~checkAnnotation)
233233

234-
let sanitizeVariableName name = name |> Str.global_replace (Str.regexp "-") "_"
234+
let sanitizeVariableName name =
235+
name |> String.map (function '-' -> '_' | c -> c)
235236

236237
let importFromString importString : import =
237238
let name =

jscomp/gentype/EmitJs.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ let rec emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
140140
match valueName = asPath with
141141
| true -> (valueName, "")
142142
| false -> (
143-
match asPath |> Str.split (Str.regexp "\\.") with
143+
match asPath |> String.split_on_char '.' with
144144
| x :: y -> (x, "" :: y |> String.concat ".")
145145
| _ -> (asPath, ""))
146146
in

jscomp/gentype/GenTypeCommon.ml

+8-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ type labelJS =
1717
type case = { label : string; labelJS : labelJS }
1818

1919
let isJSSafePropertyName name =
20-
let jsSafeRegex = {|^[A-z][A-z0-9]*$|} |> Str.regexp in
21-
Str.string_match jsSafeRegex name 0
20+
name = ""
21+
|| (match name.[0] with 'A' .. 'z' -> true | _ -> false)
22+
&& name
23+
|> String.for_all (function
24+
| 'A' .. 'z' | '0' .. '9' -> true
25+
| _ -> false)
2226

2327
let labelJSToString ?(alwaysQuotes = false) case =
2428
let addQuotes x =
@@ -195,7 +199,7 @@ let variantTable hash ~toJS =
195199
let ident ?(builtin = true) ?(typeArgs = []) name =
196200
Ident { builtin; name; typeArgs }
197201

198-
let sanitizeTypeName name = name |> Str.global_replace (Str.regexp "'") "_"
202+
let sanitizeTypeName name = name |> String.map (function '\'' -> '_' | c -> c)
199203
let unknown = ident "unknown"
200204
let booleanT = ident "boolean"
201205
let dateT = ident "Date"
@@ -221,7 +225,7 @@ module NodeFilename = struct
221225

222226
let normalize path : t =
223227
match Sys.os_type with
224-
| "Win32" -> path |> Str.split (Str.regexp "\\") |> String.concat dirSep
228+
| "Win32" -> path |> String.split_on_char '\\' |> String.concat dirSep
225229
| _ -> path
226230

227231
let toString path = path

jscomp/gentype/GenTypeConfig.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ let getShims map =
7272
|> Array.iter (fun x ->
7373
match x with
7474
| Ext_json_types.Str { str } ->
75-
let fromTo = Str.split (Str.regexp "=") str |> Array.of_list in
75+
let fromTo =
76+
str |> String.split_on_char '=' |> Array.of_list
77+
in
7678
assert (Array.length fromTo == 2);
7779
shims := (fromTo.(0), fromTo.(1)) :: !shims
7880
| _ -> ())

jscomp/gentype/ModuleName.ml

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@ type t = string
22

33
let curry = "Curry"
44
let rescriptPervasives = "RescriptPervasives"
5-
let dotRegex = "." |> Str.quote |> Str.regexp
6-
let lbracketRegex = "[" |> Str.quote |> Str.regexp
7-
let rbracketRegex = "]" |> Str.quote |> Str.regexp
85

96
let sanitizeId s =
107
let s =
118
if String.contains s '.' || String.contains s '[' || String.contains s ']'
12-
then
13-
s
14-
|> Str.global_replace dotRegex "_"
15-
|> Str.global_replace lbracketRegex "_"
16-
|> Str.global_replace rbracketRegex "_"
9+
then s |> String.map (function '.' | '[' | ']' -> '_' | c -> c)
1710
else s
1811
in
1912
if s <> "" && s.[0] >= 'A' && s.[0] <= 'z' then s else "_" ^ s

lib/4.06.1/whole_compiler.ml

+15-15
Original file line numberDiff line numberDiff line change
@@ -235680,18 +235680,11 @@ type t = string
235680235680

235681235681
let curry = "Curry"
235682235682
let rescriptPervasives = "RescriptPervasives"
235683-
let dotRegex = "." |> Str.quote |> Str.regexp
235684-
let lbracketRegex = "[" |> Str.quote |> Str.regexp
235685-
let rbracketRegex = "]" |> Str.quote |> Str.regexp
235686235683

235687235684
let sanitizeId s =
235688235685
let s =
235689235686
if String.contains s '.' || String.contains s '[' || String.contains s ']'
235690-
then
235691-
s
235692-
|> Str.global_replace dotRegex "_"
235693-
|> Str.global_replace lbracketRegex "_"
235694-
|> Str.global_replace rbracketRegex "_"
235687+
then s |> String.map (function '.' | '[' | ']' -> '_' | c -> c)
235695235688
else s
235696235689
in
235697235690
if s <> "" && s.[0] >= 'A' && s.[0] <= 'z' then s else "_" ^ s
@@ -235784,7 +235777,9 @@ let getShims map =
235784235777
|> Array.iter (fun x ->
235785235778
match x with
235786235779
| Ext_json_types.Str { str } ->
235787-
let fromTo = Str.split (Str.regexp "=") str |> Array.of_list in
235780+
let fromTo =
235781+
str |> String.split_on_char '=' |> Array.of_list
235782+
in
235788235783
assert (Array.length fromTo == 2);
235789235784
shims := (fromTo.(0), fromTo.(1)) :: !shims
235790235785
| _ -> ())
@@ -236020,8 +236015,12 @@ type labelJS =
236020236015
type case = { label : string; labelJS : labelJS }
236021236016

236022236017
let isJSSafePropertyName name =
236023-
let jsSafeRegex = {|^[A-z][A-z0-9]*$|} |> Str.regexp in
236024-
Str.string_match jsSafeRegex name 0
236018+
name = ""
236019+
|| (match name.[0] with 'A' .. 'z' -> true | _ -> false)
236020+
&& name
236021+
|> String.for_all (function
236022+
| 'A' .. 'z' | '0' .. '9' -> true
236023+
| _ -> false)
236025236024

236026236025
let labelJSToString ?(alwaysQuotes = false) case =
236027236026
let addQuotes x =
@@ -236198,7 +236197,7 @@ let variantTable hash ~toJS =
236198236197
let ident ?(builtin = true) ?(typeArgs = []) name =
236199236198
Ident { builtin; name; typeArgs }
236200236199

236201-
let sanitizeTypeName name = name |> Str.global_replace (Str.regexp "'") "_"
236200+
let sanitizeTypeName name = name |> String.map (function '\'' -> '_' | c -> c)
236202236201
let unknown = ident "unknown"
236203236202
let booleanT = ident "boolean"
236204236203
let dateT = ident "Date"
@@ -236224,7 +236223,7 @@ module NodeFilename = struct
236224236223

236225236224
let normalize path : t =
236226236225
match Sys.os_type with
236227-
| "Win32" -> path |> Str.split (Str.regexp "\\") |> String.concat dirSep
236226+
| "Win32" -> path |> String.split_on_char '\\' |> String.concat dirSep
236228236227
| _ -> path
236229236228

236230236229
let toString path = path
@@ -236528,7 +236527,8 @@ and structureCheckAnnotation ~checkAnnotation (structure : Typedtree.structure)
236528236527
structure.str_items
236529236528
|> List.exists (structureItemCheckAnnotation ~checkAnnotation)
236530236529

236531-
let sanitizeVariableName name = name |> Str.global_replace (Str.regexp "-") "_"
236530+
let sanitizeVariableName name =
236531+
name |> String.map (function '-' -> '_' | c -> c)
236532236532

236533236533
let importFromString importString : import =
236534236534
let name =
@@ -240407,7 +240407,7 @@ let rec emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
240407240407
match valueName = asPath with
240408240408
| true -> (valueName, "")
240409240409
| false -> (
240410-
match asPath |> Str.split (Str.regexp "\\.") with
240410+
match asPath |> String.split_on_char '.' with
240411240411
| x :: y -> (x, "" :: y |> String.concat ".")
240412240412
| _ -> (asPath, ""))
240413240413
in

scripts/ninjaFactory.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ build ../${targetDir}/rescript$ext: cc $INCL/rescript.mli $INCL/rescript.ml
2929
build ../${targetDir}/bsb_helper$ext: cc $INCL/bsb_helper.mli $INCL/bsb_helper.ml
3030
flags = $flags -unboxed-types -w -a
3131
build ../${targetDir}/bsc$ext: cc $INCL/whole_compiler.mli $INCL/whole_compiler.ml
32-
flags = $flags -w A-4-9-48-40-45-41-44-50-21-30-32-34-37-27-60-42 str.cmxa
32+
flags = $flags -w A-4-9-48-40-45-41-44-50-21-30-32-34-37-27-60-42
3333
`;
3434
}
3535

0 commit comments

Comments
 (0)