-
Notifications
You must be signed in to change notification settings - Fork 482
Expand file tree
/
Copy pathStdlib_String.res
More file actions
204 lines (165 loc) · 6.19 KB
/
Stdlib_String.res
File metadata and controls
204 lines (165 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
type t = string
@val external make: 'a => string = "String"
@val external fromCharCode: int => string = "String.fromCharCode"
@variadic @val external fromCharCodeMany: array<int> => string = "String.fromCharCode"
@val external fromCodePoint: int => string = "String.fromCodePoint"
@variadic @val external fromCodePointMany: array<int> => string = "String.fromCodePoint"
external equal: (string, string) => bool = "%equal"
external compare: (string, string) => Stdlib_Ordering.t = "%compare"
@get external length: string => int = "length"
@get_index external get: (string, int) => option<string> = ""
@get_index external getUnsafe: (string, int) => string = ""
@send external charAt: (string, int) => string = "charAt"
@send external charCodeAtUnsafe: (string, int) => int = "charCodeAt"
@val @scope("Number") external isNaN: float => bool = "isNaN"
@send external charCodeAt: (string, int) => float = "charCodeAt"
let charCodeAt = (s, i) => {
let c = charCodeAt(s, i)
isNaN(c) ? None : Some(c->Stdlib_Int.fromFloat)
}
@send external codePointAt: (string, int) => option<int> = "codePointAt"
@send external concat: (string, string) => string = "concat"
@variadic @send external concatMany: (string, array<string>) => string = "concat"
@send external endsWith: (string, string) => bool = "endsWith"
@send external endsWithFrom: (string, string, int) => bool = "endsWith"
@send external includes: (string, string) => bool = "includes"
@send external includesFrom: (string, string, int) => bool = "includes"
@send external indexOf: (string, string) => int = "indexOf"
let indexOfOpt = (s, search) =>
switch indexOf(s, search) {
| -1 => None
| index => Some(index)
}
@send external indexOfFrom: (string, string, int) => int = "indexOf"
@send external lastIndexOf: (string, string) => int = "lastIndexOf"
let lastIndexOfOpt = (s, search) =>
switch lastIndexOf(s, search) {
| -1 => None
| index => Some(index)
}
@send external lastIndexOfFrom: (string, string, int) => int = "lastIndexOf"
@return(nullable) @send
external match: (string, Stdlib_RegExp.t) => option<Stdlib_RegExp.Result.t> = "match"
type normalizeForm = [#NFC | #NFD | #NFKC | #NFKD]
@send external normalize: string => string = "normalize"
@send external normalizeByForm: (string, normalizeForm) => string = "normalize"
@send external repeat: (string, int) => string = "repeat"
@send external replace: (string, string, string) => string = "replace"
@send external replaceRegExp: (string, Stdlib_RegExp.t, string) => string = "replace"
@send external replaceAll: (string, string, string) => string = "replaceAll"
@send external replaceAllRegExp: (string, Stdlib_RegExp.t, string) => string = "replaceAll"
@send
external unsafeReplaceRegExpBy0: (
string,
Stdlib_RegExp.t,
(~match: string, ~offset: int, ~input: string) => string,
) => string = "replace"
@send
external unsafeReplaceRegExpBy1: (
string,
Stdlib_RegExp.t,
(~match: string, ~group1: string, ~offset: int, ~input: string) => string,
) => string = "replace"
@send
external unsafeReplaceRegExpBy2: (
string,
Stdlib_RegExp.t,
(~match: string, ~group1: string, ~group2: string, ~offset: int, ~input: string) => string,
) => string = "replace"
@send
external unsafeReplaceRegExpBy3: (
string,
Stdlib_RegExp.t,
(
~match: string,
~group1: string,
~group2: string,
~group3: string,
~offset: int,
~input: string,
) => string,
) => string = "replace"
@send
external replaceRegExpBy0Unsafe: (
string,
Stdlib_RegExp.t,
(~match: string, ~offset: int, ~input: string) => string,
) => string = "replace"
@send
external replaceRegExpBy1Unsafe: (
string,
Stdlib_RegExp.t,
(~match: string, ~group1: string, ~offset: int, ~input: string) => string,
) => string = "replace"
@send
external replaceRegExpBy2Unsafe: (
string,
Stdlib_RegExp.t,
(~match: string, ~group1: string, ~group2: string, ~offset: int, ~input: string) => string,
) => string = "replace"
@send
external replaceRegExpBy3Unsafe: (
string,
Stdlib_RegExp.t,
(
~match: string,
~group1: string,
~group2: string,
~group3: string,
~offset: int,
~input: string,
) => string,
) => string = "replace"
@send external search: (string, Stdlib_RegExp.t) => int = "search"
let searchOpt = (s, re) =>
switch search(s, re) {
| -1 => None
| index => Some(index)
}
@send external slice: (string, ~start: int, ~end: int=?) => string = "slice"
@deprecated({
reason: "Use `slice` instead",
migrate: String.slice(),
})
@send
external sliceToEnd: (string, ~start: int) => string = "slice"
@send external split: (string, string) => array<string> = "split"
@send external splitAtMost: (string, string, ~limit: int) => array<string> = "split"
@send external splitByRegExp: (string, Stdlib_RegExp.t) => array<option<string>> = "split"
@send
external splitByRegExpAtMost: (string, Stdlib_RegExp.t, ~limit: int) => array<option<string>> =
"split"
@send external startsWith: (string, string) => bool = "startsWith"
@send external startsWithFrom: (string, string, int) => bool = "startsWith"
@send external substring: (string, ~start: int, ~end: int=?) => string = "substring"
@deprecated({
reason: "Use `substring` instead",
migrate: String.substring(),
})
@send
external substringToEnd: (string, ~start: int) => string = "substring"
@send external toLowerCase: string => string = "toLowerCase"
@send external toLocaleLowerCase: string => string = "toLocaleLowerCase"
@send external toUpperCase: string => string = "toUpperCase"
@send external toLocaleUpperCase: string => string = "toLocaleUpperCase"
@send external trim: string => string = "trim"
@send external trimStart: string => string = "trimStart"
@send external trimEnd: string => string = "trimEnd"
@send external padStart: (string, int, string) => string = "padStart"
@send external padEnd: (string, int, string) => string = "padEnd"
@send
external localeCompare: (
string,
string,
~locales: array<string>=?,
~options: Stdlib_Intl_Collator.options=?,
) => float = "localeCompare"
let isEmpty = s => length(s) == 0
let capitalize = s =>
if isEmpty(s) {
s
} else {
toUpperCase(getUnsafe(s, 0)) ++ sliceToEnd(s, ~start=1)
}
external ignore: string => unit = "%ignore"
@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = ""