@@ -48,30 +48,14 @@ writeUnicodeWidthTable path table = do
48widthTableMagic :: Word32
48widthTableMagic :: Word32
49widthTableMagic = 0xc1a9f7e0
49widthTableMagic = 0xc1a9f7e0
51−-- NB: This parsing code uses explicit types for parsing each value to
52−-- catch situations where someone changes the types of the fields of
53−-- WidthTableRange or other values and in doing so would silently break
54−-- the parser. If the parser used a style like
56−-- WidthTableRange <$> get <*> get <*> get
58−-- then that would result in valid Haskell code that would fail to read
59−-- files that it would have previously parsed. We want those errors
60−-- caught by GHc. At the time of this writing, the library data types
61−-- *happen* to match the binary layout of the version 1 format, but that
62−-- could definitely change in later formats. In those cases we should
63−-- deal with the difference by doing the appropriate conversions.
65tableParser :: Get UnicodeWidthTable
51tableParser :: Get UnicodeWidthTable
66tableParser = do
52tableParser = do
68− <- getWord32le
53+ magic <- getWord32le
70 when (magic /= widthTableMagic) $
55 when (magic /= widthTableMagic) $
71 fail "Table magic number invalid"
56 fail "Table magic number invalid"
73− version :: Word8
58+ version <- getWord8
76 case version of
60 case version of
77 1 -> tableV1Parser
61 1 -> tableV1Parser
@@ -79,16 +63,12 @@ tableParser = do
80tableV1Parser :: Get UnicodeWidthTable
64tableV1Parser :: Get UnicodeWidthTable
81tableV1Parser = do
65tableV1Parser = do
83− <- getWord32le
66+ numRanges <- getWord32le
85 let parseRange = do
68 let parseRange = do
87− <- getWord32le
69+ start <- getWord32le
89− <- getWord32le
70+ size <- getWord32le
90− cols :: Word8
71+ cols <- getWord8
92 return WidthTableRange { rangeStart = start
72 return WidthTableRange { rangeStart = start
93 , rangeSize = size
73 , rangeSize = size
94 , rangeColumns = cols
74 , rangeColumns = cols