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

module Util.Text
  ( headToLower
  , surround
  ) 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 txt :: Text
txt = case Text -> Maybe (Char, Text)
T.uncons Text
txt of
  Nothing -> Text -> Text
forall a. HasCallStack => Text -> a
error "Empty text"
  Just (c :: Char
c, cs :: 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 pre :: a
pre post :: a
post content :: 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