From 94039dbc88e959c8fef891859f262ee42a94cf09 Mon Sep 17 00:00:00 2001 From: Pasqualino Titto Assini Date: Sun, 24 May 2020 20:32:20 +0200 Subject: [PATCH] UTF16 to UTF16LE --- src/Flat/Instances/Text.hs | 18 +++++++++--------- test/Spec.hs | 10 +++++----- test/Test/Data/Values.hs | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Flat/Instances/Text.hs b/src/Flat/Instances/Text.hs index e6ee6ab..56b07d5 100644 --- a/src/Flat/Instances/Text.hs +++ b/src/Flat/Instances/Text.hs @@ -4,7 +4,7 @@ module Flat.Instances.Text( UTF8Text(..) #if! defined(ghcjs_HOST_OS) && ! defined (ETA_VERSION) && ! defined (ETA) - ,UTF16Text(..) + ,UTF16LEText(..) #endif ) where @@ -55,7 +55,7 @@ instance Flat TL.Text where decode = TL.fromStrict <$> dUTF8 {-| -The desired text encoding can be explicitly specified using the wrappers UTF8Text and UTF16Text. +The desired text encoding can be explicitly specified using the wrappers UTF8Text and UTF16LEText. The default encoding is UTF8: @@ -72,20 +72,20 @@ instance Flat UTF8Text where #if ! defined(ghcjs_HOST_OS) && ! defined (ETA_VERSION) && ! defined (ETA) {-| ->>> tst (UTF16Text $ T.pack "aaa") +>>> tst (UTF16LEText $ T.pack "aaa") (True,72,[1,6,97,0,97,0,97,0,0]) ->>> tst (UTF16Text $ T.pack "𐍈𐍈𐍈") +>>> tst (UTF16LEText $ T.pack "𐍈𐍈𐍈") (True,120,[1,12,0,216,72,223,0,216,72,223,0,216,72,223,0]) -} -- |A wrapper to encode/decode Text as UTF16 (faster but bigger) -newtype UTF16Text = UTF16Text {unUTF16::T.Text} deriving (Eq,Ord,Show) +newtype UTF16LEText = UTF16LEText {unUTF16::T.Text} deriving (Eq,Ord,Show) -instance Flat UTF16Text where - size (UTF16Text t) = sUTF16 t - encode (UTF16Text t) = eUTF16 t - decode = UTF16Text <$> dUTF16 +instance Flat UTF16LEText where + size (UTF16LEText t) = sUTF16 t + encode (UTF16LEText t) = eUTF16 t + decode = UTF16LEText <$> dUTF16 #endif diff --git a/test/Spec.hs b/test/Spec.hs index 6c305fe..5a67f8f 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -63,10 +63,10 @@ instance Arbitrary UTF8Text where shrink t = UTF8Text <$> shrink (unUTF8 t) #if! defined(ghcjs_HOST_OS) && ! defined (ETA_VERSION) -instance Arbitrary UTF16Text where - arbitrary = UTF16Text <$> arbitrary +instance Arbitrary UTF16LEText where + arbitrary = UTF16LEText <$> arbitrary - shrink t = UTF16Text <$> shrink (unUTF16 t) + shrink t = UTF16LEText <$> shrink (unUTF16 t) #endif -- instance Flat [Int16] @@ -317,7 +317,7 @@ testSize = testGroup "Size" , sz tx utf8Size , sz (UTF8Text tx) utf8Size #if! defined(ghcjs_HOST_OS) && ! defined (ETA_VERSION) - , sz (UTF16Text tx) utf16Size + , sz (UTF16LEText tx) utf16Size #endif ] where @@ -385,7 +385,7 @@ flatUnflatRT = testGroup , rt "Text" (prop_Flat_roundtrip :: RT T.Text) , rt "UTF8 Text" (prop_Flat_roundtrip :: RT UTF8Text) #if! defined(ghcjs_HOST_OS) && ! defined (ETA_VERSION) - , rt "UTF16 Text" (prop_Flat_roundtrip :: RT UTF16Text) + , rt "UTF16 Text" (prop_Flat_roundtrip :: RT UTF16LEText) #endif , rt "ByteString" (prop_Flat_roundtrip :: RT B.ByteString) , rt "Lazy ByteString" (prop_Flat_roundtrip :: RT L.ByteString) diff --git a/test/Test/Data/Values.hs b/test/Test/Data/Values.hs index 83165ed..e6a1813 100644 --- a/test/Test/Data/Values.hs +++ b/test/Test/Data/Values.hs @@ -192,7 +192,7 @@ asciiTextT = ("asciiText", T.pack $ longS english ) unicodeTextUTF8T = ("unicodeTextUTF8",UTF8Text unicodeText) #if! defined(ghcjs_HOST_OS) && ! defined (ETA_VERSION) -unicodeTextUTF16T = ("unicodeTextUTF16",UTF16Text unicodeText) +unicodeTextUTF16T = ("unicodeTextUTF16",UTF16LEText unicodeText) #endif unicodeTextT = ("unicodeText",unicodeText)