File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,17 @@ function Base.checkbounds(buf::Buffer, i::Integer)
47
47
end
48
48
end
49
49
50
+ function Base. getindex (buf:: Buffer , r:: UnitRange{<:Integer} )
51
+ @boundscheck checkbounds (buf, r)
52
+ @inbounds return buf. data[r+ buf. bufferpos- 1 ]
53
+ end
54
+
55
+ function Base. checkbounds (buf:: Buffer , r:: UnitRange{<:Integer} )
56
+ if ! isempty (r) && ! (1 ≤ first (r) && last (r) ≤ endof (buf))
57
+ throw (BoundsError (buf, r))
58
+ end
59
+ end
60
+
50
61
function bufferptr (buf:: Buffer )
51
62
return pointer (buf. data, buf. bufferpos)
52
63
end
Original file line number Diff line number Diff line change @@ -64,8 +64,10 @@ using Base.Test
64
64
@test endof (s. state. buffer1) == 2
65
65
@test s. state. buffer1[1 ] === UInt8 (' a' )
66
66
@test s. state. buffer1[2 ] === UInt8 (' z' )
67
+ @test s. state. buffer1[1 : 2 ] == b " az"
67
68
@test_throws BoundsError s. state. buffer1[0 ]
68
69
@test_throws BoundsError s. state. buffer1[3 ]
70
+ @test_throws BoundsError s. state. buffer1[3 : 4 ]
69
71
end
70
72
71
73
Pkg. test (" CodecZlib" )
You can’t perform that action at this time.
0 commit comments