File tree Expand file tree Collapse file tree 15 files changed +305
-23
lines changed Expand file tree Collapse file tree 15 files changed +305
-23
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,18 +26,18 @@ fromCharCode :: Int -> Char
2626
2727Constructs a character from the given Unicode numeric value.
2828
29- #### ` toLowerChar `
29+ #### ` toLower `
3030
3131``` purescript
32- toLowerChar :: Char -> Char
32+ toLower :: Char -> Char
3333```
3434
3535Converts a character to lowercase.
3636
37- #### ` toUpperChar `
37+ #### ` toUpper `
3838
3939``` purescript
40- toUpperChar :: Char -> Char
40+ toUpper :: Char -> Char
4141```
4242
4343Converts a character to uppercase.
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 @@ -15,10 +15,10 @@ exports.fromCharCode = function (c) {
1515 return String . fromCharCode ( c ) ;
1616} ;
1717
18- exports . toLowerChar = function ( c ) {
18+ exports . toLower = function ( c ) {
1919 return c . toLowerCase ( ) ;
2020} ;
2121
22- exports . toUpperChar = function ( c ) {
22+ exports . toUpper = function ( c ) {
2323 return c . toUpperCase ( ) ;
2424} ;
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ module Data.Char
33 ( toString
44 , fromCharCode
55 , toCharCode
6- , toLowerChar
7- , toUpperChar
6+ , toLower
7+ , toUpper
88 ) where
99
1010import Prelude
@@ -19,10 +19,10 @@ foreign import toCharCode :: Char -> Int
1919foreign import fromCharCode :: Int -> Char
2020
2121-- | Converts a character to lowercase.
22- foreign import toLowerChar :: Char -> Char
22+ foreign import toLower :: Char -> Char
2323
2424-- | Converts a character to uppercase.
25- foreign import toUpperChar :: Char -> Char
25+ foreign import toUpper :: Char -> Char
2626
2727-- | Characters fall within the Unicode range.
2828instance boundedChar :: Bounded Char where
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 @@ -33,7 +33,7 @@ module Data.String
3333 ) where
3434
3535import Prelude
36- import Data.Char
36+ import qualified Data.Char as C
3737import Data.Maybe (Maybe (..), isJust )
3838import Data.Monoid (Monoid )
3939import qualified Data.String.Unsafe as U
@@ -50,7 +50,7 @@ foreign import _charAt :: (forall a. a -> Maybe a)
5050
5151-- | Returns a string of length `1` containing the given character.
5252fromChar :: Char -> String
53- fromChar = toString
53+ fromChar = C . toString
5454
5555-- | Returns a string of length `1` containing the given character.
5656-- | 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