A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
a11::flow::TextIndex Class Reference

A document, and the offset arithmetic every editor protocol needs over it. More...

#include <cpp/a11/flow/offsets.h>

Public Member Functions

 TextIndex ()=default
 
 TextIndex (std::string text)
 
const std::string & Text () const
 
size_t LineCount () const
 
size_t Utf16Of (size_t byte_offset) const
 How many UTF-16 units of the document precede this byte offset.
 
size_t ByteOf (size_t utf16_offset) const
 The byte offset that many UTF-16 units into the document.
 
std::pair< int, int > PositionOf (size_t byte_offset) const
 The LSP position – zero-based line, UTF-16 units into it – of a byte offset.
 
size_t ByteOfPosition (int line, int character) const
 The byte offset of an LSP position, clamped into the document.
 

Detailed Description

A document, and the offset arithmetic every editor protocol needs over it.

Converts between byte offsets and editor position units.

Flow offsets count bytes from the start of the file. LSP positions count UTF-16 code units from the start of a line, while JVM offsets count UTF-16 code units from the start of the document. Both protocol adapters use this conversion.

Constructor & Destructor Documentation

◆ TextIndex() [1/2]

a11::flow::TextIndex::TextIndex ( )
default

◆ TextIndex() [2/2]

a11::flow::TextIndex::TextIndex ( std::string  text)
explicit

Member Function Documentation

◆ ByteOf()

size_t a11::flow::TextIndex::ByteOf ( size_t  utf16_offset) const

The byte offset that many UTF-16 units into the document.

◆ ByteOfPosition()

size_t a11::flow::TextIndex::ByteOfPosition ( int  line,
int  character 
) const

The byte offset of an LSP position, clamped into the document.

◆ LineCount()

size_t a11::flow::TextIndex::LineCount ( ) const
inline

◆ PositionOf()

std::pair< int, int > a11::flow::TextIndex::PositionOf ( size_t  byte_offset) const

The LSP position – zero-based line, UTF-16 units into it – of a byte offset.

◆ Text()

const std::string & a11::flow::TextIndex::Text ( ) const
inline

◆ Utf16Of()

size_t a11::flow::TextIndex::Utf16Of ( size_t  byte_offset) const

How many UTF-16 units of the document precede this byte offset.


The documentation for this class was generated from the following files: