{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UnboxedSums #-}
{-# LANGUAGE UnboxedTuples #-}

-- | This module treats 'Bytes' data as holding text encoded in ISO-8859-1. This
-- encoding can only encode codepoints strictly below @U+0100@, but this allows
-- each codepoint to be placed directly into a single byte. This range consists
-- of Unicode Basic Latin, Latin-1 Supplement and C0+C1 Controls, which includes
-- ASCII.
--
-- Strictly, ISO-8859-1 is not to be confused with ISO/IEC 8859-1 (which was the
-- default encoding for webpages before HTML5). ISO/IEC 8859-1 lacks encodings
-- for the C0 and C1 control characters. 
-- 
-- With HTML5, the default encoding of webpages was changed to Windows-1252,
-- which is _not_ compatible with ISO-8859-1. Windows-1252 uses the C1 Control
-- range (@U+0080@ -- @U+009F@) mostly to encode a variety of printable
-- characters. For this encoding, see 'Data.Bytes.Text.Windows1252'.
module Data.Bytes.Text.Latin1
  ( toString
  , fromString
  , decodeDecWord
  -- * Specialized Comparisons
  , equals1
  , equals2
  , equals3
  , equals4
  , equals5
  , equals6
  , equals7
  , equals8
  , equals9
  , equals10
  , equals11
  , equals12
  , equals13
  , equals14
  , equals15
  ) where

import Prelude hiding (length)

import Data.Bytes.Types (Bytes(..))
import Data.Char (ord,chr)
import Data.Primitive (ByteArray(ByteArray))
import Data.Word (Word8)
import GHC.Exts (Int(I#),Char(C#),or#,ltWord#,int2Word#)
import GHC.Exts (Word(W#),Word#)

import qualified Data.Primitive as PM
import qualified Data.Bytes.Pure as Bytes
import qualified GHC.Exts as Exts


-- | Convert a 'String' consisting of only characters representable
-- by ISO-8859-1. These are encoded with ISO-8859-1. Any character
-- with a codepoint above @U+00FF@ is replaced by an unspecified byte.
fromString :: String -> Bytes
fromString :: String -> Bytes
fromString =
  ByteArray -> Bytes
Bytes.fromByteArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l. IsList l => [Item l] -> l
Exts.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Int @Word8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord)

-- | Interpret a byte sequence as text encoded by ISO-8859-1.
toString :: Bytes -> String
{-# INLINE toString #-}
toString :: Bytes -> String
toString = forall a. (Word8 -> a -> a) -> a -> Bytes -> a
Bytes.foldr (\Word8
w String
xs -> Int -> Char
chr (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word8 @Int Word8
w) forall a. a -> [a] -> [a]
: String
xs) []

-- TODO presumably also fromText and fromShortText


-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a singleton whose element matches the character?
equals1 :: Char -> Bytes -> Bool
{-# INLINE equals1 #-}
equals1 :: Char -> Bytes -> Bool
equals1 !Char
c0 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
1 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a doubleton whose elements match the characters?
equals2 :: Char -> Char -> Bytes -> Bool
equals2 :: Char -> Char -> Bytes -> Bool
equals2 !Char
c0 !Char
c1 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
2 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
       Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1)
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a tripleton whose elements match the characters?
equals3 :: Char -> Char -> Char -> Bytes -> Bool
equals3 :: Char -> Char -> Char -> Bytes -> Bool
equals3 !Char
c0 !Char
c1 !Char
c2 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
3 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
       Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
       Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2)
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a quadrupleton whose elements match the characters?
equals4 :: Char -> Char -> Char -> Char -> Bytes -> Bool
equals4 :: Char -> Char -> Char -> Char -> Bytes -> Bool
equals4 !Char
c0 !Char
c1 !Char
c2 !Char
c3 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
4 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
       Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
       Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
       Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3)
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a quintupleton whose elements match the characters?
equals5 :: Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals5 :: Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals5 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
5 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
       Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
       Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
       Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
       Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4)
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a sextupleton whose elements match the characters?
equals6 :: Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals6 :: Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals6 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 !Char
c5 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
6 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
       Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
       Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
       Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
       Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4) Bool -> Bool -> Bool
&&
       Char
c5 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
5)
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a septupleton whose elements match the characters?
equals7 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals7 :: Char
-> Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals7 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 !Char
c5 !Char
c6 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
7 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
       Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
       Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
       Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
       Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4) Bool -> Bool -> Bool
&&
       Char
c5 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
5) Bool -> Bool -> Bool
&&
       Char
c6 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
6)
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- an octupleton whose elements match the characters?
equals8 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals8 :: Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Bytes
-> Bool
equals8 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 !Char
c5 !Char
c6 !Char
c7 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
8 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
       Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
       Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
       Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
       Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4) Bool -> Bool -> Bool
&&
       Char
c5 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
5) Bool -> Bool -> Bool
&&
       Char
c6 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
6) Bool -> Bool -> Bool
&&
       Char
c7 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
7)
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a 9-tuple whose elements match the characters?
equals9 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals9 :: Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Bytes
-> Bool
equals9 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 !Char
c5 !Char
c6 !Char
c7 !Char
c8 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
9 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
       Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
       Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
       Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
       Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4) Bool -> Bool -> Bool
&&
       Char
c5 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
5) Bool -> Bool -> Bool
&&
       Char
c6 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
6) Bool -> Bool -> Bool
&&
       Char
c7 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
7) Bool -> Bool -> Bool
&&
       Char
c8 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
8)
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a 10-tuple whose elements match the characters?
equals10 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals10 :: Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Bytes
-> Bool
equals10 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 !Char
c5 !Char
c6 !Char
c7 !Char
c8 !Char
c9 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
10 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
        Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
        Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
        Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
        Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4) Bool -> Bool -> Bool
&&
        Char
c5 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
5) Bool -> Bool -> Bool
&&
        Char
c6 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
6) Bool -> Bool -> Bool
&&
        Char
c7 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
7) Bool -> Bool -> Bool
&&
        Char
c8 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
8) Bool -> Bool -> Bool
&&
        Char
c9 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
9)
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a 11-tuple whose elements match the characters?
equals11 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals11 :: Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Bytes
-> Bool
equals11 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 !Char
c5 !Char
c6 !Char
c7 !Char
c8 !Char
c9 !Char
c10 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
11 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
        Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
        Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
        Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
        Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4) Bool -> Bool -> Bool
&&
        Char
c5 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
5) Bool -> Bool -> Bool
&&
        Char
c6 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
6) Bool -> Bool -> Bool
&&
        Char
c7 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
7) Bool -> Bool -> Bool
&&
        Char
c8 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
8) Bool -> Bool -> Bool
&&
        Char
c9 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
9) Bool -> Bool -> Bool
&&
        Char
c10 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
10)
  Int
_ -> Bool
False

-- | Is the byte sequence, when interpreted as ISO-8859-1-encoded text,
-- a 12-tuple whose elements match the characters?
equals12 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals12 :: Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Bytes
-> Bool
equals12 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 !Char
c5 !Char
c6 !Char
c7 !Char
c8 !Char
c9 !Char
c10 !Char
c11 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
12 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
        Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
        Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
        Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
        Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4) Bool -> Bool -> Bool
&&
        Char
c5 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
5) Bool -> Bool -> Bool
&&
        Char
c6 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
6) Bool -> Bool -> Bool
&&
        Char
c7 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
7) Bool -> Bool -> Bool
&&
        Char
c8 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
8) Bool -> Bool -> Bool
&&
        Char
c9 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
9) Bool -> Bool -> Bool
&&
        Char
c10 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
10) Bool -> Bool -> Bool
&&
        Char
c11 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
11)
  Int
_ -> Bool
False

equals13 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals13 :: Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Bytes
-> Bool
equals13 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 !Char
c5 !Char
c6 !Char
c7 !Char
c8 !Char
c9 !Char
c10 !Char
c11 !Char
c12 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
13 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
        Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
        Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
        Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
        Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4) Bool -> Bool -> Bool
&&
        Char
c5 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
5) Bool -> Bool -> Bool
&&
        Char
c6 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
6) Bool -> Bool -> Bool
&&
        Char
c7 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
7) Bool -> Bool -> Bool
&&
        Char
c8 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
8) Bool -> Bool -> Bool
&&
        Char
c9 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
9) Bool -> Bool -> Bool
&&
        Char
c10 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
10) Bool -> Bool -> Bool
&&
        Char
c11 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
11) Bool -> Bool -> Bool
&&
        Char
c12 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
12)
  Int
_ -> Bool
False

equals14 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals14 :: Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Bytes
-> Bool
equals14 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 !Char
c5 !Char
c6 !Char
c7 !Char
c8 !Char
c9 !Char
c10 !Char
c11 !Char
c12 !Char
c13 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
14 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
        Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
        Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
        Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
        Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4) Bool -> Bool -> Bool
&&
        Char
c5 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
5) Bool -> Bool -> Bool
&&
        Char
c6 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
6) Bool -> Bool -> Bool
&&
        Char
c7 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
7) Bool -> Bool -> Bool
&&
        Char
c8 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
8) Bool -> Bool -> Bool
&&
        Char
c9 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
9) Bool -> Bool -> Bool
&&
        Char
c10 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
10) Bool -> Bool -> Bool
&&
        Char
c11 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
11) Bool -> Bool -> Bool
&&
        Char
c12 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
12) Bool -> Bool -> Bool
&&
        Char
c13 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
13)
  Int
_ -> Bool
False

equals15 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Bytes -> Bool
equals15 :: Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Bytes
-> Bool
equals15 !Char
c0 !Char
c1 !Char
c2 !Char
c3 !Char
c4 !Char
c5 !Char
c6 !Char
c7 !Char
c8 !Char
c9 !Char
c10 !Char
c11 !Char
c12 !Char
c13 !Char
c14 (Bytes ByteArray
arr Int
off Int
len) = case Int
len of
  Int
15 -> Char
c0 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr Int
off Bool -> Bool -> Bool
&&
        Char
c1 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
1) Bool -> Bool -> Bool
&&
        Char
c2 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
2) Bool -> Bool -> Bool
&&
        Char
c3 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
3) Bool -> Bool -> Bool
&&
        Char
c4 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
4) Bool -> Bool -> Bool
&&
        Char
c5 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
5) Bool -> Bool -> Bool
&&
        Char
c6 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
6) Bool -> Bool -> Bool
&&
        Char
c7 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
7) Bool -> Bool -> Bool
&&
        Char
c8 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
8) Bool -> Bool -> Bool
&&
        Char
c9 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
9) Bool -> Bool -> Bool
&&
        Char
c10 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
10) Bool -> Bool -> Bool
&&
        Char
c11 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
11) Bool -> Bool -> Bool
&&
        Char
c12 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
12) Bool -> Bool -> Bool
&&
        Char
c13 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
13) Bool -> Bool -> Bool
&&
        Char
c14 forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Char
indexCharArray ByteArray
arr (Int
off forall a. Num a => a -> a -> a
+ Int
14)
  Int
_ -> Bool
False

indexCharArray :: ByteArray -> Int -> Char
indexCharArray :: ByteArray -> Int -> Char
indexCharArray (ByteArray ByteArray#
arr) (I# Int#
off) = Char# -> Char
C# (ByteArray# -> Int# -> Char#
Exts.indexCharArray# ByteArray#
arr Int#
off)

-- | Decode machine-sized word from decimal representation. Returns
-- Nothing on overflow. Allows any number of leading zeros. Trailing
-- non-digit bytes cause Nothing to be returned.
decodeDecWord :: Bytes -> Maybe Word
{-# inline decodeDecWord #-}
decodeDecWord :: Bytes -> Maybe Word
decodeDecWord !Bytes
b = case Bytes -> (# (# #) | Word# #)
decWordStart Bytes
b of
  (# (# #) | #) -> forall a. Maybe a
Nothing
  (# | Word#
w #) -> forall a. a -> Maybe a
Just (Word# -> Word
W# Word#
w)

decWordStart ::
     Bytes -- Chunk
  -> (# (# #) | Word# #)
{-# noinline decWordStart #-}
decWordStart :: Bytes -> (# (# #) | Word# #)
decWordStart !Bytes
chunk0 = if Bytes -> Int
length Bytes
chunk0 forall a. Ord a => a -> a -> Bool
> Int
0
  then
    let !w :: Word
w = forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word8 @Word
          (forall a. Prim a => ByteArray -> Int -> a
PM.indexByteArray (Bytes -> ByteArray
array Bytes
chunk0) (Bytes -> Int
offset Bytes
chunk0)) forall a. Num a => a -> a -> a
- Word
48
     in if Word
w forall a. Ord a => a -> a -> Bool
< Word
10
          then Word -> Bytes -> (# (# #) | Word# #)
decWordMore Word
w (Int -> Bytes -> Bytes
Bytes.unsafeDrop Int
1 Bytes
chunk0)
          else (# (# #) | #)
  else (# (# #) | #)
  where
  decWordMore ::
       Word -- Accumulator
    -> Bytes -- Chunk
    -> (# (# #) | Word# #)
  decWordMore :: Word -> Bytes -> (# (# #) | Word# #)
decWordMore !Word
acc !Bytes
chunk = let len :: Int
len = Bytes -> Int
length Bytes
chunk in case Int
len of
    Int
0 -> (# | Word -> Word#
unW (forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
acc) #)
    Int
_ ->
      let !w :: Word
w = forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word8 @Word
            (forall a. Prim a => ByteArray -> Int -> a
PM.indexByteArray (Bytes -> ByteArray
array Bytes
chunk) (Bytes -> Int
offset Bytes
chunk)) forall a. Num a => a -> a -> a
- Word
48
       in if Word
w forall a. Ord a => a -> a -> Bool
< Word
10
            then
              let (Bool
overflow,Word
acc') = Word -> Word -> (Bool, Word)
unsignedPushBase10 Word
acc Word
w
               in if Bool
overflow
                 then (# (# #) | #)
                 else Word -> Bytes -> (# (# #) | Word# #)
decWordMore Word
acc' (Int -> Bytes -> Bytes
Bytes.unsafeDrop Int
1 Bytes
chunk)
            else (# (# #) | #)

unsignedPushBase10 :: Word -> Word -> (Bool,Word)
{-# inline unsignedPushBase10 #-}
unsignedPushBase10 :: Word -> Word -> (Bool, Word)
unsignedPushBase10 (W# Word#
a) (W# Word#
b) = 
  let !(# Word#
ca, Word#
r0 #) = Word# -> Word# -> (# Word#, Word# #)
Exts.timesWord2# Word#
a Word#
10##
      !r1 :: Word#
r1 = Word# -> Word# -> Word#
Exts.plusWord# Word#
r0 Word#
b
      !cb :: Word#
cb = Int# -> Word#
int2Word# (Word# -> Word# -> Int#
ltWord# Word#
r1 Word#
r0)
      !c :: Word#
c = Word#
ca Word# -> Word# -> Word#
`or#` Word#
cb
   in (case Word#
c of { Word#
0## -> Bool
False; Word#
_ -> Bool
True }, Word# -> Word
W# Word#
r1)

unW :: Word -> Word#
{-# inline unW #-}
unW :: Word -> Word#
unW (W# Word#
w) = Word#
w