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
78
78
79
79
Returns the suffix remaining after ` takeWhile ` .
80
80
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
+
81
92
#### ` fromCharArray `
82
93
83
94
``` purescript
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ module Data.String
23
23
, takeWhile
24
24
, drop
25
25
, dropWhile
26
+ , stripPrefix
26
27
, split
27
28
, toCharArray
28
29
, toLower
@@ -94,6 +95,16 @@ takeWhile p s = take (count p s) s
94
95
dropWhile :: (Char -> Boolean ) -> String -> String
95
96
dropWhile p s = drop (count p s) s
96
97
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
+
97
108
-- | Converts an array of characters into a string.
98
109
foreign import fromCharArray :: Array Char -> String
99
110
You can’t perform that action at this time.
0 commit comments