class

TextBuffer

Inherits Reference < Object

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.

Constants

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

new(string : String)
Source

Instance methods

==(other : self)

Two buffers are equal if their strings are equal.

[](index : Int)

Returns the index-th character in this buffer.

Source
hash(hasher)

Two buffers are equal if their strings are equal.

line(index : Int)

Returns the index-th line, or raises.

Source
line?(index : Int)

Returns the index-th line, or nil.

Source
line_at(index : Int)

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

Source
line_at?(index : Int)

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

Source
lines

Returns the amount of lines in this buffer.

Source
size(*args, **options)

Returns the amount of characters in this buffer.

Source
size(*args, **options, &)

Returns the amount of characters in this buffer.

Source
slice(b : Int, e : Int)

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

Source
update(string : String, lineno = 0)

Sets buffer string to string.

Source
update(lineno = 0, &)

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

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

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

Source