on master help sign in
Implement takeWhileEnd.
commit2de66fd2e25b69ed7c637afaa829db5e5999d278 authorLuigy Leon <luigy@outlook.com> dateThu 6 Oct 2016, 10:03 (10 years ago) parentfb26001
1 file changed+16−7
Data/Text.hs+16−7
Data/Text.hs+16−7
@@ -1271,13 +1271,20 @@ takeWhile = coerce JSS.takeWhile
12711271--
12721272-- > takeWhileEnd (=='o') "foo" == "oo"
12731273takeWhileEnd :: (Char -> Bool) -> Text -> Text
1274−takeWhileEnd = P.error "takeWhileEnd: not implemented."
1275−-- takeWhileEnd :: (Char -> Bool) -> Text -> Text
1276−-- takeWhileEnd p t@(Text arr off len) = loop (len-1) len
1277−-- where loop !i !l | l <= 0 = t
1278−-- | p c = loop (i+d) (l+d)
1279−-- | otherwise = text arr (off+l) (len-l)
1280−-- where (c,d) = reverseIter t i
1274+#ifndef __GHCJS__
1275+takeWhileEnd p t@(Text arr off len) = loop (len-1) len
1276+ where loop !i !l | l <= 0 = t
1277+ | p c = loop (i+d) (l+d)
1278+ | otherwise = text arr (off+l) (len-l)
1279+ where (c,d) = reverseIter t i
1280+#else
1281+takeWhileEnd p t@(Text jst) = loop (len-1) len
1282+ where loop !i !l | l <= 0 = t
1283+ | p c = loop (i+d) (l+d)
1284+ | otherwise = Text $ js_substr1 l jst
1285+ where (c,d) = reverseIter t i
1286+ len = length t
1287+#endif
12811288{-# INLINE [1] takeWhileEnd #-}
12821289
12831290{-# RULES
@@ -1903,3 +1910,5 @@ copy = P.id -- TODO
19031910
19041911foreign import javascript unsafe
19051912 "h$jsstringReplicateChar" js_replicateChar :: Int -> Char -> JSString
1913+foreign import javascript unsafe
1914+ "$2.substr($1)" js_substr1 :: Int -> JSString -> JSString