From cd222f8d4d4ab756efa7b3fe507c2f39ee12773b Mon Sep 17 00:00:00 2001 From: Tuong Nguyen Manh Date: Sun, 21 Sep 2025 00:08:10 +0200 Subject: [PATCH] Fix length calculation for combined characters --- src/Text/GridTable/Trace.hs | 4 ++-- test/test-gridtables.hs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Text/GridTable/Trace.hs b/src/Text/GridTable/Trace.hs index 9bcf9e6..e924c48 100644 --- a/src/Text/GridTable/Trace.hs +++ b/src/Text/GridTable/Trace.hs @@ -30,7 +30,7 @@ import Data.List (foldl') import Data.Maybe (fromMaybe) import Data.Set (Set) import Data.Text (Text) -import Text.DocLayout (charWidth) +import Text.DocLayout (charWidth, realLength) import Text.GridTable.ArrayTable import qualified Data.Map.Strict as Map import qualified Data.Set as Set @@ -99,7 +99,7 @@ initialTraceInfo = TraceInfo -- | Converts a list of lines into a char array. toCharGrid :: [Text] -> CharGrid toCharGrid lines = - let chars = foldr (\t m -> max m (T.length t)) 0 lines -- potential overcount + let chars = foldr (\t m -> max m (realLength t)) 0 lines -- potential overcount gbounds = ( (CharRow 1, CharCol 1) , (CharRow (length lines), CharCol chars) ) diff --git a/test/test-gridtables.hs b/test/test-gridtables.hs index 2b55fe6..b1a0af2 100644 --- a/test/test-gridtables.hs +++ b/test/test-gridtables.hs @@ -372,6 +372,23 @@ gridTableTests = testGroup "parseArrayTable" , arrayTableColSpecs = defaultAlign [10, 1] }) + , testCase "combined characters" $ + let gt = T.unlines + [ "+---+------+" + , "| a | back |" + , "+===+======+" + , "| ø̞ | o̞ |" + , "+---+------+" + ] + in parse' gridTable gt @?= + Right (ArrayTable + { arrayTableCells = listArray ((1,1),(2,2)) + [ ContentCell 1 1 [" a "], ContentCell 1 1 [" back "], ContentCell 1 1 [" ø̞ "], ContentCell 1 1 [" o̞ "]] + , arrayTableHead = Just 1 + , arrayTableFoot = Nothing + , arrayTableColSpecs = defaultAlign [3, 6] + }) + ] , testCase "unterminated row" $