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 2020 ],
2121 "dependencies" : {
2222 "purescript-maybe" : " ^0.3.0"
23+ },
24+ "devDependencies" : {
25+ "purescript-assert" : " ~0.1.0" ,
26+ "purescript-console" : " ~0.1.0"
2327 }
2428}
Original file line number Diff line number Diff line change @@ -26,4 +26,20 @@ fromCharCode :: Int -> Char
2626
2727Constructs a character from the given Unicode numeric value.
2828
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+
2945
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
115115#### ` search `
116116
117117``` purescript
118- search :: Regex -> String -> Int
118+ search :: Regex -> String -> Maybe Int
119119```
120120
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.
123123
124124#### ` split `
125125
Original file line number Diff line number Diff line change 22 "private" : true ,
33 "scripts" : {
44 "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"
66 },
77 "devDependencies" : {
88 "jscs" : " ^1.13.1" ,
Original file line number Diff line number Diff line change @@ -14,3 +14,11 @@ exports.toCharCode = function (c) {
1414exports . fromCharCode = function ( c ) {
1515 return String . fromCharCode ( c ) ;
1616} ;
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
33 ( toString
44 , fromCharCode
55 , toCharCode
6+ , toLower
7+ , toUpper
68 ) where
79
810import Prelude
@@ -16,6 +18,12 @@ foreign import toCharCode :: Char -> Int
1618-- | Constructs a character from the given Unicode numeric value.
1719foreign import fromCharCode :: Int -> Char
1820
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+
1927-- | Characters fall within the Unicode range.
2028instance boundedChar :: Bounded Char where
2129 top = fromCharCode zero
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ exports["_indexOf'"] = function (just) {
5151 return function ( x ) {
5252 return function ( startAt ) {
5353 return function ( s ) {
54+ if ( startAt < 0 || startAt > s . length ) return nothing ;
5455 var i = s . indexOf ( x , startAt ) ;
5556 return i === - 1 ? nothing : just ( i ) ;
5657 } ;
@@ -75,6 +76,7 @@ exports["_lastIndexOf'"] = function (just) {
7576 return function ( x ) {
7677 return function ( startAt ) {
7778 return function ( s ) {
79+ if ( startAt < 0 || startAt > s . length ) return nothing ;
7880 var i = s . lastIndexOf ( x , startAt ) ;
7981 return i === - 1 ? nothing : just ( i ) ;
8082 } ;
@@ -93,7 +95,7 @@ exports._localeCompare = function (lt) {
9395 return function ( s1 ) {
9496 return function ( s2 ) {
9597 var result = s1 . localeCompare ( s2 ) ;
96- return result < 0 ? lt : result > 1 ? gt : eq ;
98+ return result < 0 ? lt : result > 0 ? gt : eq ;
9799 } ;
98100 } ;
99101 } ;
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ module Data.String
3434 ) where
3535
3636import Prelude
37- import Data.Char
37+ import qualified Data.Char as C
3838import Data.Maybe (Maybe (..), isJust )
3939import Data.Monoid (Monoid )
4040import qualified Data.String.Unsafe as U
@@ -51,7 +51,7 @@ foreign import _charAt :: (forall a. a -> Maybe a)
5151
5252-- | Returns a string of length `1` containing the given character.
5353fromChar :: Char -> String
54- fromChar = toString
54+ fromChar = C . toString
5555
5656-- | Returns a string of length `1` containing the given character.
5757-- | Same as `fromChar`.
Original file line number Diff line number Diff line change @@ -70,9 +70,14 @@ exports["replace'"] = function (r) {
7070 } ;
7171} ;
7272
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+ } ;
7681 } ;
7782} ;
7883
Original file line number Diff line number Diff line change @@ -104,9 +104,16 @@ foreign import replace :: Regex -> String -> String -> String
104104-- | See the [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter).
105105foreign import replace' :: Regex -> (String -> Array String -> String ) -> String -> String
106106
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
110117
111118-- | Split the string into an array of substrings along occurences of the `Regex`.
112119foreign import split :: Regex -> String -> Array String
You can’t perform that action at this time.
0 commit comments