class TextBuffer

Overview

TextBuffer is an abstraction over a string and an array of line bounds (see Line) in that string. These bounds are recomputed after every #update (e.g. on every keystroke).

The latter is done as quickly as possible, so there is little performance penalty in exchange for great ease-of-use.

Defined in:

aspis/buffer.cr

Constant Summary

AVG_CPL = 40

Characters per line, on average. A heuristic used to pre- allocate the line array.

WORDSTOP = "`~!@#$%^&*()-=+[{]}|;:'\",.<>/?"

Non-whitespace characters that terminate word boundary search.

Constructors

Instance Method Summary

Constructor Detail

def self.new(string : String) #

[View source]

Instance Method Detail

def ==(other : self) #

Two buffers are equal if their strings are equal.


def [](index : Int) #

Returns the index-th character in this buffer.


[View source]
def hash(hasher) #

Two buffers are equal if their strings are equal.


def line(index : Int) #

Returns the index-th line, or raises.


[View source]
def line?(index : Int) #

Returns the index-th line, or nil.


[View source]
def line_at(index : Int) #

Returns the line at the given character index, or raises.


[View source]
def line_at?(index : Int) #

Returns the line at the given character index, or nil.


[View source]
def lines #

Returns the amount of lines in this buffer.


[View source]
def size(*args, **options) #

Returns the amount of characters in this buffer.


[View source]
def size(*args, **options, &) #

Returns the amount of characters in this buffer.


[View source]
def slice(b : Int, e : Int) #

Slices this buffer from begin index to end index. Both ends are included.


[View source]
def update(string : String, lineno = 0) #

Sets buffer string to string.


[View source]
def update(lineno = 0, &) #

Yields buffer string to the block. Updates buffer string with block result.


[View source]
def word_begin_at(index : Int) #

Finds word begin position by going back as far as possible, stopping either on word stop characters WORDSTOP or the first whitespace.


[View source]
def word_end_at(index : Int) #

Find end position by going forth as far as possible, stopping either on word stop characters or the first whitespace.


[View source]