|
1 | 1 | {-# LANGUAGE BangPatterns #-} |
2 | 2 | {-# LANGUAGE OverloadedStrings #-} |
3 | | -{-# LANGUAGE TupleSections #-} |
4 | 3 | {-# LANGUAGE PatternGuards #-} |
| 4 | +{-# LANGUAGE TupleSections #-} |
5 | 5 |
|
6 | 6 | -- | |
7 | 7 | -- Module : Data.JsonStream.Parser |
@@ -43,7 +43,6 @@ module Data.JsonStream.Parser ( |
43 | 43 | -- * FromJSON parser |
44 | 44 | , value |
45 | 45 | , string |
46 | | - , bytestring |
47 | 46 | -- * Constant space parsers |
48 | 47 | , safeString |
49 | 48 | , number |
@@ -82,8 +81,7 @@ import qualified Data.HashMap.Strict as HMap |
82 | 81 | import Data.Scientific (Scientific, isInteger, |
83 | 82 | toBoundedInteger, toRealFloat) |
84 | 83 | import qualified Data.Text as T |
85 | | -import Data.Text.Encoding (encodeUtf8) |
86 | | -import Data.Text.Encoding (decodeUtf8') |
| 84 | +import Data.Text.Encoding (decodeUtf8') |
87 | 85 | import qualified Data.Vector as Vec |
88 | 86 |
|
89 | 87 | import Data.JsonStream.CLexer |
@@ -377,25 +375,13 @@ longString mbounds = Parser $ moreData (handle [] 0) |
377 | 375 | | otherwise -> Failed "Error decoding UTF8" |
378 | 376 | _ -> callParse ignoreVal tok |
379 | 377 |
|
380 | | --- | Match string as a ByteString without decoding the data from UTF8 and unescaping the contents |
381 | | --- (strings larger than input chunk, small get always decoded). |
382 | | -bytestring :: Parser BL.ByteString |
383 | | -bytestring = Parser $ moreData (handle []) |
384 | | - where |
385 | | - handle acc tok el ntok = |
386 | | - case el of |
387 | | - JValue (AE.String str) -> Yield (BL.fromChunks [encodeUtf8 str]) (Done "" ntok) |
388 | | - StringContent str -> moreData (handle (str:acc)) ntok |
389 | | - StringEnd -> Yield (BL.fromChunks $ reverse acc) (Done "" ntok) |
390 | | - _ -> callParse ignoreVal tok |
391 | | - |
392 | | - |
393 | 378 | -- | Parse string value, skip parsing otherwise. |
394 | 379 | string :: Parser T.Text |
395 | 380 | string = longString Nothing |
396 | 381 |
|
397 | 382 | -- | Stops parsing string after the limit is reached. The string will not be matched |
398 | | --- if it exceeds the size. |
| 383 | +-- if it exceeds the size. The size is the size of escaped string including escape |
| 384 | +-- characters. |
399 | 385 | safeString :: Int -> Parser T.Text |
400 | 386 | safeString limit = longString (Just limit) |
401 | 387 |
|
|
0 commit comments