pantoniou / libfyaml

Fully feature complete YAML parser and emitter, supporting the latest YAML spec and passing the full YAML testsuite.
MIT License
241 stars 74 forks source link

programmable fy_document_scanf() and fy_node_scanf() #31

Closed xunleiwu closed 3 years ago

xunleiwu commented 3 years ago

In https://github.com/pantoniou/libfyaml#usage-and-examples, there is count = fy_document_scanf(fyd, "/invoice %u " "/bill-to/given %256s", &invoice_nr, given); User has to hardcode the key in the _scanf() call. Is there a way to do something like this count = fy_document_scanf(fyd, "%s %u " "%s %256s", key1, &invoice_nr, key2, given);

In the doc page of fy_node_scanf(), https://pantoniou.github.io/libfyaml/libfyaml.html#fy-node-scanf fyn = { foo: 3 } -> fy_node_scanf(fyn, "/foo d", struct var) -> var = 3 Again, user has to hardcode the key, e.g. "/foo", in the _scanf() call. Since fyn has been located already, is there a way to do something like this? fyn = { foo: 3 } -> fy_node_scanf(fyn, "d", struct var) -> var = 3

There is also fy_node_get_scalar() API which returns a char*. Are there API's to get numeric values?

Thank you very much for the insight.

pantoniou commented 3 years ago

You can certainly use any string as input to the scanf methods.

for instance:

        char fmt[256];

        snprintf(fmt, sizeof(fmt), "%s %%d", "key");

        printf("fmt is \"%s\"\n", fmt);

atoi(fy_node_get_scalar() ? : "0")