@@ -78,6 +78,7 @@ foreign import singleton :: Char -> String
78
78
79
79
-- | Returns the numeric Unicode value of the character at the given index,
80
80
-- | if the index is within bounds.
81
+ -- | - `charCodeAt 2 "5 €" == Just 0x20AC`
81
82
charCodeAt :: Int -> String -> Maybe Int
82
83
charCodeAt = _charCodeAt Just Nothing
83
84
@@ -88,6 +89,8 @@ foreign import _charCodeAt
88
89
-> String
89
90
-> Maybe Int
90
91
92
+ -- | Converts the string to a character, if the length of the string is
93
+ -- | exactly `1`.
91
94
toChar :: String -> Maybe Char
92
95
toChar = _toChar Just Nothing
93
96
@@ -109,6 +112,7 @@ uncons s = Just { head: U.charAt zero s, tail: drop one s }
109
112
110
113
-- | Returns the longest prefix (possibly empty) of characters that satisfy
111
114
-- | the predicate.
115
+ -- | * `takeWhile (_ /= ':') "http://purescript.org" == "http"`
112
116
takeWhile :: (Char -> Boolean ) -> String -> String
113
117
takeWhile p s = take (count p s) s
114
118
@@ -127,7 +131,8 @@ stripPrefix prefix@(Pattern prefixS) str =
127
131
_ -> Nothing
128
132
129
133
-- | If the string ends with the given suffix, return the portion of the
130
- -- | string left after removing it, as a Just value. Otherwise, return Nothing.
134
+ -- | string left after removing it, as a `Just` value. Otherwise, return
135
+ -- | `Nothing`.
131
136
-- | * `stripSuffix (Pattern ".exe") "psc.exe" == Just "psc"`
132
137
-- | * `stripSuffix (Pattern ".exe") "psc" == Nothing`
133
138
stripSuffix :: Pattern -> String -> Maybe String
@@ -139,12 +144,15 @@ stripSuffix suffix@(Pattern suffixS) str =
139
144
-- | Converts an array of characters into a string.
140
145
foreign import fromCharArray :: Array Char -> String
141
146
142
- -- | Checks whether the first string exists in the second string.
147
+ -- | Checks whether the pattern appears in the given string.
148
+ -- | * `contains (Pattern "needle") "haystack with needle" == true`
149
+ -- | * `contains (Pattern "needle") "haystack" == false`
143
150
contains :: Pattern -> String -> Boolean
144
151
contains pat = isJust <<< indexOf pat
145
152
146
- -- | Returns the index of the first occurrence of the first string in the
147
- -- | second string. Returns `Nothing` if there is no match.
153
+ -- | Returns the index of the first occurrence of the pattern in the
154
+ -- | given string. Returns `Nothing` if there is no match.
155
+ -- | * `indexOf (Pattern "c") "abcde" == Just 2`
148
156
indexOf :: Pattern -> String -> Maybe Int
149
157
indexOf = _indexOf Just Nothing
150
158
@@ -155,8 +163,8 @@ foreign import _indexOf
155
163
-> String
156
164
-> Maybe Int
157
165
158
- -- | Returns the index of the first occurrence of the first string in the
159
- -- | second string, starting at the given index. Returns `Nothing` if there is
166
+ -- | Returns the index of the first occurrence of the pattern in the
167
+ -- | given string, starting at the specified index. Returns `Nothing` if there is
160
168
-- | no match.
161
169
indexOf' :: Pattern -> Int -> String -> Maybe Int
162
170
indexOf' = _indexOf' Just Nothing
@@ -169,8 +177,8 @@ foreign import _indexOf'
169
177
-> String
170
178
-> Maybe Int
171
179
172
- -- | Returns the index of the last occurrence of the first string in the
173
- -- | second string. Returns `Nothing` if there is no match.
180
+ -- | Returns the index of the last occurrence of the pattern in the
181
+ -- | given string. Returns `Nothing` if there is no match.
174
182
lastIndexOf :: Pattern -> String -> Maybe Int
175
183
lastIndexOf = _lastIndexOf Just Nothing
176
184
@@ -181,9 +189,9 @@ foreign import _lastIndexOf
181
189
-> String
182
190
-> Maybe Int
183
191
184
- -- | Returns the index of the last occurrence of the first string in the
185
- -- | second string, starting at the given index. Returns `Nothing` if there is
186
- -- | no match.
192
+ -- | Returns the index of the last occurrence of the pattern in the
193
+ -- | given string, starting at the specified index. Returns `Nothing`
194
+ -- | if there is no match.
187
195
lastIndexOf' :: Pattern -> Int -> String -> Maybe Int
188
196
lastIndexOf' = _lastIndexOf' Just Nothing
189
197
@@ -198,7 +206,11 @@ foreign import _lastIndexOf'
198
206
-- | Returns the number of characters the string is composed of.
199
207
foreign import length :: String -> Int
200
208
201
- -- | Locale-aware sort order comparison.
209
+ -- | Compare two strings in a locale-aware fashion. This is in contrast to
210
+ -- | the `Ord` instance on `String` which treats strings as arrays of code
211
+ -- | units:
212
+ -- | - `"ä" `localeCompare` "b" == LT`
213
+ -- | - `"ä" `compare` "b" == GT`
202
214
localeCompare :: String -> String -> Ordering
203
215
localeCompare = _localeCompare LT EQ GT
204
216
@@ -210,10 +222,11 @@ foreign import _localeCompare
210
222
-> String
211
223
-> Ordering
212
224
213
- -- | Replaces the first occurence of the first argument with the second argument.
225
+ -- | Replaces the first occurence of the pattern with the replacement string.
226
+ -- | * `replace (Pattern "http") (Replacement "https") "http://purescript.org" == "https://purescript.org"`
214
227
foreign import replace :: Pattern -> Replacement -> String -> String
215
228
216
- -- | Replaces all occurences of the first argument with the second argument .
229
+ -- | Replaces all occurences of the pattern with the replacement string .
217
230
foreign import replaceAll :: Pattern -> Replacement -> String -> String
218
231
219
232
-- | Returns the first `n` characters of the string.
@@ -231,7 +244,7 @@ foreign import count :: (Char -> Boolean) -> String -> Int
231
244
-- | * `split (Pattern " ") "hello world" == ["hello", "world"]`
232
245
foreign import split :: Pattern -> String -> Array String
233
246
234
- -- | Returns the substrings of split at the given index, if the index is within bounds.
247
+ -- | Returns the substrings of a split at the given index, if the index is within bounds.
235
248
splitAt :: Int -> String -> Maybe { before :: String , after :: String }
236
249
splitAt = _splitAt Just Nothing
237
250
@@ -257,4 +270,5 @@ foreign import trim :: String -> String
257
270
258
271
-- | Joins the strings in the array together, inserting the first argument
259
272
-- | as separator between them.
273
+ -- | * `joinWith ", " ["apple", "banana", "orange"] == "apple, banana, orange"`
260
274
foreign import joinWith :: String -> Array String -> String
0 commit comments