Class: Ox::Sax::Value

Inherits:
Object
  • Object
show all
Defined in:
ext/ox/sax_as.c,
ext/ox/sax_as.c

Overview

Values in the SAX callbacks. They can be converted to various different types. with the _as_x()_ methods.

Instance Method Summary collapse

Instance Method Details

#as_boolObject

return value as an boolean.



214
215
216
# File 'ext/ox/sax_as.c', line 214

static VALUE sax_value_as_bool(VALUE self) {
    return (0 == strcasecmp("true", ((SaxDrive)DATA_PTR(self))->buf.str)) ? Qtrue : Qfalse;
}

#as_fObject

return value as an Float.



147
148
149
150
151
152
153
154
# File 'ext/ox/sax_as.c', line 147

static VALUE sax_value_as_f(VALUE self) {
    SaxDrive dr = DATA_PTR(self);

    if ('\0' == *dr->buf.str) {
        return Qnil;
    }
    return rb_float_new(strtod(dr->buf.str, 0));
}

#as_iObject

return value as an Fixnum.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'ext/ox/sax_as.c', line 160

static VALUE sax_value_as_i(VALUE self) {
    SaxDrive    dr  = DATA_PTR(self);
    const char *s   = dr->buf.str;
    long        n   = 0;
    int         neg = 0;

    if ('\0' == *s) {
        return Qnil;
    }
    if ('-' == *s) {
        neg = 1;
        s++;
    } else if ('+' == *s) {
        s++;
    }
    for (; '\0' != *s; s++) {
        if ('0' <= *s && *s <= '9') {
            n = n * 10 + (*s - '0');
        } else {
            rb_raise(ox_arg_error_class, "Not a valid Fixnum.\n");
        }
    }
    if (neg) {
        n = -n;
    }
    return LONG2NUM(n);
}

#as_sObject

return value as an String.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'ext/ox/sax_as.c', line 108

static VALUE sax_value_as_s(VALUE self) {
    SaxDrive dr = DATA_PTR(self);
    VALUE    rs;

    if ('\0' == *dr->buf.str) {
        return Qnil;
    }
    if (dr->options.convert_special) {
        ox_sax_collapse_special(dr, dr->buf.str, dr->buf.pos, dr->buf.line, dr->buf.col);
    }
    switch (dr->options.skip) {
    case CrSkip: buf_collapse_return(dr->buf.str); break;
    case SpcSkip: buf_collapse_white(dr->buf.str); break;
    default: break;
    }
    rs = rb_str_new2(dr->buf.str);
    if (0 != dr->encoding) {
        rb_enc_associate(rs, dr->encoding);
    }
    return rs;
}

#as_symObject

return value as an Symbol.



134
135
136
137
138
139
140
141
# File 'ext/ox/sax_as.c', line 134

static VALUE sax_value_as_sym(VALUE self) {
    SaxDrive dr = DATA_PTR(self);

    if ('\0' == *dr->buf.str) {
        return Qnil;
    }
    return str2sym(dr, dr->buf.str, strlen(dr->buf.str), 0);
}

#as_timeObject

return value as an Time.



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'ext/ox/sax_as.c', line 192

static VALUE sax_value_as_time(VALUE self) {
    SaxDrive    dr  = DATA_PTR(self);
    const char *str = dr->buf.str;
    VALUE       t;

    if ('\0' == *str) {
        return Qnil;
    }
    if (Qnil == (t = parse_double_time(str)) && Qnil == (t = parse_xsd_time(str))) {
        VALUE args[1];

        /*printf("**** time parse\n"); */
        *args = rb_str_new2(str);
        t     = rb_funcall2(ox_time_class, ox_parse_id, 1, args);
    }
    return t;
}

#emptyBoolean

return true if the value is empty.

Returns:

  • (Boolean)


222
223
224
# File 'ext/ox/sax_as.c', line 222

static VALUE sax_value_empty(VALUE self) {
    return ('\0' == *((SaxDrive)DATA_PTR(self))->buf.str) ? Qtrue : Qfalse;
}