A cli database for some FFX stuff
module Data.PrintableText
    ( -- * Classes
      PrintableText
      -- * Constructors
    , fromText
    , singleton
      -- * Destructure
    , unPrintableText
    ) where

import           Data.Char (isSpace)
import qualified Data.Text as T

-- |A non empty string that has atleast one printable character
newtype PrintableText = PrintableText { unPrintableText :: T.Text }
    deriving (Eq, Ord, Show)

-- |Create a PrintableText from a single Char
singleton :: Char -> Maybe PrintableText
singleton x
    | isSpace x = Nothing
    | otherwise = Just . PrintableText . T.singleton $ x

-- |Attempt to create a PrintableText from a Text, returns Nothing if no printable characters detected
fromText :: T.Text -> Maybe PrintableText
fromText x
    | T.all isSpace x = Nothing
    | otherwise = Just $ PrintableText x