Class: JQ::Core

Inherits:
Object
  • Object
show all
Defined in:
ext/jq_core.c

Instance Method Summary collapse

Instance Method Details

#closeObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'ext/jq_core.c', line 45

static VALUE rb_jq_close(VALUE self) {
  struct jq_container *p;
  Data_Get_Struct(self, struct jq_container, p);

  if (!p->closed) {
    jq_teardown(&p->jq);
    p->jq = NULL;
    p->parser = NULL;
    p->closed = 1;
  }

  return Qnil;
}

#update(buf, v_is_partial) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'ext/jq_core.c', line 99

static VALUE rb_jq_update(VALUE self, VALUE buf, VALUE v_is_partial) {
  struct jq_container *p;
  int is_partial = v_is_partial ? 1 : 0;
  int status = 0;
  VALUE errmsg = Qnil;

  if (!rb_block_given_p()) {
    rb_raise(rb_eArgError, "no block given");
  }

  Data_Get_Struct(self, struct jq_container, p);
  Check_Type(buf, T_STRING);

  if (!p->parser) {
    p->parser = jv_parser_new(0);
  }

  jv_parser_set_buf(p->parser, RSTRING_PTR(buf), RSTRING_LEN(buf), is_partial);
  jq_parse(p->jq, p->parser, rb_yield, &status, &errmsg);

  if (!is_partial) {
    jv_parser_free(p->parser);
    p->parser = NULL;
  }

  if (status != 0) {
    rb_jump_tag(status);
  }

  if (!NIL_P(errmsg)) {
    rb_raise(rb_eJQ_Error, "%s", RSTRING_PTR(errmsg));
  }

  return Qnil;
}