From dc076b0d5b4ffeba5b415aee8eb6a539cb62d326 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Thu, 16 Jul 2020 20:51:48 +1000 Subject: [PATCH] lib: Use text library functions for stripping. --- hledger-lib/Hledger/Data/Posting.hs | 2 +- hledger-lib/Hledger/Data/Transaction.hs | 2 +- hledger-lib/Hledger/Utils/Text.hs | 20 -------------------- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index 72c247375..451509fa1 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -361,7 +361,7 @@ commentAddTag c (t,v) | T.null c' = tag | otherwise = c' `commentJoin` tag where - c' = textchomp c + c' = T.stripEnd c tag = t <> ": " <> v -- | Add a tag on its own line to a comment, preserving any prior content. diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 4f2929e1e..5ca0b0cd3 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -121,7 +121,7 @@ transactionNote = snd . payeeAndNoteFromDescription . tdescription payeeAndNoteFromDescription :: Text -> (Text,Text) payeeAndNoteFromDescription 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 (p, n) = T.span (/= '|') t diff --git a/hledger-lib/Hledger/Utils/Text.hs b/hledger-lib/Hledger/Utils/Text.hs index cabe127a1..f5f6954bd 100644 --- a/hledger-lib/Hledger/Utils/Text.hs +++ b/hledger-lib/Hledger/Utils/Text.hs @@ -27,10 +27,6 @@ module Hledger.Utils.Text -- isSingleQuoted, -- isDoubleQuoted, -- -- * single-line layout - textstrip, - textlstrip, - textrstrip, - textchomp, -- elideLeft, textElideRight, -- formatString, @@ -78,22 +74,6 @@ import Hledger.Utils.Test -- lowercase = map toLower -- 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 = dropWhile (`elem` "([") . reverse . dropWhile (`elem` "])") . reverse :: String -> String