Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Data/Text/Internal/Encoding/Utf8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ utf8Length :: Char -> Int
utf8Length (C# c) = I# ((1# +# geChar# c (chr# 0x80#)) +# (geChar# c (chr# 0x800#) +# geChar# c (chr# 0x10000#)))
{-# INLINE utf8Length #-}

-- | Measure byte length of UTF-8 encoding for characters,
-- starting with a given byte.
-- | Measure byte length of UTF-8 encoding for characters
-- starting with the given leading byte.
-- Continuation bytes yield a fail-safe value of 1.
--
-- @since 2.0
Comment thread
Vekhir marked this conversation as resolved.
utf8LengthByLeader :: Word8 -> Int
utf8LengthByLeader w
| w < 0x80 = 1
| w < 0xC0 = 1
| w < 0xE0 = 2
| w < 0xF0 = 3
| otherwise = 4
Expand Down
Loading