Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@

charCodeAt :: Number -> String -> Maybe Number

count :: (Char -> Boolean) -> String -> Number

drop :: Number -> String -> String

dropWhile :: (Char -> Boolean) -> String -> String

fromChar :: Char -> String

fromCharArray :: [Char] -> String
Expand All @@ -53,12 +57,18 @@

localeCompare :: String -> String -> Number

null :: String -> Boolean

replace :: String -> String -> String -> String

singleton :: Char -> String

split :: String -> String -> [String]

take :: Number -> String -> String

takeWhile :: (Char -> Boolean) -> String -> String

toCharArray :: String -> [Char]

toLower :: String -> String
Expand All @@ -67,14 +77,16 @@

trim :: String -> String

uncons :: String -> Maybe { tail :: String, head :: Char }


## Module Data.String.Regex

### Types

data Regex :: *

type RegexFlags = { unicode :: Boolean, sticky :: Boolean, multiline :: Boolean, ignoreCase :: Boolean, global :: Boolean }
type RegexFlags = { unicode :: Boolean, sticky :: Boolean, multiline :: Boolean, ignoreCase :: Boolean, global :: Boolean }


### Type Class Instances
Expand Down
34 changes: 34 additions & 0 deletions src/Data/String.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ module Data.String
indexOf',
lastIndexOf,
lastIndexOf',
null,
uncons,
length,
singleton,
localeCompare,
replace,
count,
take,
takeWhile,
drop,
dropWhile,
split,
toCharArray,
toLower,
Expand All @@ -24,6 +30,7 @@ module Data.String
import Data.Maybe
import Data.Char
import Data.Function
import qualified Data.String.Unsafe as U

foreign import _charAt
"""
Expand All @@ -38,6 +45,9 @@ module Data.String
fromChar :: Char -> String
fromChar = charString

singleton :: Char -> String
singleton = fromChar

foreign import _charCodeAt
"""
function _charCodeAt(i, s, Just, Nothing) {
Expand All @@ -48,6 +58,19 @@ module Data.String
charCodeAt :: Number -> String -> Maybe Number
charCodeAt n s = runFn4 _charCodeAt n s Just Nothing

null :: String -> Boolean
null s = length s == 0

uncons :: String -> Maybe {head :: Char, tail :: String}
uncons s | null s = Nothing
uncons s = Just {head : U.charAt 0 s, tail : drop 1 s}

takeWhile :: (Char -> Boolean) -> String -> String
takeWhile p s = take (count p s) s

dropWhile :: (Char -> Boolean) -> String -> String
dropWhile p s = drop (count p s) s

foreign import fromCharArray
"""
function fromCharArray(a) {
Expand Down Expand Up @@ -140,6 +163,17 @@ module Data.String
}
""" :: Number -> String -> String

foreign import count
"""
function count(p){
return function(s){
var i;
for(i = 0; i < s.length && p(s.charAt(i)); i++){};
return i;
};
}
""" :: (Char -> Boolean) -> String -> Number

foreign import split
"""
function split(sep) {
Expand Down