<commit_before>module Network.HPACK.HeaderBlock.String (
    encode
  , parseString
  ) where

import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Network.HPACK.Huffman as Huffman
import Network.HPACK.Types

-- | Encoding 'HeaderStuff' to 'ByteString' according to 'HuffmanEncoding'.
encode :: Bool -> HeaderStuff -> ByteString
encode True h = Huffman.encode h
encode _    h = h

-- fixme: removing
-- | Decoding 'ByteString' to 'HeaderStuff' according to 'HuffmanDecoding'.
decode :: ByteString -> Either DecodeError HeaderStuff
decode ws = Huffman.decode ws

-- | Parsing 'HeaderStuff' from 'ByteString'.
--   The second 'Bool' is whether or not huffman encoding is used.
--   The third 'Int' is the length of the encoded string.
parseString :: Bool -> Int -> ByteString
            -> Either DecodeError (HeaderStuff, ByteString)
parseString False len bs = Right (es, bs')
  where
    (es, bs') = BS.splitAt len bs
parseString True  len bs = decode es >>= \x -> return (x,bs')
  where
    (es, bs') = BS.splitAt len bs<commit_msg>removing unnecessary function.<commit_after>module Network.HPACK.HeaderBlock.String (
    encode
  , parseString
  ) where

import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Network.HPACK.Huffman as Huffman
import Network.HPACK.Types

-- | Encoding 'HeaderStuff' to 'ByteString' according to 'HuffmanEncoding'.
encode :: Bool -> HeaderStuff -> ByteString
encode True h = Huffman.encode h
encode _    h = h

-- | Parsing 'HeaderStuff' from 'ByteString'.
--   The second 'Bool' is whether or not huffman encoding is used.
--   The third 'Int' is the length of the encoded string.
parseString :: Bool -> Int -> ByteString
            -> Either DecodeError (HeaderStuff, ByteString)
parseString False len bs = Right (es, bs')
  where
    (es, bs') = BS.splitAt len bs
parseString True  len bs = Huffman.decode es >>= \x -> return (x,bs')
  where
    (es, bs') = BS.splitAt len bs
{'fraction_non_alphanumeric': 0.10402010050251256, 'fraction_numerical': 0.0, 'mean_word_length': 3.5981524249422634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6594422', 'n_tokens_mistral': 624, 'n_tokens_neox': 597, 'n_words': 219}