struct Pf::GraphemeView

Overview

Represents a single grapheme as a view into a string.

NOTE GraphemeView, just like GraphemeSeln, refers back to the trunk string, which could be very large. This may prevent the GC from freeing large chunks of memory due to a small number of grapheme views that refer to it. For this reason, you are advised not to store GraphemeViews on the heap unless you know for sure their lifetime is less than or equal to the lifetime of the trunk string. Otherwise, use #to_grapheme. In general, when working with GraphemeView, the reasoning should be the same as with GraphemeSeln; in that they carry around, at least conceptually, the larger context as well.

EXPERIMENTAL Relies on features from the experimental String::Grapheme API.

Defined in:

permafrost/grapheme_view.cr

Instance Method Summary

Instance Method Detail

def ==(other : Char) : Bool #

Returns true if this view consists only of the character other.


[View source]
def ==(other : String) : Bool #

Compares the contents of this view with other, bytewise.


[View source]
def byte_end : Int32 #

Returns the byte index of this grapheme in the trunk string.


[View source]
def byte_range : Range(Int32, Int32) #

Returns an exclusive range of the indices of the contituent bytes of this grapheme in the trunk string.


[View source]
def byte_start : Int32 #

Returns the byte index of this grapheme in the trunk string.


[View source]
def bytesize : Int32 #

Returns the size of this grapheme in bytes.


[View source]
def inspect(io) #

[View source]
def to_grapheme : String::Grapheme #

Converts this view to a String::Grapheme.


[View source]
def to_s(io) #

[View source]
def to_slice : Bytes #

Returns a read-only view of the underling bytes of this grapheme. The view is a subview of the trunk string's bytes.


[View source]