on master help sign in
Implement takeWhileEnd.
2de66fdLuigy Leon
Data/Text.hs+16−7
@@ -1271,13 +1271,20 @@ takeWhile = coerce JSS.takeWhile
1271--
1271--
1272-- > takeWhileEnd (=='o') "foo" == "oo"
1272-- > takeWhileEnd (=='o') "foo" == "oo"
1273takeWhileEnd :: (Char -> Bool) -> Text -> Text
1273takeWhileEnd :: (Char -> Bool) -> Text -> Text
1274−takeWhileEnd = P.error "takeWhileEnd: not implemented."
1274+#ifndef __GHCJS__
1275−-- takeWhileEnd :: (Char -> Bool) -> Text -> Text
1276−-- takeWhileEnd p t@(Text arr off len) = loop (len-1) len
1275+takeWhileEnd p t@(Text arr off len) = loop (len-1) len
1277−-- where loop !i !l | l <= 0 = t
1276+ where loop !i !l | l <= 0 = t
1278−-- | p c = loop (i+d) (l+d)
1277+ | p c = loop (i+d) (l+d)
1279−-- | otherwise = text arr (off+l) (len-l)
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
1280−-- where (c,d) = reverseIter t i
1285+ where (c,d) = reverseIter t i
1286+ len = length t
1287+#endif
1281{-# INLINE [1] takeWhileEnd #-}
1288{-# INLINE [1] takeWhileEnd #-}
1282
1289
1283{-# RULES
1290{-# RULES
@@ -1903,3 +1910,5 @@ copy = P.id -- TODO
1903
1910
1904foreign import javascript unsafe
1911foreign import javascript unsafe
1905 "h$jsstringReplicateChar" js_replicateChar :: Int -> Char -> JSString
1912 "h$jsstringReplicateChar" js_replicateChar :: Int -> Char -> JSString
1913+foreign import javascript unsafe
1914+ "$2.substr($1)" js_substr1 :: Int -> JSString -> JSString