lib: Use text library functions for stripping.

This commit is contained in:
Stephen Morgan 2020-07-16 20:51:48 +10:00 committed by Simon Michael
parent ed99aea7d5
commit dc076b0d5b
3 changed files with 2 additions and 22 deletions

View File

@ -361,7 +361,7 @@ commentAddTag c (t,v)
| T.null c' = tag | T.null c' = tag
| otherwise = c' `commentJoin` tag | otherwise = c' `commentJoin` tag
where where
c' = textchomp c c' = T.stripEnd c
tag = t <> ": " <> v tag = t <> ": " <> v
-- | Add a tag on its own line to a comment, preserving any prior content. -- | Add a tag on its own line to a comment, preserving any prior content.

View File

@ -121,7 +121,7 @@ transactionNote = snd . payeeAndNoteFromDescription . tdescription
payeeAndNoteFromDescription :: Text -> (Text,Text) payeeAndNoteFromDescription :: Text -> (Text,Text)
payeeAndNoteFromDescription t payeeAndNoteFromDescription t
| T.null n = (t, t) | T.null n = (t, t)
| otherwise = (textstrip p, textstrip $ T.drop 1 n) | otherwise = (T.strip p, T.strip $ T.drop 1 n)
where where
(p, n) = T.span (/= '|') t (p, n) = T.span (/= '|') t

View File

@ -27,10 +27,6 @@ module Hledger.Utils.Text
-- isSingleQuoted, -- isSingleQuoted,
-- isDoubleQuoted, -- isDoubleQuoted,
-- -- * single-line layout -- -- * single-line layout
textstrip,
textlstrip,
textrstrip,
textchomp,
-- elideLeft, -- elideLeft,
textElideRight, textElideRight,
-- formatString, -- formatString,
@ -78,22 +74,6 @@ import Hledger.Utils.Test
-- lowercase = map toLower -- lowercase = map toLower
-- uppercase = map toUpper -- uppercase = map toUpper
-- | Remove leading and trailing whitespace.
textstrip :: Text -> Text
textstrip = textlstrip . textrstrip
-- | Remove leading whitespace.
textlstrip :: Text -> Text
textlstrip = T.dropWhile (`elem` (" \t" :: String)) :: Text -> Text -- XXX isSpace ?
-- | Remove trailing whitespace.
textrstrip = T.reverse . textlstrip . T.reverse
textrstrip :: Text -> Text
-- | Remove trailing newlines/carriage returns (and other whitespace).
textchomp :: Text -> Text
textchomp = T.stripEnd
-- stripbrackets :: String -> String -- stripbrackets :: String -> String
-- stripbrackets = dropWhile (`elem` "([") . reverse . dropWhile (`elem` "])") . reverse :: String -> String -- stripbrackets = dropWhile (`elem` "([") . reverse . dropWhile (`elem` "])") . reverse :: String -> String