)
where
import Control.Applicative
+import qualified Control.Exception as E
import Control.Monad.Unicode
import Data.Ascii (Ascii, CIAscii, AsciiBuilder)
import qualified Data.Ascii as A
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.ICU.Convert as TC
+import Data.Text.ICU.Error
import Data.Text.Encoding
import Data.Traversable
import Data.Word
import Network.HTTP.Lucu.Utils
import Prelude hiding (concat, mapM, takeWhile)
import Prelude.Unicode
+import System.IO.Unsafe
printParams ∷ Map CIAscii Text → AsciiBuilder
printParams params
payload ← encodedPayload
if charset ≡ "" then
-- NOTE: I'm not sure this is the right thing, but RFC
- -- 2231 doesn't tell us what should we do when the
+ -- 2231 doesn't tell us what we should do when the
-- charset is omitted.
return ("US-ASCII", payload)
else
let t = TC.toUnicode conv epPayload
decodeSeq' (Just conv) xs $ S.singleton t
ContinuedEncodedParam {..} :< _
- → fail "decodeSeq: internal error: ContinuedEncodedParam at section 0"
+ → fail "decodeSeq: internal error: CEP at section 0"
AsciiParam {..} :< xs
→ let t = A.toText apPayload
in
EmptyL
→ return $ T.concat $ toList chunks
InitialEncodedParam {..} :< _
- → fail "decodeSeq': internal error: InitialEncodedParam at section > 0"
+ → fail "decodeSeq': internal error: IEP at section > 0"
ContinuedEncodedParam {..} :< xs
→ case convM of
Just conv
, show epSection
, " for parameter '"
, A.toString $ A.fromCIAscii epName
- , "' is encoded but its section 0 is not"
+ , "' is encoded but its first section is not"
])
AsciiParam {..} :< xs
→ let t = A.toText apPayload
openConv ∷ CIAscii → m TC.Converter
openConv charset
- = fail "FIXME"
+ = let cs = A.toString $ A.fromCIAscii charset
+ open' = TC.open cs (Just True)
+ in
+ case unsafePerformIO $ E.try open' of
+ Right conv → return conv
+ Left err → fail $ show (err ∷ ICUError)