-
Notifications
You must be signed in to change notification settings - Fork 272
/
Data-ByteString-Strict-Lens.html
73 lines (73 loc) · 8.17 KB
/
Data-ByteString-Strict-Lens.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>src/Data/ByteString/Strict/Lens.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>{-# LANGUAGE FlexibleContexts #-}</span>
<a name="line-2"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span>
<a name="line-3"></a><span class='hs-comment'>-- |</span>
<a name="line-4"></a><span class='hs-comment'>-- Module : Data.ByteString.Strict.Lens</span>
<a name="line-5"></a><span class='hs-comment'>-- Copyright : (C) 2012 Edward Kmett</span>
<a name="line-6"></a><span class='hs-comment'>-- License : BSD-style (see the file LICENSE)</span>
<a name="line-7"></a><span class='hs-comment'>-- Maintainer : Edward Kmett <ekmett@gmail.com></span>
<a name="line-8"></a><span class='hs-comment'>-- Stability : provisional</span>
<a name="line-9"></a><span class='hs-comment'>-- Portability : portable</span>
<a name="line-10"></a><span class='hs-comment'>--</span>
<a name="line-11"></a><span class='hs-comment'>----------------------------------------------------------------------------</span>
<a name="line-12"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-varop'>.</span><span class='hs-conid'>Strict</span><span class='hs-varop'>.</span><span class='hs-conid'>Lens</span>
<a name="line-13"></a> <span class='hs-layout'>(</span> <span class='hs-varid'>packedBytes</span><span class='hs-layout'>,</span> <span class='hs-varid'>bytes</span>
<a name="line-14"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>packedChars</span><span class='hs-layout'>,</span> <span class='hs-varid'>chars</span>
<a name="line-15"></a> <span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-16"></a>
<a name="line-17"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Lens</span>
<a name="line-18"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>Words</span>
<a name="line-19"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-varop'>.</span><span class='hs-conid'>Char8</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>Char8</span>
<a name="line-20"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Word</span> <span class='hs-layout'>(</span><span class='hs-conid'>Word8</span><span class='hs-layout'>)</span>
<a name="line-21"></a>
<a name="line-22"></a><a name="packedBytes"></a><span class='hs-comment'>-- | 'Data.ByteString.pack' (or 'Data.ByteString.unpack') a list of bytes into a 'ByteString'</span>
<a name="line-23"></a><span class='hs-comment'>--</span>
<a name="line-24"></a><span class='hs-comment'>-- @'Data.ByteString.pack' x = x '^.' 'packedBytes'@</span>
<a name="line-25"></a><span class='hs-comment'>--</span>
<a name="line-26"></a><span class='hs-comment'>-- @'Data.ByteString.unpack' x = x '^.' 'from' 'packedBytes'@</span>
<a name="line-27"></a><span class='hs-definition'>packedBytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Simple</span> <span class='hs-conid'>Iso</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Word8</span><span class='hs-keyglyph'>]</span> <span class='hs-conid'>ByteString</span>
<a name="line-28"></a><span class='hs-definition'>packedBytes</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>iso</span> <span class='hs-conid'>Words</span><span class='hs-varop'>.</span><span class='hs-varid'>pack</span> <span class='hs-conid'>Words</span><span class='hs-varop'>.</span><span class='hs-varid'>unpack</span>
<a name="line-29"></a><span class='hs-comment'>{-# INLINE packedBytes #-}</span>
<a name="line-30"></a>
<a name="line-31"></a><a name="bytes"></a><span class='hs-comment'>-- | Traverse each 'Word8' in a 'ByteString'</span>
<a name="line-32"></a><span class='hs-comment'>--</span>
<a name="line-33"></a><span class='hs-comment'>-- @'bytes' = 'from' 'packedBytes' '.>' 'itraversed'@</span>
<a name="line-34"></a><span class='hs-comment'>--</span>
<a name="line-35"></a><span class='hs-comment'>-- @'anyOf' 'bytes' ('==' 0x80) :: 'ByteString' -> 'Bool'@</span>
<a name="line-36"></a><span class='hs-definition'>bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>SimpleIndexedTraversal</span> <span class='hs-conid'>Int</span> <span class='hs-conid'>ByteString</span> <span class='hs-conid'>Word8</span>
<a name="line-37"></a><span class='hs-definition'>bytes</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>from</span> <span class='hs-varid'>packedBytes</span> <span class='hs-varop'>.></span> <span class='hs-varid'>itraversed</span>
<a name="line-38"></a><span class='hs-comment'>{-# INLINE bytes #-}</span>
<a name="line-39"></a>
<a name="line-40"></a><a name="packedChars"></a><span class='hs-comment'>-- | 'Data.ByteString.Char8.pack' (or 'Data.ByteString.Char8.unpack') a list of characters into a 'ByteString'</span>
<a name="line-41"></a><span class='hs-comment'>--</span>
<a name="line-42"></a><span class='hs-comment'>-- When writing back to the 'ByteString' it is assumed that every 'Char'</span>
<a name="line-43"></a><span class='hs-comment'>-- lies between '\x00' and '\xff'.</span>
<a name="line-44"></a><span class='hs-comment'>--</span>
<a name="line-45"></a><span class='hs-comment'>-- @'Data.ByteString.Char8.pack' x = x '^.' 'packedChars'@</span>
<a name="line-46"></a><span class='hs-comment'>--</span>
<a name="line-47"></a><span class='hs-comment'>-- @'Data.ByteString.Char8.unpack' x = x '^.' 'from' 'packedChars'@</span>
<a name="line-48"></a><span class='hs-definition'>packedChars</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Simple</span> <span class='hs-conid'>Iso</span> <span class='hs-conid'>String</span> <span class='hs-conid'>ByteString</span>
<a name="line-49"></a><span class='hs-definition'>packedChars</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>iso</span> <span class='hs-conid'>Char8</span><span class='hs-varop'>.</span><span class='hs-varid'>pack</span> <span class='hs-conid'>Char8</span><span class='hs-varop'>.</span><span class='hs-varid'>unpack</span>
<a name="line-50"></a><span class='hs-comment'>{-# INLINE packedChars #-}</span>
<a name="line-51"></a>
<a name="line-52"></a><a name="chars"></a><span class='hs-comment'>-- | Traverse the individual bytes in a 'ByteString' as characters.</span>
<a name="line-53"></a><span class='hs-comment'>--</span>
<a name="line-54"></a><span class='hs-comment'>-- When writing back to the 'ByteString' it is assumed that every 'Char'</span>
<a name="line-55"></a><span class='hs-comment'>-- lies between '\x00' and '\xff'.</span>
<a name="line-56"></a><span class='hs-comment'>--</span>
<a name="line-57"></a><span class='hs-comment'>-- @'chars' = 'from' 'packedChars' . 'traverse'@</span>
<a name="line-58"></a><span class='hs-comment'>--</span>
<a name="line-59"></a><span class='hs-comment'>-- @'anyOf' 'chars' ('==' \'c\') :: 'ByteString' -> 'Bool'@</span>
<a name="line-60"></a><span class='hs-definition'>chars</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>SimpleIndexedTraversal</span> <span class='hs-conid'>Int</span> <span class='hs-conid'>ByteString</span> <span class='hs-conid'>Char</span>
<a name="line-61"></a><span class='hs-definition'>chars</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>from</span> <span class='hs-varid'>packedChars</span> <span class='hs-varop'>.></span> <span class='hs-varid'>itraversed</span>
<a name="line-62"></a><span class='hs-comment'>{-# INLINE chars #-}</span>
</pre></body>
</html>