Code Monkey home page Code Monkey logo

Comments (8)

biojppm avatar biojppm commented on June 12, 2024

Sorry, I don't understand your question. Can you be more specific?

from rapidyaml.

ZhouYe890 avatar ZhouYe890 commented on June 12, 2024
Firstly, I am glad to receive your reply. When I was adding data, I found that data can only be added in the form of one key value pair per row, as shown in the following situation:

NodeOne:
- key: a
desc: b
class: c
number: d
- key: e
desc: f
class: g
number: h
- key: i
desc: j
class: k
number: l
If the data volume is large, it will inevitably increase the number of lines in the configuration file. If data can be added as follows, it will inevitably make the entire file structure clearer.
NodeOne:
- {key: a, desc: b, class: c, number: d}
- {key: e, desc: f, class: g, number: h}
- {key: i, desc: j, class: k, number: l}

from rapidyaml.

biojppm avatar biojppm commented on June 12, 2024

There are some experimental style flags which you can set on the nodes.

For example, after parsing (or after creating the tree), and before emitting, set the flow style for the specific nodes you want:

for(NodeRef child : tree["NodeOne"].children())
    child |= _WIP_STYLE_FLOW_SL;

// now emit. the node will be emitted in single-line flow style
emit(tree);

from rapidyaml.

ZhouYe890 avatar ZhouYe890 commented on June 12, 2024

That's really great. Thank you very much. So how do I save files in this form?

from rapidyaml.

biojppm avatar biojppm commented on June 12, 2024

Use the emit overloads that accept FILE* or the ones that accept streams.

from rapidyaml.

ZhouYe890 avatar ZhouYe890 commented on June 12, 2024

I tried it today, and the content of the original file is
NodeOne:

  • {key: a, desc: b, class: c, number: d}
  • {key: e, desc: f, class: g, number: h}
  • {key: i, desc: j, class: k, number: l}
    Obtained after opening and saving
    NodeOne:
  • key: a
    desc: b
    class: c
    number: d
  • key: e
    desc: f
    class: g
    number: h
  • key: i
    desc: j
    class: k
    number: l
    The code is as follows
    ::FILE *fp = ::fopen(strFileName.c_str(), "r+");
    size_t n_number = ryml::emit_yaml(tree1, fp);
    ::fclose(fp);
    May I ask how I can save the file in its original style. Thank you for taking the time to answer my question.

from rapidyaml.

biojppm avatar biojppm commented on June 12, 2024

The parser does not retain the styles when parsing. That feature will eventually be implemented.

But for now, you have to explicitly mark the nodes with the style you want.

from rapidyaml.

ZhouYe890 avatar ZhouYe890 commented on June 12, 2024

Okay, thank you for your reply.

from rapidyaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.