M lib/Graphics/Text/Font/Choose/CharSet.hs => lib/Graphics/Text/Font/Choose/CharSet.hs +2 -1
@@ 5,7 5,7 @@ module Graphics.Text.Font.Choose.CharSet(
import Data.IntSet as IntSet
-import Data.Char (isHexDigit, ord, chr)
+import Data.Char (isHexDigit, isSpace, ord, chr)
import Numeric (readHex)
import Data.MessagePack (MessagePack(..), Object(..))
@@ 25,6 25,7 @@ parseWild :: Char -> String -> Int
parseWild ch str = parseChar $ replaceWild ch str
-- | Utility for parsing "unicode-range" @font-face property.
parseCharSet :: String -> Maybe CharSet
+parseCharSet (c:rest) | isSpace c = parseCharSet rest -- Irrelevant in Stylist integration.
parseCharSet ('U':rest) = parseCharSet ('u':rest) -- lowercase initial "u"
parseCharSet ('u':'+':cs)
| (start@(_:_), '-':ends) <- span isHexDigit cs,
M test/Main.hs => test/Main.hs +11 -1
@@ 10,7 10,8 @@ import Data.MessagePack as MP
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Text as Txt
-import Data.Maybe (isJust)
+import qualified Data.IntSet as IS
+import Data.Maybe (isJust, fromMaybe)
import GHC.Real (infinity)
import Graphics.Text.Font.Choose
@@ 131,3 132,12 @@ main = hspec $ do
nameParse ":weight=[medium bold]" `shouldBe` M.fromList [
("weight", [(Strong, ValueRange $ Range 100 200)])
]
+ describe "CSS Parsing" $ do
+ it "unicode-range" $ do
+ let parseCharSet' = IS.toList . fromMaybe IS.empty . parseCharSet
+ parseCharSet' "U+26" `shouldBe` [0x26]
+ parseCharSet' "U+26, U+42" `shouldBe` [0x26, 0x42]
+ parseCharSet' "U+0-7F" `shouldBe` [0x0..0x7f]
+ parseCharSet' "U+0025-00FF" `shouldBe` [0x0025..0x00ff]
+ parseCharSet' "U+4??" `shouldBe` [0x400..0x4ff]
+ parseCharSet' "U+0025-00FF, U+4??" `shouldBe` [0x0025..0x00ff] ++ [0x400..0x4ff]