File: Unicode.hs

package info (click to toggle)
haskell-text-builder-dev 0.3.5-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 124 kB
  • sloc: haskell: 1,186; makefile: 5
file content (22 lines) | stat: -rw-r--r-- 652 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
-- |
-- Utilities for construction of Unicode codepoints.
module TextBuilderDev.Unicode where

import TextBuilderDev.Prelude

{-# INLINE utf8CodeUnits3 #-}
utf8CodeUnits3 :: Word8 -> Word8 -> Word8 -> Int
utf8CodeUnits3 byte1 byte2 byte3 =
  shiftL (fromIntegral byte1 - 0xE0) 12
    + shiftL (fromIntegral byte2 - 0x80) 6
    + fromIntegral byte3
    - 0x80

{-# INLINE utf8CodeUnits4 #-}
utf8CodeUnits4 :: Word8 -> Word8 -> Word8 -> Word8 -> Int
utf8CodeUnits4 byte1 byte2 byte3 byte4 =
  shiftL (fromIntegral byte1 - 0xF0) 18
    + shiftL (fromIntegral byte2 - 0x80) 12
    + shiftL (fromIntegral byte3 - 0x80) 6
    + fromIntegral byte4
    - 0x80