Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add Text serialization function txt.

It's similar to the existing str, except that we're using strict
ByteStrings (since text-icu does) and we need a Converter value to do
proper unicode conversion.

str still uses Char8.pack, which isn't ideal.
  • Loading branch information...
commit f6fbc8842cba5f738905a3364a03693793f7ebe6 1 parent 230bcb1
Aleksandar Dimitrov authored May 02, 2012

Showing 1 changed file with 9 additions and 0 deletions. Show diff stats Hide diff stats

  1. 9  Text/Search/Sphinx/Put.hs
9  Text/Search/Sphinx/Put.hs
@@ -8,6 +8,10 @@ import Data.ByteString.Lazy.Char8 (pack)
8 8
 import qualified Data.ByteString.Lazy as BS
9 9
 import qualified Text.Search.Sphinx.Types as T
10 10
 
  11
+import Data.Text (Text)
  12
+import qualified Data.Text.ICU.Convert as ICU
  13
+import qualified Data.ByteString as Strict (length)
  14
+
11 15
 num     = putWord32be . fromIntegral
12 16
 num64 i = putWord64be $ fromIntegral i
13 17
 
@@ -39,3 +43,8 @@ foldPuts :: [Put] -> Put
39 43
 foldPuts [] = return ()
40 44
 foldPuts [p] = p
41 45
 foldPuts (p:ps) = p >> foldPuts ps
  46
+
  47
+txt :: ICU.Converter -> Text -> Put
  48
+txt conv t = do let bs = ICU.fromUnicode conv t
  49
+                num (fromEnum $ Strict.length bs)
  50
+                putByteString bs

0 notes on commit f6fbc88

Please sign in to comment.
Something went wrong with that request. Please try again.