Class: RNV::Document
- Inherits:
-
Object
- Object
- RNV::Document
- Defined in:
- ext/rnv/ruby_rnv.c
Instance Attribute Summary collapse
-
#errors ⇒ Array<RNV::Error>
errors from current document.
-
#last_col ⇒ Integer
last column processed, set by SAX handler.
-
#last_line ⇒ Integer
last line processed, set by SAX handler.
Instance Method Summary collapse
-
#characters(r_str) ⇒ Integer
to be called by SAX characters handler.
-
#end_tag(r_name) ⇒ Integer
to be called by SAX end tag handler.
- #initialize ⇒ Object constructor
-
#load_file(r_fn) ⇒ Boolean
load schema from a file.
-
#load_string(r_str) ⇒ Boolean
load schema from a buffer.
-
#start_document ⇒ nil
begin a new document.
-
#start_tag(r_name, r_attrs) ⇒ Integer
to be called by SAX start tag handler.
-
#valid? ⇒ Array<RNV::Error>
is current document valid ?.
Constructor Details
#initialize ⇒ Object
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'ext/rnv/ruby_rnv.c', line 440
VALUE rb_document_init(VALUE self)
{
document_t *document;
Data_Get_Struct(self, document_t, document);
rnl_init(document->rnv, document->rn_st, document->rnc_st, document->rnd_st);
rnv_init(document->rnv, document->drv_st, document->rn_st, document->rx_st);
rnx_init(document->rnv, document->rnx_st);
document->opened = document->ok = 0;
document->rnv->user_data = (void *)self;
document->rnv->verror_handler = &ruby_verror_handler;
document->nexp = 16; /* maximum number of candidates to display */
rb_iv_set(self, "@errors", rb_ary_new2(0));
return self;
}
|
Instance Attribute Details
#errors ⇒ Array<RNV::Error>
errors from current document
#last_col ⇒ Integer
last column processed, set by SAX handler
#last_line ⇒ Integer
last line processed, set by SAX handler
Instance Method Details
#characters(r_str) ⇒ Integer
to be called by SAX characters handler
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'ext/rnv/ruby_rnv.c', line 579
VALUE rb_document_characters(VALUE self, VALUE r_str)
{
document_t *document;
Data_Get_Struct(self, document_t, document);
if (document->opened && document->current != document->rnv->rn_notAllowed)
{
Check_Type(r_str, T_STRING);
char *s = RSTRING_PTR(r_str);
int len = RSTRING_LEN(r_str);
int newlen_txt = document->n_txt + len + 1;
if (newlen_txt <= LIM_T && LIM_T < document->len_txt)
newlen_txt = LIM_T;
else if (newlen_txt < document->len_txt)
newlen_txt = document->len_txt;
if (document->len_txt != newlen_txt)
{
document->text = (char *)m_stretch(document->text, document->len_txt = newlen_txt, document->n_txt, sizeof(char));
}
memcpy(document->text + document->n_txt, s, len);
document->n_txt += len;
document->text[document->n_txt] = '\0'; /* '\0' guarantees that the text is bounded, and strto[ld] work for data */
}
return INT2NUM(document->ok);
}
|
#end_tag(r_name) ⇒ Integer
to be called by SAX end tag handler
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
# File 'ext/rnv/ruby_rnv.c', line 659
VALUE rb_document_end_tag(VALUE self, VALUE r_name)
{
document_t *document;
Data_Get_Struct(self, document_t, document);
if (document->opened && document->current != document->rnv->rn_notAllowed)
{
char *name;
Check_Type(r_name, T_STRING);
name = RSTRING_PTR(r_name);
flush_text(document);
//printf("RNV END %d/%d %s\n", current, previous, name);
document->ok = rnv_end_tag(document->rnv, document->drv_st, document->rn_st,
&document->current, &document->previous, (char *)name) &&
document->ok;
document->mixed = 1;
}
return INT2NUM(document->ok);
}
|
#load_file(r_fn) ⇒ Boolean
load schema from a file
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'ext/rnv/ruby_rnv.c', line 506
VALUE rb_document_load_file(VALUE self, VALUE r_fn)
{
document_t *document;
Data_Get_Struct(self, document_t, document);
Check_Type(r_fn, T_STRING);
document->fn = RSTRING_PTR(r_fn);
document->opened = rnl_fn(document->rnv,
document->rnc_st,
document->rn_st,
document->rnd_st,
document->fn);
if (document->opened)
{
document_load(document);
return Qtrue;
}
else
return Qfalse;
}
|
#load_string(r_str) ⇒ Boolean
load schema from a buffer
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'ext/rnv/ruby_rnv.c', line 475
VALUE rb_document_load_string(VALUE self, VALUE r_str)
{
document_t *document;
Data_Get_Struct(self, document_t, document);
Check_Type(r_str, T_STRING);
VALUE r_fn = rb_str_new2("");
document->fn = RSTRING_PTR(r_fn);
document->opened = rnl_s(document->rnv,
document->rnc_st,
document->rn_st,
document->rnd_st,
document->fn,
RSTRING_PTR(r_str), RSTRING_LEN(r_str));
if (document->opened)
{
document_load(document);
return Qtrue;
}
else
return Qfalse;
}
|
#start_document ⇒ nil
begin a new document
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
# File 'ext/rnv/ruby_rnv.c', line 557
VALUE rb_document_begin(VALUE self)
{
document_t *document;
Data_Get_Struct(self, document_t, document);
m_free(document->text);
document->text = (char *)m_alloc(document->len_txt = LEN_T, sizeof(char));
document->ok = document->current = document->previous = document->start;
document->text[0] = '\0';
document->n_txt = 0;
document->mixed = 0;
return Qnil;
}
|
#start_tag(r_name, r_attrs) ⇒ Integer
to be called by SAX start tag handler
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 |
# File 'ext/rnv/ruby_rnv.c', line 614
VALUE rb_document_start_tag(VALUE self, VALUE r_name, VALUE r_attrs)
{
document_t *document;
Data_Get_Struct(self, document_t, document);
if (document->opened && document->current != document->rnv->rn_notAllowed)
{
int i;
char *name;
char **attrs;
Check_Type(r_name, T_STRING);
name = RSTRING_PTR(r_name);
Check_Type(r_attrs, T_ARRAY);
unsigned int attrs_len = RARRAY_LEN(r_attrs);
attrs = malloc(sizeof(char *) * (attrs_len + 1));
for (i = 0; i < attrs_len; i++)
{
attrs[i] = RSTRING_PTR(rb_ary_entry(r_attrs, i));
}
attrs[attrs_len] = 0; // zero terminated
document->mixed = 1;
flush_text(document);
//printf("RNV START %d/%d %s %d\n", current, previous, name, attrs_len);
document->ok = rnv_start_tag(document->rnv, document->drv_st, document->rn_st, document->rx_st,
&document->current, &document->previous, (char *)name, (char **)attrs) &&
document->ok;
document->mixed = 0;
free(attrs);
}
return INT2NUM(document->ok);
}
|
#valid? ⇒ Array<RNV::Error>
is current document valid ?
534 535 536 537 538 539 540 541 542 543 |
# File 'ext/rnv/ruby_rnv.c', line 534
VALUE rb_document_valid(VALUE self)
{
document_t *document;
Data_Get_Struct(self, document_t, document);
if (document->ok)
return Qtrue;
else
return Qfalse;
}
|