File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,7 @@ module Data.Text
167
167
, isPrefixOf
168
168
, isSuffixOf
169
169
, isInfixOf
170
+ , isSubsequenceOf
170
171
171
172
-- ** View patterns
172
173
, stripPrefix
@@ -1881,6 +1882,22 @@ isInfixOf needle haystack
1881
1882
| otherwise = not . L. null . indices needle $ haystack
1882
1883
{-# INLINE [1] isInfixOf #-}
1883
1884
1885
+ -- | The 'isSubsequenceOf' function takes two 'Text's and returns
1886
+ -- 'True' iff the first is a subsequence of a second.
1887
+ -- (characters of the first argument appear in same sequential order in
1888
+ -- the second, to say if first argument that can be derived by deleting some
1889
+ -- or no elements from the second).
1890
+ isSubsequenceOf :: Text -> Text -> Bool
1891
+ isSubsequenceOf sf tf
1892
+ | length sf > length tf = False
1893
+ | otherwise = subseqOf sf tf
1894
+ where
1895
+ subseqOf s t
1896
+ | null s = True
1897
+ | null t = False
1898
+ | unsafeHead s == unsafeHead t = subseqOf (unsafeTail s) (unsafeTail t)
1899
+ | otherwise = subseqOf s $ unsafeTail t
1900
+
1884
1901
-------------------------------------------------------------------------------
1885
1902
-- * View patterns
1886
1903
You can’t perform that action at this time.
0 commit comments