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
-
#add_datatype_library(r_ns, r_cb_obj) ⇒ nil
add a new datatype library.
-
#characters(r_str) ⇒ Boolean
to be called by SAX characters handler.
-
#end_tag(r_name) ⇒ Boolean
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 parsing a new document.
-
#start_tag(r_name, r_attrs) ⇒ Boolean
to be called by SAX start tag handler.
-
#valid? ⇒ Array<RNV::Error>
is current document valid ?.
Constructor Details
#initialize ⇒ Object
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'ext/rnv/ruby_rnv.c', line 386 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 */ document->text = NULL; rb_iv_set(self, "@errors", rb_ary_new2(0)); rb_iv_set(self, "@libraries", rb_hash_new()); 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
#add_datatype_library(r_ns, r_cb_obj) ⇒ nil
add a new datatype library
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
# File 'ext/rnv/ruby_rnv.c', line 533 VALUE rb_document_add_dtl(VALUE self, VALUE r_ns, VALUE r_cb_obj) { document_t *document; Data_Get_Struct(self, document_t, document); if (document->opened) { Check_Type(r_ns, T_STRING); char *suri = RSTRING_PTR(r_ns); drv_add_dtl(document->rnv, document->drv_st, document->rn_st, suri, &rb_dtl_equal, &rb_dtl_allows); int uri = document->drv_st->dtl[document->drv_st->n_dtl - 1].uri; VALUE libraries = rb_iv_get(self, "@libraries"); rb_hash_aset(libraries, INT2FIX(uri), r_cb_obj); } return Qnil; } |
#characters(r_str) ⇒ Boolean
to be called by SAX characters handler
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
# File 'ext/rnv/ruby_rnv.c', line 587 VALUE rb_document_characters(VALUE self, VALUE r_str) { document_t *document; Data_Get_Struct(self, document_t, document); if (!document->opened) rb_raise(SchemaNotLoaded, "schema was not loaded correctly"); if (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 RTEST(document->ok); } |
#end_tag(r_name) ⇒ Boolean
to be called by SAX end tag handler
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
# File 'ext/rnv/ruby_rnv.c', line 675 VALUE rb_document_end_tag(VALUE self, VALUE r_name) { document_t *document; Data_Get_Struct(self, document_t, document); if (!document->opened) rb_raise(SchemaNotLoaded, "schema was not loaded correctly"); if (document->current != document->rnv->rn_notAllowed) { char *name; Check_Type(r_name, T_STRING); name = RSTRING_PTR(r_name); flush_text(document); 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 RTEST(document->ok); } |
#load_file(r_fn) ⇒ Boolean
load schema from a file
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'ext/rnv/ruby_rnv.c', line 455 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
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'ext/rnv/ruby_rnv.c', line 424 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 parsing a new document
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'ext/rnv/ruby_rnv.c', line 559 VALUE rb_document_begin(VALUE self) { document_t *document; Data_Get_Struct(self, document_t, document); if (!document->opened) rb_raise(SchemaNotLoaded, "schema was not loaded correctly"); // reset errors rb_iv_set(self, "@errors", rb_ary_new2(0)); 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) ⇒ Boolean
to be called by SAX start tag handler
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 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
# File 'ext/rnv/ruby_rnv.c', line 625 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) rb_raise(SchemaNotLoaded, "schema was not loaded correctly"); if (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); // lazyly flatten with ruby VALUE r_flat_attrs = rb_funcall(r_attrs, rb_intern("flatten"), 0); unsigned int attrs_len = RARRAY_LEN(r_flat_attrs); attrs = malloc(sizeof(char *) * (attrs_len + 1)); for (i = 0; i < attrs_len; i++) { attrs[i] = RSTRING_PTR(rb_ary_entry(r_flat_attrs, i)); } attrs[attrs_len] = 0; // zero terminated document->mixed = 1; flush_text(document); 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 RTEST(document->ok); } |
#valid? ⇒ Array<RNV::Error>
is current document valid ?
483 484 485 486 487 488 489 490 491 492 |
# File 'ext/rnv/ruby_rnv.c', line 483 VALUE rb_document_valid(VALUE self) { document_t *document; Data_Get_Struct(self, document_t, document); if (document->ok) return Qtrue; else return Qfalse; } |