Skip to content

Commit 7cb3127

Browse files
TuongNMtarleb
authored andcommitted
Fix length calculation for combined characters
1 parent 456d1cd commit 7cb3127

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Text/GridTable/Trace.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Data.List (foldl')
3030
import Data.Maybe (fromMaybe)
3131
import Data.Set (Set)
3232
import Data.Text (Text)
33-
import Text.DocLayout (charWidth)
33+
import Text.DocLayout (charWidth, realLength)
3434
import Text.GridTable.ArrayTable
3535
import qualified Data.Map.Strict as Map
3636
import qualified Data.Set as Set
@@ -99,7 +99,7 @@ initialTraceInfo = TraceInfo
9999
-- | Converts a list of lines into a char array.
100100
toCharGrid :: [Text] -> CharGrid
101101
toCharGrid lines =
102-
let chars = foldr (\t m -> max m (T.length t)) 0 lines -- potential overcount
102+
let chars = foldr (\t m -> max m (realLength t)) 0 lines -- potential overcount
103103
gbounds = ( (CharRow 1, CharCol 1)
104104
, (CharRow (length lines), CharCol chars)
105105
)

test/test-gridtables.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,23 @@ gridTableTests = testGroup "parseArrayTable"
372372
, arrayTableColSpecs = defaultAlign [10, 1]
373373
})
374374

375+
, testCase "combined characters" $
376+
let gt = T.unlines
377+
[ "+---+------+"
378+
, "| a | back |"
379+
, "+===+======+"
380+
, "| ø̞ | o̞ |"
381+
, "+---+------+"
382+
]
383+
in parse' gridTable gt @?=
384+
Right (ArrayTable
385+
{ arrayTableCells = listArray ((1,1),(2,2))
386+
[ ContentCell 1 1 [" a "], ContentCell 1 1 [" back "], ContentCell 1 1 [" ø̞ "], ContentCell 1 1 [""]]
387+
, arrayTableHead = Just 1
388+
, arrayTableFoot = Nothing
389+
, arrayTableColSpecs = defaultAlign [3, 6]
390+
})
391+
375392
]
376393

377394
, testCase "unterminated row" $

0 commit comments

Comments
 (0)