1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
-----------------------------------------------------------------------------
-- |
-- Module : Coded.Text.Raw
-- Copyright : (c) Dominic Steinitz 2006
-- License : BSD-style (see the file ReadMe.tex)
--
-- Maintainer : dominic.steinitz@blueyonder.co.uk
-- Stability : experimental
-- Portability : portable
--
-----------------------------------------------------------------------------
module Codec.Text.Raw(
hexdump,
hexdumpBy,
) where
import Data.List
import Codec.Utils
import Numeric
import Text.PrettyPrint
split :: Int -> [a] -> [[a]]
split n xs = unfoldr (g n) xs
g :: Int -> [a] -> Maybe ([a],[a])
g n [] = Nothing
g n y = Just (splitAt n y)
sh x | x < 16 = '0':(showHex x "")
| otherwise = showHex x ""
type OctetsPerLine = Int
hexdump :: OctetsPerLine -> [Octet] -> Doc
hexdump n =
vcat .
map hcat .
map (intersperse colon) .
map (map (text . sh)) .
split n
hexdumpBy :: String -> OctetsPerLine -> [Octet] -> Doc
hexdumpBy s n =
vcat .
map hcat .
map (intersperse (text s)) .
map (map (text . sh)) .
split n
|