[macruby-changes] [2542] MacRuby/trunk/ext/libyaml/rubyext.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Sep 10 16:37:58 PDT 2009
Revision: 2542
http://trac.macosforge.org/projects/ruby/changeset/2542
Author: lsansonetti at apple.com
Date: 2009-09-10 16:37:54 -0700 (Thu, 10 Sep 2009)
Log Message:
-----------
fixed yaml deserialization of integers and floats
Modified Paths:
--------------
MacRuby/trunk/ext/libyaml/rubyext.c
Modified: MacRuby/trunk/ext/libyaml/rubyext.c
===================================================================
--- MacRuby/trunk/ext/libyaml/rubyext.c 2009-09-10 23:11:55 UTC (rev 2541)
+++ MacRuby/trunk/ext/libyaml/rubyext.c 2009-09-10 23:37:54 UTC (rev 2542)
@@ -341,11 +341,34 @@
return collect ? (VALUE)CFMakeCollectable((CFTypeRef)result) : result;
}
+static inline bool
+is_numeric(const char *str, bool *has_point)
+{
+ char c;
+ bool point = false;
+ while ((c = *str++) != '\0') {
+ if (!isdigit(c)) {
+ if (c == '.') {
+ if (point) {
+ return false;
+ }
+ point = true;
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ *has_point = point;
+ return true;
+}
+
static VALUE
handle_scalar(rb_yaml_parser_t *parser)
{
char *val = (char*)parser->event.data.scalar.value;
char *tag = (char*)parser->event.data.scalar.tag;
+ bool has_point = false;
if (parser->event.data.scalar.style == YAML_PLAIN_SCALAR_STYLE
&& tag == NULL) {
if (parser->event.data.scalar.length == 0) {
@@ -354,9 +377,10 @@
else if (*val == ':') {
tag = "tag:ruby.yaml.org,2002:symbol";
}
- else if (strtol(val, NULL, 10) != 0) {
- // TODO use rb_str_to_inum
- tag = "tag:yaml.org,2002:int";
+ else if (is_numeric(val, &has_point)) {
+ tag = has_point
+ ? "tag:yaml.org,2002:float"
+ : "tag:yaml.org,2002:int";
}
else if (strcmp(val, "true") == 0) {
tag = "tag:yaml.org,2002:true";
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090910/cf2d5cc7/attachment.html>
More information about the macruby-changes
mailing list