Skip to content

Commit 5b870dd

Browse files
committed
ucd2haskell: Simplier enum bitmaps
1 parent 7dcdfce commit 5b870dd

File tree

5 files changed

+518
-587
lines changed

5 files changed

+518
-587
lines changed

ucd2haskell/exe/UCD2Haskell/Generator.hs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -477,35 +477,26 @@ genEnumBitmapShamochu funcNameStr rawInt stage1 stage2 convert (defPUA, pPUA) (d
477477
, funcName, " :: Char -> Int", rawSuffix, "\n"
478478
, funcName, func
479479
, "\n"
480-
, generateShamochuBitmaps funcName03 rawInt stage1 stage2 convert bitmap03
481-
, "\n"
482-
, case mBitmap14 of
483-
Nothing -> mempty
484-
Just bitmap14 -> generateShamochuBitmaps
485-
funcName14 rawInt stage1 stage2 convert bitmap14 <> "\n"
480+
, generateShamochuBitmaps funcNameStr rawInt stage1 stage2 convert bitmap
486481
]
487482
where
488483
rawSuffix = if rawInt then "#" else ""
489484
funcName = BB.string7 funcNameStr
490-
funcName03 = funcNameStr <> "Planes0To3"
491-
funcName14 = funcNameStr <> "Plane14"
492-
lookup03 = toLookupBitMapName funcName03
493-
lookup14 = toLookupBitMapName funcName14
485+
lookupFunc = toLookupBitMapName funcNameStr
494486
planes0To3' = L.dropWhileEnd (== def) planes0To3
495487
check = if length planes0To3 <= 0x40000
496488
then ()
497489
else error "genEnumBitmap: Cannot build"
498-
(func, bitmap03, mBitmap14) = check `seq` if null plane14 && defPUA == def
490+
(func, bitmap) = check `seq` if null plane14 && defPUA == def
499491
-- Only planes 0-3
500492
then
501493
( mconcat
502-
[ " = \\c -> let cp = ord c in if cp >= 0x"
494+
[ " = \\c -> if c >= '\\x"
503495
, showPaddedHeXB (length planes0To3')
504-
, " then "
496+
, "' then "
505497
, pDef, rawSuffix
506-
, " else ", lookup03, " cp\n" ]
507-
, planes0To3'
508-
, Nothing )
498+
, " else ", lookupFunc, " (ord c)\n" ]
499+
, planes0To3' )
509500
-- All the planes
510501
else
511502
let plane14' = L.dropWhileEnd (== def) plane14
@@ -515,14 +506,14 @@ genEnumBitmapShamochu funcNameStr rawInt stage1 stage2 convert (defPUA, pPUA) (d
515506
[ " c\n"
516507
, " -- Planes 0-3\n"
517508
, " | cp < 0x", showPaddedHeXB bound1
518-
, " = ", lookup03, " cp", rawSuffix, "\n"
509+
, " = ", lookupFunc, " cp", rawSuffix, "\n"
519510
, " -- Planes 4-13: ", showB def, "\n"
520511
, " | cp < 0xE0000 = " <> pDef, rawSuffix, "\n"
521512
, " -- Plane 14\n"
522513
, " | cp < 0x", showPaddedHeXB bound2
523-
, " = ", lookup14, " (cp", rawSuffix
514+
, " = ", lookupFunc, " (cp", rawSuffix
524515
, " -", rawSuffix, " 0x"
525-
, showPaddedHeXB 0xE0000, rawSuffix
516+
, showPaddedHeXB (0xE0000 - bound1), rawSuffix
526517
, ")\n"
527518
, if defPUA == def
528519
then ""
@@ -539,8 +530,7 @@ genEnumBitmapShamochu funcNameStr rawInt stage1 stage2 convert (defPUA, pPUA) (d
539530
, " | otherwise = " <> pDef, rawSuffix, "\n"
540531
, " where\n"
541532
, " ", if rawInt then "!cp@(I# cp#)" else "cp", " = ord c\n" ]
542-
, planes0To3'
543-
, Just plane14' )
533+
, planes0To3' <> plane14' )
544534

545535
generateShamochuBitmaps ::
546536
String -> Bool -> NE.NonEmpty Word -> [Word] -> (a -> Word8) -> [a] -> BB.Builder

ucd2haskell/exe/UCD2Haskell/Modules/UnicodeData/GeneralCategory.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ genGeneralCategoryModule moduleName = Fold step initial done
131131
, "-- The caller of this function must ensure its parameter is \\< @0x40000@."
132132
, "{-# INLINE generalCategoryPlanes0To3 #-}"
133133
, "generalCategoryPlanes0To3 :: Int -> Int"
134-
, "generalCategoryPlanes0To3 = lookupGeneralCategoryPlanes0To3BitMap"
134+
, "generalCategoryPlanes0To3 = lookupGeneralCategoryBitMap"
135135
, ""
136136
, "-- | Return the general category of a character"
137137
, genEnumBitmapShamochu

0 commit comments

Comments
 (0)