lib: Refactor unlinesB to be cleaner and more efficient.
This commit is contained in:
parent
d3a1caa6c1
commit
2c2bd8b27e
@ -66,19 +66,15 @@ module Hledger.Utils.Text
|
|||||||
where
|
where
|
||||||
|
|
||||||
import Data.Char (digitToInt)
|
import Data.Char (digitToInt)
|
||||||
import Data.List
|
import Data.List (transpose)
|
||||||
#if !(MIN_VERSION_base(4,11,0))
|
#if !(MIN_VERSION_base(4,11,0))
|
||||||
import Data.Monoid
|
import Data.Semigroup ((<>))
|
||||||
#endif
|
#endif
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Lazy.Builder as TB
|
import qualified Data.Text.Lazy.Builder as TB
|
||||||
-- import Text.Parsec
|
|
||||||
-- import Text.Printf (printf)
|
|
||||||
|
|
||||||
-- import Hledger.Utils.Parse
|
import Hledger.Utils.Test ((@?=), test, tests)
|
||||||
-- import Hledger.Utils.Regex
|
|
||||||
import Hledger.Utils.Test
|
|
||||||
import Text.WideString (WideBuilder(..), wbToText, wbUnpack, charWidth, textWidth)
|
import Text.WideString (WideBuilder(..), wbToText, wbUnpack, charWidth, textWidth)
|
||||||
|
|
||||||
|
|
||||||
@ -373,11 +369,9 @@ linesPrepend2 prefix1 prefix2 s = T.unlines $ case T.lines s of
|
|||||||
[] -> []
|
[] -> []
|
||||||
l:ls -> (prefix1<>l) : map (prefix2<>) ls
|
l:ls -> (prefix1<>l) : map (prefix2<>) ls
|
||||||
|
|
||||||
-- | Concatenate a list of Text Builders with a newline between each item, and
|
-- | Join a list of Text Builders with a newline after each item.
|
||||||
-- another at the end. If the list is empty, return the identity builder.
|
|
||||||
unlinesB :: [TB.Builder] -> TB.Builder
|
unlinesB :: [TB.Builder] -> TB.Builder
|
||||||
unlinesB [] = mempty
|
unlinesB = foldMap (<> TB.singleton '\n')
|
||||||
unlinesB xs = mconcat (intersperse (TB.singleton '\n') xs) <> TB.singleton '\n'
|
|
||||||
|
|
||||||
-- | Read a decimal number from a Text. Assumes the input consists only of digit
|
-- | Read a decimal number from a Text. Assumes the input consists only of digit
|
||||||
-- characters.
|
-- characters.
|
||||||
|
|||||||
@ -103,7 +103,7 @@ renderTableB topts@TableOpts{prettyTable=pretty, tableBorders=borders} fr fc f (
|
|||||||
-- borders and bars
|
-- borders and bars
|
||||||
addBorders xs = if borders then bar VT SingleLine : xs ++ [bar VB SingleLine] else xs
|
addBorders xs = if borders then bar VT SingleLine : xs ++ [bar VB SingleLine] else xs
|
||||||
bar vpos prop = mconcat $ renderHLine vpos borders pretty sizes ch2 prop
|
bar vpos prop = mconcat $ renderHLine vpos borders pretty sizes ch2 prop
|
||||||
unlinesB = (<>singleton '\n') . mconcat . intersperse "\n"
|
unlinesB = foldMap (<> singleton '\n')
|
||||||
|
|
||||||
-- | Render a single row according to cell specifications.
|
-- | Render a single row according to cell specifications.
|
||||||
renderRow :: TableOpts -> Header Cell -> TL.Text
|
renderRow :: TableOpts -> Header Cell -> TL.Text
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user