class Crowbar::Buffer

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.from_io(io : IO, limit : Int32 | Nil = nil) : self #

def self.new(initial_bytes : Bytes | Array(UInt8) | String = Bytes.empty) #

Instance Method Detail

def ==(other : Buffer) : Bool #

def ==(other) : Bool #
Description copied from class Reference

Returns false (other can only be a Value here).


def [](start : Int32, count : Int32) : Bytes #

def [](range : Range(B, E)) : Bytes forall B, E #

def [](index : Int32) : UInt8 #

def []=(index : Int32, value : UInt8) #

def []?(index : Int32) : UInt8 | Nil #

def bytes : Array(UInt8) #

def clear : Nil #

Clears all bytes in buffer


def clone : Buffer #

def concat(slice : Bytes | Array(UInt8)) : Nil #

Appends bytes to the buffer


def delete_at(pos : Int32) : UInt8 | Nil #

Delete single byte at position


def delete_range(start : Int32, length : Int32) #

Delete a contiguous range of bytes


def empty? : Bool #

def find_delimiter_pairs(open_byte : UInt8, close_byte : UInt8) : Array(Tuple(Int32, Int32)) #

Find balanced delimiter pairs like (), [], {}, <>, "", ''


def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def index(needle : Bytes | Array(UInt8) | Buffer, offset : Int32 = 0) : Int32 | Nil #

Searches for a needle sequence starting at offset


def insert(pos : Int32, byte : UInt8) #

Insert a single byte at position


def insert(pos : Int32, slice : Bytes | Array(UInt8)) #

Insert a byte slice at position


def lines : Array(Tuple(Int32, Int32)) #

Find line ranges (0-indexed [start, end_exclusive])


def replace_range(start : Int32, length : Int32, replacement : Bytes | Array(UInt8)) #

Replace a slice with another slice


def size : Int32 #

def swap_ranges(pos1 : Int32, len : Int32, pos2 : Int32, len2 : Int32 = len) : Nil #

Swaps two equal-length ranges of bytes in-place


def text? : Bool #

Check if buffer appears to be mostly text


def to_raw_s : String #

def to_s(io : IO) : Nil #
Description copied from class Reference

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>

def to_s : String #
Description copied from class Object

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.


def to_slice : Bytes #