Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- `LottieReader::parseFile()`, `parseData()`, `parseStream()`, and `parseFromZip()` now return `ResultValue<AnimationComposition::Ptr>` and no longer take a trailing `String* outError` out-parameter; check `wasOk()`/`failed()` and read the message via `getErrorMessage()`.
- `AnimationFrameExporter` is now an instance-based class bound to a `GraphicsContext` (construct `AnimationFrameExporter exporter (ctx);` then call `exporter.renderFrame(anim, …)` / `exporter.renderAllFrames(…)` / `exporter.exportToGif(anim, …)`), so it can own and reuse the GPU matte-composite pipeline across frames instead of recompiling it per frame. The `exportToGif(frames, frameRate, …)` frame-sequence encoder remains a static helper.

### Core

- Added a `YAML` class: a self-contained YAML parser and writer converting between YAML text and `var` (`parse`, `fromString`, `toString`, `writeToStream`, `FormatOptions`), with core-schema type resolution, block/flow collections, block scalars, and anchors/aliases/merge keys

### Graphics

- Added a native WebGPU `GraphicsContext` backend for Emscripten via the Emdawnwebgpu port (`RIVE_WEBGPU=2` + `--use-port=emdawnwebgpu`, enabled with the `ENABLE_EMSCRIPTEN_WEBGPU` parameter of `yup_standalone_app`), rendering Rive content through the browser's WebGPU API without Dawn
Expand Down
57 changes: 57 additions & 0 deletions docs/core/data-interchange.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,63 @@ Related helpers:
`JSON::parse` accepts only a valid JSON object or array at the top level.
```

## YAML

The `YAML` class converts between YAML text and `var`, mirroring the `JSON`
interface: `parse` (with `Result` error detail), `fromString`, `toString` and
`writeToStream`, plus `FormatOptions` to choose spacing style and number
precision.

```cpp
var parsed = YAML::parse (yamlText); // var() on failure
Result r = YAML::parse (yamlText, result); // error detail with line numbers
String text = YAML::toString (parsed); // block style by default
String flow = YAML::toString (parsed, YAML::FormatOptions {}.withSpacing (YAML::Spacing::singleLine));
String none = YAML::toString (parsed, YAML::FormatOptions {}.withSpacing (YAML::Spacing::none));
```

### Supported features

**Type resolution** according to the YAML core schema:

- `null`, `~` → void
- `true`/`false`, `yes`/`no`, `on`/`off`, `y`/`n` (case-insensitive) → bool
- Integers: decimal, hex (`0x1F`), octal (`0o17`), with `_` separators (`1_000`)
- Floats: `3.14`, `1e5`, `1.5e-3`, `.5`, `1.`; `.inf`/`-.inf`, `.nan`
- Strings: plain, single-quoted, double-quoted scalars

**Collections:** block (`key: value`, `- item`) and flow (`{a: 1}`, `[1, 2]`)
with arbitrary nesting.

**Block scalars:** literal (`|`) and folded (`>`) with chomping indicators
(`-`/`+`) and explicit indentation (`|2`).

**Anchors, aliases, and merge keys:** `&anchor` defines an anchor on any node,
`*anchor` dereferences it (deep-copied into the result), and `<<: *anchor`
merges mapped values in a YAML 1.1-compatible way.

**Quoted string utilities:** `escapeString` escapes a string for double-quoted
YAML output; `parseQuotedString` parses a quoted YAML scalar from a raw
character pointer.

### Error handling and safety

`YAML::parse(text, result)` returns a `Result` with line-numbered error messages
for malformed input. The parser enforces:

- Maximum nesting depth of 512 to prevent stack overflow
- Cyclic alias detection (`&a [*a]` is rejected)
- Duplicate anchor detection (`&a 1\n&a 2` is rejected)

```{note}
`YAML::parse` accepts only a valid YAML mapping or sequence at the top level.
Use `YAML::fromString` to parse plain scalars, booleans, or numbers. Custom
tags, multi-document streams (`---`/`...`), and the merge key `<<` in a quoted
context are not supported. The writer never emits anchors, aliases or merge
keys; YAML 1.1 boolean spellings (`yes`/`no`/`on`/`off`/`y`/`n`) are
recognised on input but emitted as quoted strings to ensure unambiguous
interop.

## XML

`yup_core` ships a small, self-contained XML DOM: `XmlElement` (a mutable node)
Expand Down
8 changes: 6 additions & 2 deletions modules/yup_core/javascript/yup_JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,12 @@ struct JSONParser
throwError ("Expected a property name in double-quotes", errorLocation);

errorLocation = currentLocation;
Identifier propertyName (parseString ('"'));

auto propertyString = parseString ('"');
if (propertyString.isEmpty())
throwError ("Property name cannot be empty", errorLocation);

auto propertyName = Identifier (propertyString);
if (! propertyName.isValid())
throwError ("Invalid property name", errorLocation);

Expand Down Expand Up @@ -418,7 +422,7 @@ struct JSONFormatter
break;

default:
if (c >= 32 && c < 127)
if (CharacterFunctions::isAsciiPrintable (c))
{
out << (char) c;
}
Expand Down
10 changes: 10 additions & 0 deletions modules/yup_core/text/yup_CharacterFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@ bool CharacterFunctions::isPrintable (const yup_wchar character) noexcept
return iswprint ((wint_t) character) != 0;
}

bool CharacterFunctions::isAsciiPrintable (const yup_wchar character) noexcept
{
return character >= 32 && character < 127;
}

bool CharacterFunctions::isControlCharacter (const yup_wchar character) noexcept
{
return character < 0x20 || character == 0x7f;
}

int CharacterFunctions::getHexDigitValue (const yup_wchar digit) noexcept
{
auto d = (unsigned int) (digit - '0');
Expand Down
6 changes: 6 additions & 0 deletions modules/yup_core/text/yup_CharacterFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ class YUP_API CharacterFunctions
*/
static bool isPrintable (yup_wchar character) noexcept;

/** Checks whether a character is a printable ASCII character (codes 32–126 inclusive). */
static bool isAsciiPrintable (yup_wchar character) noexcept;

/** Checks whether a character is an ASCII control character (codes 0–31 or 127). */
static bool isControlCharacter (yup_wchar character) noexcept;

/** Returns 0 to 16 for '0' to 'F", or -1 for characters that aren't a legal hex digit. */
static int getHexDigitValue (yup_wchar digit) noexcept;

Expand Down
Loading
Loading