on master help sign in
Fix another bug
a97092bBryan O'Sullivan
Data/Text.hs+11−9
@@ -658,15 +658,17 @@ words :: Text -> [Text]
658words (Text arr off len) = loop0 off off
658words (Text arr off len) = loop0 off off
659 where
659 where
660 loop0 start n
660 loop0 start n
661+ | n >= len = if start == n
662+ then []
663+ else [Text arr (start+off) (n-start)]
661− | isSpace (unsafeChr c) = if start == n
664+ | isSpace (unsafeChr c) =
665+ if start == n
662− then loop0 (start+1) (start+1)
666+ then loop0 (start+1) (start+1)
663− else (Text arr start (n-start)):loop0 (n+1) (n+1)
667+ else Text arr (start+off) (n-start) : loop0 (n+1) (n+1)
668+ | otherwise = if c < 0xD800 || c > 0xDBFF
664− | n < (off+len) = loop0 start (n+1)
669+ then loop0 start (n+1)
665− | otherwise = if start == n
666− then []
667− else [(Text arr start (n-start))]
670+ else loop0 start (n+2)
668− where
669− c = arr `A.unsafeIndex` n
671+ where c = arr `A.unsafeIndex` n
670{-# INLINE words #-}
672{-# INLINE words #-}
671
673
672-- | /O(n)/ Breaks a 'Text' up into a list of 'Text's at
674-- | /O(n)/ Breaks a 'Text' up into a list of 'Text's at