class
Crowbar::Buffer
- Crowbar::Buffer
- Reference
- Object
Overview
Binary-safe byte buffer container for non-destructive and in-place transformations. Handles raw bytes, arbitrary non-UTF-8 binaries, and provides slicing/splicing helpers.
Defined in:
crowbar/buffer.crConstructors
- .from_io(io : IO, limit : Int32 | Nil = nil) : self
- .new(initial_bytes : Bytes | Array(UInt8) | String = Bytes.empty)
Instance Method Summary
- #==(other : Buffer) : Bool
-
#==(other) : Bool
Returns
false(other can only be aValuehere). - #[](start : Int32, count : Int32) : Bytes
- #[](range : Range(B, E)) : Bytes forall B, E
- #[](index : Int32) : UInt8
- #[]=(index : Int32, value : UInt8)
- #[]?(index : Int32) : UInt8 | Nil
- #bytes : Array(UInt8)
-
#clear : Nil
Clears all bytes in buffer
- #clone : Buffer
-
#concat(slice : Bytes | Array(UInt8)) : Nil
Appends bytes to the buffer
-
#delete_at(pos : Int32) : UInt8 | Nil
Delete single byte at position
-
#delete_range(start : Int32, length : Int32)
Delete a contiguous range of bytes
- #empty? : Bool
-
#find_delimiter_pairs(open_byte : UInt8, close_byte : UInt8) : Array(Tuple(Int32, Int32))
Find balanced delimiter pairs like (), [], {}, <>, "", ''
-
#hash(hasher)
See
Object#hash(hasher) -
#index(needle : Bytes | Array(UInt8) | Buffer, offset : Int32 = 0) : Int32 | Nil
Searches for a needle sequence starting at offset
-
#insert(pos : Int32, byte : UInt8)
Insert a single byte at position
-
#insert(pos : Int32, slice : Bytes | Array(UInt8))
Insert a byte slice at position
-
#lines : Array(Tuple(Int32, Int32))
Find line ranges (0-indexed [start, end_exclusive])
-
#replace_range(start : Int32, length : Int32, replacement : Bytes | Array(UInt8))
Replace a slice with another slice
- #size : Int32
-
#swap_ranges(pos1 : Int32, len : Int32, pos2 : Int32, len2 : Int32 = len) : Nil
Swaps two equal-length ranges of bytes in-place
-
#text? : Bool
Check if buffer appears to be mostly text
- #to_raw_s : String
-
#to_s(io : IO) : Nil
Appends a short String representation of this object which includes its class name and its object address.
-
#to_s : String
Returns a nicely readable and concise string representation of this object, typically intended for users.
- #to_slice : Bytes
Constructor Detail
Instance Method Detail
Returns false (other can only be a Value here).
Find balanced delimiter pairs like (), [], {}, <>, "", ''
Searches for a needle sequence starting at offset
Replace a slice with another slice
Swaps two equal-length ranges of bytes in-place
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Returns a nicely readable and concise string representation of this object, typically intended for users.
This method should usually not be overridden. It delegates to
#to_s(IO) which can be overridden for custom implementations.
Also see #inspect.