From fd6388d7b4014ec8b5ab7f937a1619bad843bdae Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 11 Nov 2022 07:17:10 +1300 Subject: [PATCH] Fix tag encoding & decoding (remembered hex digits are nybbles not bytes) --- Data/Text/Glyphize/Buffer.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Data/Text/Glyphize/Buffer.hs b/Data/Text/Glyphize/Buffer.hs index 67fe9a0..f173d3e 100644 --- a/Data/Text/Glyphize/Buffer.hs +++ b/Data/Text/Glyphize/Buffer.hs @@ -267,19 +267,19 @@ script_from_string str = tag_from_string $ case titlecase str of tag_from_string :: String -> Word32 tag_from_string str = case str ++ Prelude.repeat ' ' of c1:c2:c3:c4:_ -> Prelude.foldl (.|.) 0 [ - shiftL (c2w c1 .&. 0x7) 24, - shiftL (c2w c2 .&. 0x7) 16, - shiftL (c2w c3 .&. 0x7) 8, - shiftL (c2w c4 .&. 0x7) 0 + shiftL (c2w c1 .&. 0x7f) 24, + shiftL (c2w c2 .&. 0x7f) 16, + shiftL (c2w c3 .&. 0x7f) 8, + shiftL (c2w c4 .&. 0x7f) 0 ] _ -> 0 -- | Converts a "tag" `Word32` into a 4 `Char` `String`. tag_to_string :: Word32 -> String tag_to_string tag = [ - w2c (shiftR tag 24 .&. 0x7), - w2c (shiftR tag 16 .&. 0x7), - w2c (shiftR tag 8 .&. 0x7), - w2c (shiftR tag 0 .&. 0x7) + w2c (shiftR tag 24 .&. 0x7f), + w2c (shiftR tag 16 .&. 0x7f), + w2c (shiftR tag 8 .&. 0x7f), + w2c (shiftR tag 0 .&. 0x7f) ] ------ -- 2.30.2