packages feed

papa-0.7.0: src/Papa/Internal/Char8.hs

{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}

-- | The characters that fit in a byte, for the checked functions of the
-- Char8 modules.
module Papa.Internal.Char8 (
  latin1,
  latin1s,
) where

import Control.Monad (guard)
import Data.Bool (Bool)
import Data.Char (Char)
import Data.Foldable (all)
import Data.Function ((.))
import Data.Maybe (Maybe)
import Data.Ord ((<=))
import Data.String (String)

-- | Whether a character fits in a byte: @\'\\0\'@ to @\'\\255\'@, which the
-- Char8 functions store as its code point, where they store any other
-- character's code point modulo 256.
latin1 :: Char -> Bool
latin1 c =
  c <= '\255'
{-# INLINE latin1 #-}

-- | 'Data.Maybe.Just' for a string whose characters all fit in a byte.
latin1s :: String -> Maybe ()
latin1s =
  guard . all latin1
{-# INLINE latin1s #-}