From 4bd95db2a46001cccd030584d3de570b5e9366fa Mon Sep 17 00:00:00 2001 From: Jaro Date: Wed, 22 Feb 2023 01:21:36 +0100 Subject: [PATCH] Clean up ParagraphConstruction. --- .../ParagraphLayout/ParagraphConstruction.hs | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/test/Data/Text/ParagraphLayout/ParagraphConstruction.hs b/test/Data/Text/ParagraphLayout/ParagraphConstruction.hs index a9af880..a9d53c2 100644 --- a/test/Data/Text/ParagraphLayout/ParagraphConstruction.hs +++ b/test/Data/Text/ParagraphLayout/ParagraphConstruction.hs @@ -21,44 +21,46 @@ import Data.Text.Foreign (lengthWord8) import Data.Text.Internal (Text(Text)) import Data.Text.ParagraphLayout.Plain (Paragraph(Paragraph) - ,ParagraphOptions() + ,ParagraphOptions ,Span(Span) ) -- | Create first span with optional ignored suffix. infixr 5 >| (>|) :: (String, String) -> String -> (Text, [Span]) -(spanText, spanLanguage) >| ignoredSuffix = (newText, newSpans) +(spanLanguage, spanText) >| suffix = (newText, newSpans) where - newSpans = [Span (fromIntegral $ lengthWord8 packedSpanText) spanLanguage] + newSpans = [newSpan] + newSpan = Span (fromIntegral $ lengthWord8 packedSpanText) spanLanguage newText = append packedSpanText packedSuffix packedSpanText = pack spanText - packedSuffix = pack ignoredSuffix + packedSuffix = pack suffix --- Create next span. +-- | Create next span. infixr 5 >|< (>|<) :: (String, String) -> (Text, [Span]) -> (Text, [Span]) -(spanText, spanLanguage) >|< (oldText, oldSpans) = (newText, newSpans) +(spanLanguage, spanText) >|< (oldText, oldSpans) = (newText, newSpans) where - newSpans = Span (fromIntegral $ lengthWord8 packedText) spanLanguage : oldSpans - newText = append packedText oldText - packedText = pack spanText + newSpans = newSpan:oldSpans + newSpan = Span (fromIntegral $ lengthWord8 packedSpanText) spanLanguage + newText = append packedSpanText oldText + packedSpanText = pack spanText --- Add optional ignored prefix and wrap in a `Paragraph`. +-- | Add optional ignored prefix and wrap in a `Paragraph`. infixr 5 |< (|<) :: String -> (Text, [Span]) -> ParagraphOptions -> Paragraph -ignoredPrefix |< (oldText, spans) = Paragraph arr (fromIntegral off) spans +prefix |< (oldText, spans) = Paragraph arr (fromIntegral afterPrefix) spans where - (Text arr offPrefix _) = append packedPrefix oldText - off = offPrefix + (lengthWord8 packedPrefix) - packedPrefix = pack ignoredPrefix + (Text arr beforePrefix _) = append packedPrefix oldText + afterPrefix = beforePrefix + lengthWord8 packedPrefix + packedPrefix = pack prefix --- Create a `Paragraph` with no spans, just two ignored texts. +-- | Create a `Paragraph` with no spans, just two ignored texts. infixr 5 |<>| (|<>|) :: String -> String -> ParagraphOptions -> Paragraph -ignoredPrefix |<>| ignoredSuffix = ignoredPrefix |< (pack ignoredSuffix, []) +prefix |<>| suffix = prefix |< (pack suffix, []) --- Combine language with text. +-- | Combine language with text. infix 6 ~ (~) :: String -> String -> (String, String) -lang ~ txt = (txt, lang) +lang ~ txt = (lang, txt) -- 2.30.2