Get Involved

TextFormat

The TextFormat class provides functionality to load and save text files in various file formats. It supports UTF-8, UTF-16, optional byte order marks (BOM), and either Unix or Windows-style newlines.

All text loaded through TextFormat is converted to UTF-8 with Unix-style newlines and no byte order mark (BOM).

For more information, see Unicode Support.

Header File

#include <ply-runtime/io/text/TextFormat.h>

Data Members

 Encoding encoding [code]

Possible values are Bytes, UTF8, UTF16_be and UTF16_le.

 NewLine newLine [code]

Possible values are LF and CRLF.

 bool bom [code]

Whether the text begins with a byte order mark (BOM).

Member Functions

 static TextFormat TextFormat::unixUTF8() [code]

Returns a TextFormat with UTF8, LF and no BOM.

 static TextFormat TextFormat::platformPreference() [code]

Returns a default TextFormat according to the host platform. On Windows, the default is UTF8, CRLF and no BOM. On Linux and macOS, the default is UTF8, LF and no BOM.

 static TextFormat TextFormat::autodetect(InStream* ins) [code]

Attempts to guess the text file format of the contents of ins. This function reads up to 4 KB of data from ins, then rewinds it back to the beginning using InStream::rewind().

 Owned<InStream> TextFormat::createImporter(OptionallyOwned<InStream>&& ins) const [code]

Creates a new InStream that converts the raw contents of ins to UTF-8 with Unix-style newlines and no byte order mark (BOM). The contents of ins are expected to have the format described by the provided TextFormat object. Conversion is performed on-the-fly while data is being read.

[FIXME: Say something here about OptionallyOwned.]

 Owned<OutStream> TextFormat::createExporter(OptionallyOwned<OutStream>&& outs) const [code]

Creates a new OutStream that writes raw data to outs in the format described by the provided TextFormat object. The resulting OutStream object expects UTF-8-encoded text. The OutStream accepts both Windows and Unix-style newlines; all newlines will be converted to the format described by the provided TextFormat object. Conversion is performed on-the-fly while data is written.

bool TextFormat::operator==(const TextFormat& other) const [code]

Returns true if the TextFormats are identical.