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
@@ -1877,6 +1878,22 @@ isInfixOf needle haystack
1877
1878
| otherwise = not . L. null . indices needle $ haystack
1878
1879
{-# INLINE [1] isInfixOf #-}
1879
1880
1881
+ -- | The 'isSubsequenceOf' function takes two 'Text's and returns
1882
+ -- 'True' iff the first is a subsequence of a second.
1883
+ -- (characters of the first argument appear in same sequential order in
1884
+ -- the second, to say if first argument that can be derived by deleting some
1885
+ -- or no elements from the second).
1886
+ isSubsequenceOf :: Text -> Text -> Bool
1887
+ isSubsequenceOf sf tf
1888
+ | length sf > length tf = False
1889
+ | otherwise = subseqOf sf tf
1890
+ where
1891
+ subseqOf s t
1892
+ | null s = True
1893
+ | null t = False
1894
+ | unsafeHead s == unsafeHead t = subseqOf (unsafeTail s) (unsafeTail t)
1895
+ | otherwise = subseqOf s $ unsafeTail t
1896
+
1880
1897
-------------------------------------------------------------------------------
1881
1898
-- * View patterns
1882
1899
You can’t perform that action at this time.
0 commit comments