Header file:<ply-base.h>Namespace:plyManipulating Text

Plywood provides utility functions for reading and writing text data.

Reading Text

These functions parse common text patterns from input streams.

String readLine(Stream& in)
StringView readLine(ViewStream& viewIn)
String readWhitespace(Stream& in)
StringView readWhitespace(ViewStream& in)
void skipWhitespace(Stream& in)
String readIdentifier(Stream& in, u32 flags)
StringView readIdentifier(ViewStream& viewIn, u32 flags)
u64 readU64FromText(Stream& in, u32 radix)
s64 readS64FromText(Stream& in, u32 radix)
double readDoubleFromText(Stream& in, u32 radix)
String readQuotedString(Stream& in, u32 flags, Functor<void(QS_Error_Code )> errorCallback)
String readLine(Streamin)
StringView readLine(ViewStreamviewIn)

Reads characters until a newline or end-of-file. The newline character is consumed but not included in the result.

String readWhitespace(Streamin)
StringView readWhitespace(ViewStreamin)

Reads and returns a sequence of whitespace characters.

void skipWhitespace(Streamin)

Consumes whitespace characters without returning them.

String readIdentifier(Streamin,  u32 flags)
StringView readIdentifier(ViewStreamviewIn,  u32 flags)

Reads a C-style identifier (letters, digits, underscores, starting with a non-digit).

u64 readU64FromText(Streamin,  u32 radix)

Parses an unsigned integer from the stream. The radix parameter specifies the number base (e.g., 10 for decimal, 16 for hexadecimal).

s64 readS64FromText(Streamin,  u32 radix)

Parses a signed integer from the stream. Handles optional leading - sign.

double readDoubleFromText(Streamin,  u32 radix)

Parses a floating-point number from the stream.

String readQuotedString(Streamin,  u32 flags,  Functor<void(QS_Error_Code )> errorCallback)

Reads a quoted string, handling escape sequences. The opening quote must already be consumed. Calls errorCallback if parsing fails.

Writing Text

While Stream::format handles most formatting needs, these functions provide finer control over number formatting and string escaping.

void printNumber(Stream& out, u64 value, u32 radix, bool capitalize)
void printNumber(Stream& out, s64 value, u32 radix, bool capitalize)
void printNumber(Stream& out, u32 value, u32 radix, bool capitalize)
void printNumber(Stream& out, s32 value, u32 radix, bool capitalize)
void printNumber(Stream& out, double value, u32 radix, bool capitalize)
void printEscapedString(Stream& out, StringView str)
void printXmlEscapedString(Stream& out, StringView str)
void printNumber(Streamout,  u64 value,  u32 radix,  bool capitalize)
void printNumber(Streamout,  s64 value,  u32 radix,  bool capitalize)
void printNumber(Streamout,  u32 value,  u32 radix,  bool capitalize)
void printNumber(Streamout,  s32 value,  u32 radix,  bool capitalize)
void printNumber(Streamout,  double value,  u32 radix,  bool capitalize)

Writes a number to the stream. Use radix to specify the base (e.g., 16 for hexadecimal). Set capitalize to true for uppercase hex digits.

void printEscapedString(Streamout,  StringView str)

Writes a string with C-style escape sequences for special characters (e.g., \n, \t, \\).

void printXmlEscapedString(Streamout,  StringView str)

Writes a string with XML entity escaping (e.g., &lt;, &gt;, &amp;).

Converting Unicode

These functions convert between Unicode codepoints and various encoded representations (UTF-8, UTF-16, etc.).

u32 encodeUnicode(FixedArray<char>& buf, UnicodeType unicodeType, u32 codepoint, ExtendedTextParams* extParams)
DecodeResult decodeUnicode(StringView str, UnicodeType unicodeType, ExtendedTextParams* extParams)
bool encodeUnicode(Stream& out, UnicodeType unicodeType, u32 codepoint, ExtendedTextParams* extParams)
DecodeResult decodeUnicode(Stream& in, UnicodeType unicodeType, ExtendedTextParams* extParams)
u32 encodeUnicode(FixedArray<char>& buf,  UnicodeType unicodeType,  u32 codepoint,  ExtendedTextParamsextParams)

Encodes a Unicode codepoint into the specified encoding. Returns the number of bytes written to buf.

DecodeResult decodeUnicode(StringView str,  UnicodeType unicodeType,  ExtendedTextParamsextParams)

Decodes a Unicode codepoint from the beginning of str. Returns the codepoint and number of bytes consumed.

bool encodeUnicode(Streamout,  UnicodeType unicodeType,  u32 codepoint,  ExtendedTextParamsextParams)

Encodes a Unicode codepoint and writes it to the stream.

DecodeResult decodeUnicode(Streamin,  UnicodeType unicodeType,  ExtendedTextParamsextParams)

Decodes a Unicode codepoint from the stream.

Convenience Functions

Character classification functions for common character types.

bool isWhitespace(char c)
bool isAsciiLetter(char c)
bool isDecimalDigit(char c)
bool isWhitespace(char c)

Returns true if c is a whitespace character (space, tab, newline, etc.).

bool isAsciiLetter(char c)

Returns true if c is an ASCII letter (a-z or A-Z).

bool isDecimalDigit(char c)

Returns true if c is a decimal digit (0-9).