-- | Replace that with internal function in Data.Text when switching to Data.Text instead of String.
-- Function doing both left and right strip of white spaces.
strip :: String -> String
strip unstripped = walk unstripped [] 0 0
    where walk :: String -- ^ Rest of string to process
               -> String -- ^ Lstripped string. Empty in the beginning, non empty and constant when first chart is found.
               -> Int -- ^ Number of cheracters in lstripped string. Maximum non wghitespace character position.
               -> Int -- ^ Position in lstripped string currently processed.
               -> String -- ^ Result string.
          walk [] s l _ = take l s
          walk (x:xs) [] l n | isWspace x = walk xs [] l n
                             | otherwise = walk xs (x:xs) 1 1
          walk (x:xs) ys l n | isWspace x = walk xs ys l (n + 1)
                             | otherwise = walk xs ys (n + 1) (n + 1)
          isWspace c = c `elem` " \t\r\n"


-- | Split string by character. Do not merge mutliple separators in a row but instead
-- | generate empty strings.
strip :: String -> String
strip unstripped = walk unstripped [] 0 0
    where walk :: String -- ^ Rest of string to process
               -> String -- ^ Lstripped string. Empty in the beginning, non empty and constant when first chart is found.
               -> Int -- ^ Number of cheracters in lstripped string. Maximum non wghitespace character position.
               -> Int -- ^ Position in lstripped string currently processed.
               -> String -- ^ Result string.
          walk [] s l _ = take l s
          walk (x:xs) [] l n | isWspace x = walk xs [] l n
                             | otherwise = walk xs (x:xs) 1 1
          walk (x:xs) ys l n | isWspace x = walk xs ys l (n + 1)
                             | otherwise = walk xs ys (n + 1) (n + 1)
          isWspace c = c `elem` " \t\r\n"


-- | Split string by character. Do not merge mutliple separators in a row but instead
-- | generate empty strings.
strip unstripped = walk unstripped [] 0 0
    where walk :: String -- ^ Rest of string to process
               -> String -- ^ Lstripped string. Empty in the beginning, non empty and constant when first chart is found.
               -> Int -- ^ Number of cheracters in lstripped string. Maximum non wghitespace character position.
               -> Int -- ^ Position in lstripped string currently processed.
               -> String -- ^ Result string.
          walk [] s l _ = take l s
          walk (x:xs) [] l n | isWspace x = walk xs [] l n
                             | otherwise = walk xs (x:xs) 1 1
          walk (x:xs) ys l n | isWspace x = walk xs ys l (n + 1)
                             | otherwise = walk xs ys (n + 1) (n + 1)
          isWspace c = c `elem` " \t\r\n"


-- | Split string by character. Do not merge mutliple separators in a row but instead
-- | generate empty strings.