YamlTextEditor

Changes one value of a YAML text and leaves every other character as it is.

Declared in src/libs/libyaml/yaml/YamlTextEditor.hpp.

Detailed description

A data model that keeps comments must attach each one to a node by a guess, because YAML says comments carry no content. This editor does not guess. It finds the lines of one node through YamlParser::NodeSpan and rewrites those lines only. So comments, blank lines, key order and keys that no reader knows survive every edit (construct-definition-editor §DUM-4).

A path names a node from the root: a QString for a map key, an int for a list index, for example `{"parameters", 2, "max"}`.

The contract, which testLibyaml checks:

  1. No-op is byte-exact: `setValue(p, value(p))` changes nothing.
  2. Locality: after `setValue(p, v)` every line outside the lines of `p` is unchanged.
  3. Round trip: after `setValue(p, v)`, `value(p)` equals `v`, and every other path keeps its value.
  4. Comments survive: only `remove` of a commented key removes a comment.
  5. Indentation follows the document: an inserted key gets the indentation of its siblings, or its parent's plus one level.

A function that cannot find its path returns false and does not change the text. Line ends stay as the text has them, CRLF included. A value is written with the rules of YamlSerializer, so the editor and the serializer write one value the same way.

In this section