File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,17 @@ dropWhile :: (Char -> Boolean) -> String -> String
7878
7979Returns the suffix remaining after ` takeWhile ` .
8080
81+ #### ` stripPrefix `
82+
83+ ``` purescript
84+ stripPrefix :: String -> String -> Maybe String
85+ ```
86+
87+ If the string starts with the given prefix, return the portion of the
88+ string left after removing it, as a Just value. Otherwise, return Nothing.
89+ * `stripPrefix "http:" "http://purescript.org " == Just "//purescript.org"
90+ * `stripPrefix "http:" "https://purescript.org " == Nothing
91+
8192#### ` fromCharArray `
8293
8394``` purescript
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ module Data.String
2323 , takeWhile
2424 , drop
2525 , dropWhile
26+ , stripPrefix
2627 , split
2728 , toCharArray
2829 , toLower
@@ -94,6 +95,16 @@ takeWhile p s = take (count p s) s
9495dropWhile :: (Char -> Boolean ) -> String -> String
9596dropWhile p s = drop (count p s) s
9697
98+ -- | If the string starts with the given prefix, return the portion of the
99+ -- | string left after removing it, as a Just value. Otherwise, return Nothing.
100+ -- | * `stripPrefix "http:" "http://purescript.org" == Just "//purescript.org"
101+ -- | * `stripPrefix "http:" "https://purescript.org" == Nothing
102+ stripPrefix :: String -> String -> Maybe String
103+ stripPrefix prefix str =
104+ case indexOf prefix str of
105+ Just 0 -> Just $ drop (length prefix) str
106+ _ -> Nothing
107+
97108-- | Converts an array of characters into a string.
98109foreign import fromCharArray :: Array Char -> String
99110
You can’t perform that action at this time.
0 commit comments