<ply-base.h>
namespace ply
Manipulating Text

Plywood provides utility functions for reading and writing text data.

Reading Text

These functions parse common text patterns from input streams.

String read_line(Stream& in)
StringView read_line(ViewStream& view_in)
String read_whitespace(Stream& in)
StringView read_whitespace(ViewStream& in)
void skip_whitespace(Stream& in)
String read_identifier(Stream& in, u32 flags)
StringView read_identifier(ViewStream& view_in, u32 flags)
u64 read_u64_from_text(Stream& in, u32 radix)
s64 read_s64_from_text(Stream& in, u32 radix)
double read_double_from_text(Stream& in, u32 radix)
String read_quoted_string(Stream& in, u32 flags, Functor<void(QS_Error_Code )> error_callback)
String read_line(Streamin)
StringView read_line(ViewStreamview_in)

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

String read_whitespace(Streamin)
StringView read_whitespace(ViewStreamin)

Reads and returns a sequence of whitespace characters.

void skip_whitespace(Streamin)

Consumes whitespace characters without returning them.

String read_identifier(Streamin,  u32 flags)
StringView read_identifier(ViewStreamview_in,  u32 flags)

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

u64 read_u64_from_text(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 read_s64_from_text(Streamin,  u32 radix)

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

double read_double_from_text(Streamin,  u32 radix)

Parses a floating-point number from the stream.

String read_quoted_string(Streamin,  u32 flags,  Functor<void(QS_Error_Code )> error_callback)

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

Writing Text

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

void print_number(Stream& out, u64 value, u32 radix, bool capitalize)
void print_number(Stream& out, s64 value, u32 radix, bool capitalize)
void print_number(Stream& out, u32 value, u32 radix, bool capitalize)
void print_number(Stream& out, s32 value, u32 radix, bool capitalize)
void print_number(Stream& out, double value, u32 radix, bool capitalize)
void print_escaped_string(Stream& out, StringView str)
void print_xml_escaped_string(Stream& out, StringView str)
void print_number(Streamout,  u64 value,  u32 radix,  bool capitalize)
void print_number(Streamout,  s64 value,  u32 radix,  bool capitalize)
void print_number(Streamout,  u32 value,  u32 radix,  bool capitalize)
void print_number(Streamout,  s32 value,  u32 radix,  bool capitalize)
void print_number(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 print_escaped_string(Streamout,  StringView str)

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

void print_xml_escaped_string(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 encode_unicode(FixedArray<char>& buf, UnicodeType unicode_type, u32 codepoint, ExtendedTextParams* ext_params)
DecodeResult decode_unicode(StringView str, UnicodeType unicode_type, ExtendedTextParams* ext_params)
bool encode_unicode(Stream& out, UnicodeType unicode_type, u32 codepoint, ExtendedTextParams* ext_params)
DecodeResult decode_unicode(Stream& in, UnicodeType unicode_type, ExtendedTextParams* ext_params)
u32 encode_unicode(FixedArray<char>& buf,  UnicodeType unicode_type,  u32 codepoint,  ExtendedTextParamsext_params)

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

DecodeResult decode_unicode(StringView str,  UnicodeType unicode_type,  ExtendedTextParamsext_params)

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

bool encode_unicode(Streamout,  UnicodeType unicode_type,  u32 codepoint,  ExtendedTextParamsext_params)

Encodes a Unicode codepoint and writes it to the stream.

DecodeResult decode_unicode(Streamin,  UnicodeType unicode_type,  ExtendedTextParamsext_params)

Decodes a Unicode codepoint from the stream.

Convenience Functions

Character classification functions for common character types.

bool is_whitespace(char c)
bool is_ascii_letter(char c)
bool is_decimal_digit(char c)
bool is_whitespace(char c)

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

bool is_ascii_letter(char c)

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

bool is_decimal_digit(char c)

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