Skip to content

Commit 76ddec3

Browse files
committed
Use Int everywhere, add contains, rename charString
1 parent 9d8a554 commit 76ddec3

File tree

5 files changed

+341
-332
lines changed

5 files changed

+341
-332
lines changed

README.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ For details of the underlying implementation, see [String Reference at MDN](http
7979
#### `charAt`
8080

8181
``` purescript
82-
charAt :: Number -> String -> Maybe Char
82+
charAt :: Int -> String -> Maybe Char
8383
```
8484

8585
Returns the character at the given index, if the index is within bounds.
@@ -104,7 +104,7 @@ Same as `fromChar`.
104104
#### `charCodeAt`
105105

106106
``` purescript
107-
charCodeAt :: Number -> String -> Maybe Number
107+
charCodeAt :: Int -> String -> Maybe Int
108108
```
109109

110110
Returns the numeric Unicode value of the character at the given index,
@@ -152,29 +152,37 @@ fromCharArray :: [Char] -> String
152152

153153
Converts an array of characters into a string.
154154

155+
#### `contains`
156+
157+
``` purescript
158+
contains :: String -> String -> Boolean
159+
```
160+
161+
Checks whether the first string exists in the second string.
162+
155163
#### `indexOf`
156164

157165
``` purescript
158-
indexOf :: String -> String -> Number
166+
indexOf :: String -> String -> Maybe Int
159167
```
160168

161169
Returns the index of the first occurrence of the first string in the
162-
second string. Returns `-1` if there is no match.
170+
second string. Returns `Nothing` if there is no match.
163171

164172
#### `indexOf'`
165173

166174
``` purescript
167-
indexOf' :: String -> Number -> String -> Number
175+
indexOf' :: String -> Int -> String -> Maybe Int
168176
```
169177

170178
Returns the index of the first occurrence of the first string in the
171-
second string, starting at the given index. Returns `-1` if there is
179+
second string, starting at the given index. Returns `Nothing` if there is
172180
no match.
173181

174182
#### `lastIndexOf`
175183

176184
``` purescript
177-
lastIndexOf :: String -> String -> Number
185+
lastIndexOf :: String -> String -> Maybe Int
178186
```
179187

180188
Returns the index of the last occurrence of the first string in the
@@ -183,31 +191,28 @@ second string. Returns `-1` if there is no match.
183191
#### `lastIndexOf'`
184192

185193
``` purescript
186-
lastIndexOf' :: String -> Number -> String -> Number
194+
lastIndexOf' :: String -> Int -> String -> Maybe Int
187195
```
188196

189-
Returns the index of the first occurrence of the last string in the
190-
second string, starting at the given index. Returns `-1` if there is
197+
Returns the index of the last occurrence of the first string in the
198+
second string, starting at the given index. Returns `Nothing` if there is
191199
no match.
192200

193201
#### `length`
194202

195203
``` purescript
196-
length :: String -> Number
204+
length :: String -> Int
197205
```
198206

199207
Returns the number of characters the string is composed of.
200208

201209
#### `localeCompare`
202210

203211
``` purescript
204-
localeCompare :: String -> String -> Number
212+
localeCompare :: String -> String -> Ordering
205213
```
206214

207-
Locale-aware sort order comparison. Returns a negative number if the
208-
first string occurs before the second in a sort, a positive number
209-
if the first string occurs after the second, and `0` if their sort order
210-
is equal.
215+
Locale-aware sort order comparison.
211216

212217
#### `replace`
213218

@@ -220,23 +225,23 @@ Replaces the first occurence of the first argument with the second argument.
220225
#### `take`
221226

222227
``` purescript
223-
take :: Number -> String -> String
228+
take :: Int -> String -> String
224229
```
225230

226231
Returns the first `n` characters of the string.
227232

228233
#### `drop`
229234

230235
``` purescript
231-
drop :: Number -> String -> String
236+
drop :: Int -> String -> String
232237
```
233238

234239
Returns the string without the first `n` characters.
235240

236241
#### `count`
237242

238243
``` purescript
239-
count :: (Char -> Boolean) -> String -> Number
244+
count :: (Char -> Boolean) -> String -> Int
240245
```
241246

242247
Returns the number of characters in the string for which the predicate holds.
@@ -413,7 +418,7 @@ See the [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe
413418
#### `search`
414419

415420
``` purescript
416-
search :: Regex -> String -> Number
421+
search :: Regex -> String -> Int
417422
```
418423

419424
Returns the index of the first match of the `Regex` in the string, or
@@ -436,7 +441,7 @@ Unsafe string and character functions.
436441
#### `charCodeAt`
437442

438443
``` purescript
439-
charCodeAt :: Number -> String -> Number
444+
charCodeAt :: Int -> String -> Int
440445
```
441446

442447
Returns the numeric Unicode value of the character at the given index.
@@ -446,7 +451,7 @@ Returns the numeric Unicode value of the character at the given index.
446451
#### `charAt`
447452

448453
``` purescript
449-
charAt :: Number -> String -> Char
454+
charAt :: Int -> String -> Char
450455
```
451456

452457
Returns the character at the given index.

src/Data/Char/Char.purs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import Data.Int (Int(), fromNumber)
1212
newtype Char = Char String
1313

1414
-- | Returns the string of length `1` containing only the given character.
15-
charString :: Char -> String
16-
charString (Char s) = s
15+
toString :: Char -> String
16+
toString (Char s) = s
1717

1818
-- | Returns the numeric Unicode value of the character.
1919
foreign import toCharCode
@@ -40,6 +40,7 @@ instance eqChar :: Eq Char where
4040
instance ordChar :: Ord Char where
4141
compare (Char a) (Char b) = a `compare` b
4242

43+
-- | Characters fall within the Unicode range.
4344
instance boundedChar :: Bounded Char where
4445
top = fromCharCode zero
4546
bottom = fromCharCode (fromNumber 65535)

0 commit comments

Comments
 (0)