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
11 changes: 11 additions & 0 deletions docs/Data/String.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ dropWhile :: (Char -> Boolean) -> String -> String

Returns the suffix remaining after `takeWhile`.

#### `stripPrefix`

``` purescript
stripPrefix :: String -> String -> Maybe String
```

If the string starts with the given prefix, return the portion of the
string left after removing it, as a Just value. Otherwise, return Nothing.
* `stripPrefix "http:" "http://purescript.org" == Just "//purescript.org"
* `stripPrefix "http:" "https://purescript.org" == Nothing

#### `fromCharArray`

``` purescript
Expand Down
11 changes: 11 additions & 0 deletions src/Data/String.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Data.String
, takeWhile
, drop
, dropWhile
, stripPrefix
, split
, toCharArray
, toLower
Expand Down Expand Up @@ -94,6 +95,16 @@ takeWhile p s = take (count p s) s
dropWhile :: (Char -> Boolean) -> String -> String
dropWhile p s = drop (count p s) s

-- | If the string starts with the given prefix, return the portion of the
-- | string left after removing it, as a Just value. Otherwise, return Nothing.
-- | * `stripPrefix "http:" "http://purescript.org" == Just "//purescript.org"
-- | * `stripPrefix "http:" "https://purescript.org" == Nothing
stripPrefix :: String -> String -> Maybe String
stripPrefix prefix str =
case indexOf prefix str of
Just 0 -> Just $ drop (length prefix) str
_ -> Nothing

-- | Converts an array of characters into a string.
foreign import fromCharArray :: Array Char -> String

Expand Down