    -- |
    -- Utilities for construction of Unicode codepoints.
    module TextBuilderCore.Utf16View.Unicode where

    import TextBuilderCore.Prelude

    {-# INLINE utf8CodeUnits3 #-}
    utf8CodeUnits3 :: Word8 -> Word8 -> Word8 -> Int
    utf8CodeUnits3 :: Word8 -> Word8 -> Word8 -> Int
    utf8CodeUnits3 Word8
    byte1 Word8
    byte2 Word8
    byte3 =
      Int -> Int -> Int
    forall a. Bits a => a -> Int -> a
    shiftL (Word8 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word8
    byte1 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    0xE0) Int
    12
        Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int -> Int -> Int
    forall a. Bits a => a -> Int -> a
    shiftL (Word8 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word8
    byte2 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    0x80) Int
    6
        Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Word8 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word8
    byte3
        Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    0x80

    {-# INLINE utf8CodeUnits4 #-}
    utf8CodeUnits4 :: Word8 -> Word8 -> Word8 -> Word8 -> Int
    utf8CodeUnits4 :: Word8 -> Word8 -> Word8 -> Word8 -> Int
    utf8CodeUnits4 Word8
    byte1 Word8
    byte2 Word8
    byte3 Word8
    byte4 =
      Int -> Int -> Int
    forall a. Bits a => a -> Int -> a
    shiftL (Word8 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word8
    byte1 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    0xF0) Int
    18
        Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int -> Int -> Int
    forall a. Bits a => a -> Int -> a
    shiftL (Word8 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word8
    byte2 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    0x80) Int
    12
        Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int -> Int -> Int
    forall a. Bits a => a -> Int -> a
    shiftL (Word8 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word8
    byte3 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    0x80) Int
    6
        Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Word8 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word8
    byte4
        Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    0x80