-- SPDX-FileCopyrightText: 2020 Tocqueville Group
--
-- SPDX-License-Identifier: LicenseRef-MIT-TQ

module Morley.Util.Text
  ( headToLower
  , surround
  , dquotes
  ) where

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

-- | Leads first character of text to lower case.
--
-- For empty text this will throw an error.
headToLower :: HasCallStack => Text -> Text
headToLower :: Text -> Text
headToLower Text
txt = case Text -> Maybe (Char, Text)
T.uncons Text
txt of
  Maybe (Char, Text)
Nothing -> Text -> Text
forall a. HasCallStack => Text -> a
error Text
"Empty text"
  Just (Char
c, Text
cs) -> Char -> Text -> Text
T.cons (Char -> Char
toLower Char
c) Text
cs

surround :: Semigroup a => a -> a -> a -> a
surround :: a -> a -> a -> a
surround a
pre a
post a
content = a
pre a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
content a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
post

dquotes :: (Semigroup a, IsString a) => a -> a
dquotes :: a -> a
dquotes = a -> a -> a -> a
forall a. Semigroup a => a -> a -> a -> a
surround a
"\"" a
"\""