File tree Expand file tree Collapse file tree 15 files changed +327
-13
lines changed Expand file tree Collapse file tree 15 files changed +327
-13
lines changed Original file line number Diff line number Diff line change 20
20
],
21
21
"dependencies" : {
22
22
"purescript-maybe" : " ^0.3.0"
23
+ },
24
+ "devDependencies" : {
25
+ "purescript-assert" : " ~0.1.0" ,
26
+ "purescript-console" : " ~0.1.0"
23
27
}
24
28
}
Original file line number Diff line number Diff line change @@ -26,4 +26,20 @@ fromCharCode :: Int -> Char
26
26
27
27
Constructs a character from the given Unicode numeric value.
28
28
29
+ #### ` toLower `
30
+
31
+ ``` purescript
32
+ toLower :: Char -> Char
33
+ ```
34
+
35
+ Converts a character to lowercase.
36
+
37
+ #### ` toUpper `
38
+
39
+ ``` purescript
40
+ toUpper :: Char -> Char
41
+ ```
42
+
43
+ Converts a character to uppercase.
44
+
29
45
Original file line number Diff line number Diff line change @@ -115,11 +115,11 @@ See the [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe
115
115
#### ` search `
116
116
117
117
``` purescript
118
- search :: Regex -> String -> Int
118
+ search :: Regex -> String -> Maybe Int
119
119
```
120
120
121
- Returns the index of the first match of the ` Regex ` in the string, or
122
- ` -1 ` if there is no match.
121
+ Returns ` Just ` the index of the first match of the ` Regex ` in the string,
122
+ or ` Nothing ` if there is no match.
123
123
124
124
#### ` split `
125
125
Original file line number Diff line number Diff line change 2
2
"private" : true ,
3
3
"scripts" : {
4
4
"postinstall" : " pulp dep install" ,
5
- "build" : " jshint src && jscs src && pulp build && rimraf docs && pulp docs"
5
+ "build" : " jshint src && jscs src && pulp build && pulp test && rimraf docs && pulp docs"
6
6
},
7
7
"devDependencies" : {
8
8
"jscs" : " ^1.13.1" ,
Original file line number Diff line number Diff line change @@ -14,3 +14,11 @@ exports.toCharCode = function (c) {
14
14
exports . fromCharCode = function ( c ) {
15
15
return String . fromCharCode ( c ) ;
16
16
} ;
17
+
18
+ exports . toLower = function ( c ) {
19
+ return c . toLowerCase ( ) ;
20
+ } ;
21
+
22
+ exports . toUpper = function ( c ) {
23
+ return c . toUpperCase ( ) ;
24
+ } ;
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ module Data.Char
3
3
( toString
4
4
, fromCharCode
5
5
, toCharCode
6
+ , toLower
7
+ , toUpper
6
8
) where
7
9
8
10
import Prelude
@@ -16,6 +18,12 @@ foreign import toCharCode :: Char -> Int
16
18
-- | Constructs a character from the given Unicode numeric value.
17
19
foreign import fromCharCode :: Int -> Char
18
20
21
+ -- | Converts a character to lowercase.
22
+ foreign import toLower :: Char -> Char
23
+
24
+ -- | Converts a character to uppercase.
25
+ foreign import toUpper :: Char -> Char
26
+
19
27
-- | Characters fall within the Unicode range.
20
28
instance boundedChar :: Bounded Char where
21
29
top = fromCharCode zero
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ exports["_indexOf'"] = function (just) {
51
51
return function ( x ) {
52
52
return function ( startAt ) {
53
53
return function ( s ) {
54
+ if ( startAt < 0 || startAt > s . length ) return nothing ;
54
55
var i = s . indexOf ( x , startAt ) ;
55
56
return i === - 1 ? nothing : just ( i ) ;
56
57
} ;
@@ -75,6 +76,7 @@ exports["_lastIndexOf'"] = function (just) {
75
76
return function ( x ) {
76
77
return function ( startAt ) {
77
78
return function ( s ) {
79
+ if ( startAt < 0 || startAt > s . length ) return nothing ;
78
80
var i = s . lastIndexOf ( x , startAt ) ;
79
81
return i === - 1 ? nothing : just ( i ) ;
80
82
} ;
@@ -93,7 +95,7 @@ exports._localeCompare = function (lt) {
93
95
return function ( s1 ) {
94
96
return function ( s2 ) {
95
97
var result = s1 . localeCompare ( s2 ) ;
96
- return result < 0 ? lt : result > 1 ? gt : eq ;
98
+ return result < 0 ? lt : result > 0 ? gt : eq ;
97
99
} ;
98
100
} ;
99
101
} ;
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ module Data.String
34
34
) where
35
35
36
36
import Prelude
37
- import Data.Char
37
+ import qualified Data.Char as C
38
38
import Data.Maybe (Maybe (..), isJust )
39
39
import Data.Monoid (Monoid )
40
40
import qualified Data.String.Unsafe as U
@@ -51,7 +51,7 @@ foreign import _charAt :: (forall a. a -> Maybe a)
51
51
52
52
-- | Returns a string of length `1` containing the given character.
53
53
fromChar :: Char -> String
54
- fromChar = toString
54
+ fromChar = C . toString
55
55
56
56
-- | Returns a string of length `1` containing the given character.
57
57
-- | Same as `fromChar`.
Original file line number Diff line number Diff line change @@ -70,9 +70,14 @@ exports["replace'"] = function (r) {
70
70
} ;
71
71
} ;
72
72
73
- exports . search = function ( r ) {
74
- return function ( s ) {
75
- return s . search ( r ) ;
73
+ exports . _search = function ( just ) {
74
+ return function ( nothing ) {
75
+ return function ( r ) {
76
+ return function ( s ) {
77
+ var result = s . search ( r ) ;
78
+ return result === - 1 ? nothing : just ( result ) ;
79
+ } ;
80
+ } ;
76
81
} ;
77
82
} ;
78
83
Original file line number Diff line number Diff line change @@ -104,9 +104,16 @@ foreign import replace :: Regex -> String -> String -> String
104
104
-- | See the [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter).
105
105
foreign import replace' :: Regex -> (String -> Array String -> String ) -> String -> String
106
106
107
- -- | Returns the index of the first match of the `Regex` in the string, or
108
- -- | `-1` if there is no match.
109
- foreign import search :: Regex -> String -> Int
107
+ foreign import _search :: (forall r . r -> Maybe r )
108
+ -> (forall r . Maybe r )
109
+ -> Regex
110
+ -> String
111
+ -> Maybe Int
112
+
113
+ -- | Returns `Just` the index of the first match of the `Regex` in the string,
114
+ -- | or `Nothing` if there is no match.
115
+ search :: Regex -> String -> Maybe Int
116
+ search = _search Just Nothing
110
117
111
118
-- | Split the string into an array of substrings along occurences of the `Regex`.
112
119
foreign import split :: Regex -> String -> Array String
You can’t perform that action at this time.
0 commit comments