@@ -658,15 +658,17 @@ words :: Text -> [Text]
658658words (Text arr off len) = loop0 off off
659659 where
660660 loop0 start n
661− | isSpace (unsafeChr c) = if start == n
662− then loop0 (start+1) (start+1)
663− else (Text arr start (n-start)):loop0 (n+1) (n+1)
664− | n < (off+len) = loop0 start (n+1)
665− | otherwise = if start == n
666− then []
667− else [(Text arr start (n-start))]
668− where
669− c = arr `A.unsafeIndex` n
661+ | n >= len = if start == n
662+ then []
663+ else [Text arr (start+off) (n-start)]
664+ | isSpace (unsafeChr c) =
665+ if start == n
666+ then loop0 (start+1) (start+1)
667+ else Text arr (start+off) (n-start) : loop0 (n+1) (n+1)
668+ | otherwise = if c < 0xD800 || c > 0xDBFF
669+ then loop0 start (n+1)
670+ else loop0 start (n+2)
671+ where c = arr `A.unsafeIndex` n
670672{-# INLINE words #-}
671673
672674-- | /O(n)/ Breaks a 'Text' up into a list of 'Text's at