file_content

Defined in header: <orcus/stream.hpp>

class file_content

Represents the content of a file.

The file content is memory-mapped initially, but may later become in-memory if the non-utf-8 content gets converted to utf-8.

Public Functions

file_content(const file_content&) = delete
file_content &operator=(const file_content&) = delete
file_content()
file_content(file_content &&other)
file_content(std::string_view filepath)
file_content(std::u16string_view filepath)
~file_content()
const char *data() const

Obtain the memory address to the first character in the content buffer.

Returns:

pointer to the first character in the buffer.

size_t size() const

Return the size of the content i.e. the number of characters in the content buffer.

Returns:

size of the content.

bool empty() const

Query whether or not the content is empty.

Returns:

true if the content is empty, otherwise false.

void swap(file_content &other)

Swap content with another instance.

Parameters:

other – another instance to swap content with.

void load(std::string_view filepath)

Load from a new file. This will invalidate the pointer returned from the data() method prior to the call.

Parameters:

filepath – path of the file to load from.

void convert_to_utf8()

Convert a non-utf-8 stream to a utf-8 one if the source stream contains a byte order mark. If not, it does nothing. When the conversion happens, the converted content will be stored in-memory.

std::string_view str() const