module Hedgehog.Extras.Stock.String
  ( strip
  , lastLine
  , firstLine
  ) where

import           Data.Function
import           Data.String

import qualified Data.List as L
import qualified Data.Text as T

-- | Strip whitepsace from the beginning and end of the string.
strip :: String -> String
strip :: String -> String
strip = Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.strip forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack

-- | Get the last line in the string
lastLine :: String -> String
lastLine :: String -> String
lastLine = String -> String
strip forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
L.unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> [a]
L.reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> [a] -> [a]
L.take Int
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> [a]
L.reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
L.lines

-- | Get the first line in the string
firstLine :: String -> String
firstLine :: String -> String
firstLine = String -> String
strip forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
L.unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> [a] -> [a]
L.take Int
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
L.lines