Class: JQ::Core

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

Instance Method Summary collapse

Instance Method Details

#closeObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'ext/jq_core.c', line 72

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;
    p->errmsg = Qnil;
  }

  return Qnil;
}

#update(buf, v_is_partial) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'ext/jq_core.c', line 127

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;
}