Re: Basic question about scalar types and libyaml
William Spitzak <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <[email protected]> |
You can detect if the scalar is quoted with:
yaml_parser_parse(yaml, event);
if (event->type == YAML_SCALAR_EVENT) {
quoted = event->data.scalar.style != YAML_PLAIN_SCALAR_STYLE;
}
If it is quoted then it is *not* a float or bool, etc.
When writing with libyaml, it apparently is your responsibility to check
any strings you write and turn quoting on if there is any possibility
that they will be confused with float or other types. I have not done
this as it does not happen in my case. I don't know how you do this, as
I am not using libyaml to write the files anymore, I wrote my own output
routines that produce flow-format only.
Neil N. Carlson wrote:
> I'm investigating the feasibility of moving the input format
> for a large scientific code to some standard XML-like format,
> and found YAML/JSON to be very appealing possibilities. I'm
> playing around with libyaml and have a very basic question
> about scalar types. The wikipedia page on YAML (perhaps my
> first mistake) describes autodetection of simple types (int,
> float, bool, string) as a compelling feature, yet it appears
> to me that libyaml returns all data as strings. I thought
> I could work around that by looking at the tag attribute but
> that turns out to be null, unless I explicitly give a tag
> in the input file. So it appears that libyaml isn't doing
> any autodetection of type at all. Have I missed something?
> It seems that I would need to write things like
> [ !!float 1.0, !!float 1.0e3 ] instead of the more natural
> [ 1.0, 1.0e3 ].
>
> Thanks for your advice,
> Neil
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev