Class: Ox::Sax::Value
- Inherits:
-
Object
- Object
- Ox::Sax::Value
- 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
- #as_bool ⇒ Object
- #as_f ⇒ Object
- #as_i ⇒ Object
- #as_s ⇒ Object
- #as_sym ⇒ Object
- #as_time ⇒ Object
- #empty? ⇒ Object
Instance Method Details
#as_bool ⇒ Object
258 259 260 261 262 263 |
# File 'ext/ox/sax_as.c', line 258
static VALUE sax_value_as_bool(VALUE self) {
SaxDrive dr;
TypedData_Get_Struct(self, struct _saxDrive, &ox_sax_value_type, dr);
return (0 == strcasecmp("true", dr->buf.str)) ? Qtrue : Qfalse;
}
|
#as_f ⇒ Object
183 184 185 186 187 188 189 190 191 192 |
# File 'ext/ox/sax_as.c', line 183
static VALUE sax_value_as_f(VALUE self) {
SaxDrive dr;
TypedData_Get_Struct(self, struct _saxDrive, &ox_sax_value_type, dr);
if ('\0' == *dr->buf.str) {
return Qnil;
}
return rb_float_new(strtod(dr->buf.str, 0));
}
|
#as_i ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'ext/ox/sax_as.c', line 198
static VALUE sax_value_as_i(VALUE self) {
SaxDrive dr;
const char *s;
long n = 0;
int neg = 0;
TypedData_Get_Struct(self, struct _saxDrive, &ox_sax_value_type, dr);
s = dr->buf.str;
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_s ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'ext/ox/sax_as.c', line 140
static VALUE sax_value_as_s(VALUE self) {
SaxDrive dr;
VALUE rs;
TypedData_Get_Struct(self, struct _saxDrive, &ox_sax_value_type, dr);
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_sym ⇒ Object
168 169 170 171 172 173 174 175 176 177 |
# File 'ext/ox/sax_as.c', line 168
static VALUE sax_value_as_sym(VALUE self) {
SaxDrive dr;
TypedData_Get_Struct(self, struct _saxDrive, &ox_sax_value_type, dr);
if ('\0' == *dr->buf.str) {
return Qnil;
}
return str2sym(dr, dr->buf.str, strlen(dr->buf.str), 0);
}
|
#as_time ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'ext/ox/sax_as.c', line 233
static VALUE sax_value_as_time(VALUE self) {
SaxDrive dr;
const char *str;
VALUE t;
TypedData_Get_Struct(self, struct _saxDrive, &ox_sax_value_type, dr);
str = dr->buf.str;
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;
}
|
#empty? ⇒ Object
269 270 271 272 273 274 |
# File 'ext/ox/sax_as.c', line 269
static VALUE sax_value_empty(VALUE self) {
SaxDrive dr;
TypedData_Get_Struct(self, struct _saxDrive, &ox_sax_value_type, dr);
return ('\0' == *dr->buf.str) ? Qtrue : Qfalse;
}
|