File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -116,3 +116,15 @@ exports.splitAt = function (i) {
116116 return { before : s . substring ( 0 , i ) , after : s . substring ( i ) } ;
117117 } ;
118118} ;
119+
120+ exports . startsWith = function ( pattern ) {
121+ return function ( s ) {
122+ return s . startsWith ( pattern ) ;
123+ }
124+ }
125+
126+ exports . endsWith = function ( pattern ) {
127+ return function ( s ) {
128+ return s . endsWith ( pattern ) ;
129+ }
130+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ module Data.String.CodeUnits
2222 , dropWhile
2323 , slice
2424 , splitAt
25+ , startsWith
26+ , endsWith
2527 ) where
2628
2729import Prelude
@@ -343,3 +345,19 @@ foreign import _slice :: Int -> Int -> String -> String
343345-- | splitAt i s == {before: take i s, after: drop i s}
344346-- | ```
345347foreign import splitAt :: Int -> String -> { before :: String , after :: String }
348+
349+ -- | Checks whether the given string starts with the pattern.
350+ -- |
351+ -- | ```purescript
352+ -- | startsWith (Pattern "foo") "foobar" == true
353+ -- | startsWith (Pattern "bar") "foobar" == false
354+ -- | ```
355+ foreign import startsWith :: Pattern -> String -> Boolean
356+
357+ -- | Checks whether the given string ends with the pattern.
358+ -- |
359+ -- | ```purescript
360+ -- | endsWith (Pattern "bar") "foobar" == true
361+ -- | endsWith (Pattern "foo") "foobar" == false
362+ -- | ```
363+ foreign import endsWith :: Pattern -> String -> Boolean
Original file line number Diff line number Diff line change @@ -510,3 +510,17 @@ testStringCodeUnits = do
510510 { actual: SCU .slice 3 1000 " purescript"
511511 , expected: Nothing -- e > l
512512 }
513+
514+ log " startsWith"
515+ assert $ SCU .startsWith (Pattern " foo" ) " foobar"
516+ assert $ SCU .startsWith (Pattern " foo" ) " foo"
517+ assert $ SCU .startsWith (Pattern " " ) " "
518+ assert $ SCU .startsWith (Pattern " " ) " foo"
519+ assert $ not $ SCU .startsWith (Pattern " foo" ) " "
520+
521+ log " endsWith"
522+ assert $ SCU .endsWith (Pattern " bar" ) " foobar"
523+ assert $ SCU .endsWith (Pattern " bar" ) " bar"
524+ assert $ SCU .endsWith (Pattern " " ) " "
525+ assert $ SCU .endsWith (Pattern " " ) " bar"
526+ assert $ not $ SCU .endsWith (Pattern " bar" ) " "
You can’t perform that action at this time.
0 commit comments