nokolexbor 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/nokolexbor/CMakeLists.txt +92 -0
- data/ext/nokolexbor/config.h.cmake.in +26 -0
- data/ext/nokolexbor/extconf.rb +17 -8
- data/ext/nokolexbor/libxml/{xmlversion.h → xmlversion.h.in} +41 -41
- data/ext/nokolexbor/nl_document.c +12 -4
- data/ext/nokolexbor/nl_node.c +66 -56
- data/ext/nokolexbor/nl_node_set.c +43 -22
- data/ext/nokolexbor/nl_xpath_context.c +78 -18
- data/ext/nokolexbor/nokolexbor.h +2 -0
- data/ext/nokolexbor/xml_error.c +225 -27
- data/lib/nokolexbor/node.rb +2 -2
- data/lib/nokolexbor/node_set.rb +5 -1
- data/lib/nokolexbor/version.rb +1 -1
- data/lib/nokolexbor/xpath.rb +69 -0
- data/lib/nokolexbor.rb +1 -0
- metadata +26 -9
- data/ext/nokolexbor/config.h +0 -186
@@ -7,9 +7,13 @@
|
|
7
7
|
#include "libxml/xpathInternals.h"
|
8
8
|
#include "libxml/parserInternals.h"
|
9
9
|
|
10
|
+
#define RBSTR_OR_QNIL(_str) (_str ? rb_utf8_str_new_cstr(_str) : Qnil)
|
11
|
+
|
10
12
|
extern VALUE mNokolexbor;
|
11
13
|
extern VALUE cNokolexborNodeSet;
|
12
|
-
VALUE
|
14
|
+
VALUE cNokolexborXpathContext;
|
15
|
+
VALUE mNokolexborXpath;
|
16
|
+
VALUE cNokolexborXpathSyntaxError;
|
13
17
|
|
14
18
|
static void
|
15
19
|
free_xml_xpath_context(xmlXPathContextPtr ctx)
|
@@ -24,7 +28,7 @@ free_xml_xpath_context(xmlXPathContextPtr ctx)
|
|
24
28
|
* Register the namespace with +prefix+ and +uri+.
|
25
29
|
*/
|
26
30
|
static VALUE
|
27
|
-
|
31
|
+
nl_xpath_context_register_ns(VALUE self, VALUE prefix, VALUE uri)
|
28
32
|
{
|
29
33
|
xmlXPathContextPtr ctx;
|
30
34
|
Data_Get_Struct(self, xmlXPathContext, ctx);
|
@@ -42,7 +46,7 @@ rb_xml_xpath_context_register_ns(VALUE self, VALUE prefix, VALUE uri)
|
|
42
46
|
* Register the variable +name+ with +value+.
|
43
47
|
*/
|
44
48
|
static VALUE
|
45
|
-
|
49
|
+
nl_xpath_context_register_variable(VALUE self, VALUE name, VALUE value)
|
46
50
|
{
|
47
51
|
xmlXPathContextPtr ctx;
|
48
52
|
xmlXPathObjectPtr xmlValue;
|
@@ -69,7 +73,7 @@ xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr ctx, VALUE rb_do
|
|
69
73
|
switch (c_xpath_object->type)
|
70
74
|
{
|
71
75
|
case XPATH_STRING:
|
72
|
-
rb_retval = rb_utf8_str_new_cstr(c_xpath_object->stringval);
|
76
|
+
rb_retval = rb_utf8_str_new_cstr((const char *)c_xpath_object->stringval);
|
73
77
|
xmlFree(c_xpath_object->stringval);
|
74
78
|
return rb_retval;
|
75
79
|
|
@@ -106,6 +110,60 @@ xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr ctx, VALUE rb_do
|
|
106
110
|
}
|
107
111
|
}
|
108
112
|
|
113
|
+
static VALUE
|
114
|
+
nl_xpath_wrap_syntax_error(xmlErrorPtr error)
|
115
|
+
{
|
116
|
+
VALUE msg, e;
|
117
|
+
|
118
|
+
msg = (error && error->message) ? rb_utf8_str_new_cstr(error->message) : Qnil;
|
119
|
+
|
120
|
+
e = rb_class_new_instance(
|
121
|
+
1,
|
122
|
+
&msg,
|
123
|
+
cNokolexborXpathSyntaxError);
|
124
|
+
|
125
|
+
if (error)
|
126
|
+
{
|
127
|
+
rb_iv_set(e, "@domain", INT2NUM(error->domain));
|
128
|
+
rb_iv_set(e, "@code", INT2NUM(error->code));
|
129
|
+
rb_iv_set(e, "@level", INT2NUM((short)error->level));
|
130
|
+
rb_iv_set(e, "@file", RBSTR_OR_QNIL(error->file));
|
131
|
+
rb_iv_set(e, "@line", INT2NUM(error->line));
|
132
|
+
rb_iv_set(e, "@str1", RBSTR_OR_QNIL(error->str1));
|
133
|
+
rb_iv_set(e, "@str2", RBSTR_OR_QNIL(error->str2));
|
134
|
+
rb_iv_set(e, "@str3", RBSTR_OR_QNIL(error->str3));
|
135
|
+
rb_iv_set(e, "@int1", INT2NUM(error->int1));
|
136
|
+
rb_iv_set(e, "@column", INT2NUM(error->int2));
|
137
|
+
}
|
138
|
+
|
139
|
+
return e;
|
140
|
+
}
|
141
|
+
|
142
|
+
static void nl_xpath_error_array_pusher(void *ctx, xmlErrorPtr error)
|
143
|
+
{
|
144
|
+
VALUE list = (VALUE)ctx;
|
145
|
+
Check_Type(list, T_ARRAY);
|
146
|
+
rb_ary_push(list, nl_xpath_wrap_syntax_error(error));
|
147
|
+
}
|
148
|
+
|
149
|
+
static void
|
150
|
+
nl_xpath_generic_exception_pusher(void *ctx, const char *msg, ...)
|
151
|
+
{
|
152
|
+
VALUE rb_errors = (VALUE)ctx;
|
153
|
+
VALUE rb_message;
|
154
|
+
VALUE rb_exception;
|
155
|
+
|
156
|
+
Check_Type(rb_errors, T_ARRAY);
|
157
|
+
|
158
|
+
va_list args;
|
159
|
+
va_start(args, msg);
|
160
|
+
rb_message = rb_vsprintf(msg, args);
|
161
|
+
va_end(args);
|
162
|
+
|
163
|
+
rb_exception = rb_exc_new_str(cNokolexborXpathSyntaxError, rb_message);
|
164
|
+
rb_ary_push(rb_errors, rb_exception);
|
165
|
+
}
|
166
|
+
|
109
167
|
/*
|
110
168
|
* call-seq:
|
111
169
|
* evaluate(search_path, handler = nil)
|
@@ -113,7 +171,7 @@ xpath2ruby(xmlXPathObjectPtr c_xpath_object, xmlXPathContextPtr ctx, VALUE rb_do
|
|
113
171
|
* Evaluate the +search_path+ returning an XML::XPath object.
|
114
172
|
*/
|
115
173
|
static VALUE
|
116
|
-
|
174
|
+
nl_xpath_context_evaluate(int argc, VALUE *argv, VALUE self)
|
117
175
|
{
|
118
176
|
VALUE search_path, xpath_handler;
|
119
177
|
VALUE retval = Qnil;
|
@@ -137,13 +195,13 @@ rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE self)
|
|
137
195
|
// xmlXPathRegisterFuncLookup(ctx, handler_lookup, (void *)xpath_handler);
|
138
196
|
// }
|
139
197
|
|
140
|
-
|
141
|
-
|
198
|
+
xmlSetStructuredErrorFunc((void *)errors, nl_xpath_error_array_pusher);
|
199
|
+
xmlSetGenericErrorFunc((void *)errors, nl_xpath_generic_exception_pusher);
|
142
200
|
|
143
201
|
xpath = xmlXPathEvalExpression(query, ctx);
|
144
202
|
|
145
|
-
|
146
|
-
|
203
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
204
|
+
xmlSetGenericErrorFunc(NULL, NULL);
|
147
205
|
|
148
206
|
if (xpath == NULL)
|
149
207
|
{
|
@@ -156,7 +214,7 @@ rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE self)
|
|
156
214
|
retval = rb_funcall(cNokolexborNodeSet, rb_intern("new"), 1, rb_ary_new());
|
157
215
|
}
|
158
216
|
|
159
|
-
|
217
|
+
xmlXPathFreeNodeSetList(xpath);
|
160
218
|
|
161
219
|
return retval;
|
162
220
|
}
|
@@ -168,7 +226,7 @@ rb_xml_xpath_context_evaluate(int argc, VALUE *argv, VALUE self)
|
|
168
226
|
* Create a new XPathContext with +node+ as the reference point.
|
169
227
|
*/
|
170
228
|
static VALUE
|
171
|
-
|
229
|
+
nl_xpath_context_new(VALUE klass, VALUE rb_node)
|
172
230
|
{
|
173
231
|
xmlXPathContextPtr ctx;
|
174
232
|
VALUE self;
|
@@ -179,7 +237,7 @@ rb_xml_xpath_context_new(VALUE klass, VALUE rb_node)
|
|
179
237
|
ctx->node = node;
|
180
238
|
|
181
239
|
self = Data_Wrap_Struct(klass, 0, free_xml_xpath_context, ctx);
|
182
|
-
rb_iv_set(self, "@document",
|
240
|
+
rb_iv_set(self, "@document", nl_rb_document_get(rb_node));
|
183
241
|
|
184
242
|
return self;
|
185
243
|
}
|
@@ -188,13 +246,15 @@ void Init_nl_xpath_context(void)
|
|
188
246
|
{
|
189
247
|
xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
|
190
248
|
|
191
|
-
|
249
|
+
cNokolexborXpathContext = rb_define_class_under(mNokolexbor, "XPathContext", rb_cObject);
|
250
|
+
mNokolexborXpath = rb_define_module_under(mNokolexbor, "XPath");
|
251
|
+
cNokolexborXpathSyntaxError = rb_define_class_under(mNokolexborXpath, "SyntaxError", rb_eStandardError);
|
192
252
|
|
193
|
-
rb_undef_alloc_func(
|
253
|
+
rb_undef_alloc_func(cNokolexborXpathContext);
|
194
254
|
|
195
|
-
rb_define_singleton_method(
|
255
|
+
rb_define_singleton_method(cNokolexborXpathContext, "new", nl_xpath_context_new, 1);
|
196
256
|
|
197
|
-
rb_define_method(
|
198
|
-
rb_define_method(
|
199
|
-
rb_define_method(
|
257
|
+
rb_define_method(cNokolexborXpathContext, "evaluate", nl_xpath_context_evaluate, -1);
|
258
|
+
rb_define_method(cNokolexborXpathContext, "register_variable", nl_xpath_context_register_variable, 2);
|
259
|
+
rb_define_method(cNokolexborXpathContext, "register_ns", nl_xpath_context_register_ns, 2);
|
200
260
|
}
|
data/ext/nokolexbor/nokolexbor.h
CHANGED
@@ -28,6 +28,8 @@ lxb_inline VALUE nl_rb_document_get(VALUE rb_node_or_doc)
|
|
28
28
|
return rb_iv_get(rb_node_or_doc, "@document");
|
29
29
|
}
|
30
30
|
|
31
|
+
lxb_dom_document_t * nl_rb_document_unwrap(VALUE rb_doc);
|
32
|
+
|
31
33
|
const lxb_char_t *
|
32
34
|
lxb_dom_node_name_qualified(lxb_dom_node_t *node, size_t *len);
|
33
35
|
|
data/ext/nokolexbor/xml_error.c
CHANGED
@@ -3,12 +3,38 @@
|
|
3
3
|
#include <stdarg.h>
|
4
4
|
#include "libxml/xmlerror.h"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
#define XML_GET_VAR_STR(msg, str) { \
|
7
|
+
int size, prev_size = -1; \
|
8
|
+
int chars; \
|
9
|
+
char *larger; \
|
10
|
+
va_list ap; \
|
11
|
+
\
|
12
|
+
str = (char *) xmlMalloc(150); \
|
13
|
+
if (str != NULL) { \
|
14
|
+
\
|
15
|
+
size = 150; \
|
16
|
+
\
|
17
|
+
while (size < 64000) { \
|
18
|
+
va_start(ap, msg); \
|
19
|
+
chars = vsnprintf(str, size, msg, ap); \
|
20
|
+
va_end(ap); \
|
21
|
+
if ((chars > -1) && (chars < size)) { \
|
22
|
+
if (prev_size == chars) { \
|
23
|
+
break; \
|
24
|
+
} else { \
|
25
|
+
prev_size = chars; \
|
26
|
+
} \
|
27
|
+
} \
|
28
|
+
if (chars > -1) \
|
29
|
+
size += chars + 1; \
|
30
|
+
else \
|
31
|
+
size += 100; \
|
32
|
+
if ((larger = (char *) xmlRealloc(str, size)) == NULL) {\
|
33
|
+
break; \
|
34
|
+
} \
|
35
|
+
str = larger; \
|
36
|
+
}} \
|
37
|
+
}
|
12
38
|
|
13
39
|
/**
|
14
40
|
* xmlGenericErrorDefaultFunc:
|
@@ -20,22 +46,57 @@ void *_xmlGenericErrorContext = NULL;
|
|
20
46
|
*/
|
21
47
|
void XMLCDECL
|
22
48
|
xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
|
23
|
-
|
49
|
+
}
|
24
50
|
|
25
|
-
|
26
|
-
|
51
|
+
/**
|
52
|
+
* xmlCopyError:
|
53
|
+
* @from: a source error
|
54
|
+
* @to: a target error
|
55
|
+
*
|
56
|
+
* Save the original error to the new place.
|
57
|
+
*
|
58
|
+
* Returns 0 in case of success and -1 in case of error.
|
59
|
+
*/
|
60
|
+
int
|
61
|
+
xmlCopyError(xmlErrorPtr from, xmlErrorPtr to) {
|
62
|
+
char *message, *file, *str1, *str2, *str3;
|
27
63
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
64
|
+
if ((from == NULL) || (to == NULL))
|
65
|
+
return(-1);
|
66
|
+
|
67
|
+
message = (char *) xmlStrdup((xmlChar *) from->message);
|
68
|
+
file = (char *) xmlStrdup ((xmlChar *) from->file);
|
69
|
+
str1 = (char *) xmlStrdup ((xmlChar *) from->str1);
|
70
|
+
str2 = (char *) xmlStrdup ((xmlChar *) from->str2);
|
71
|
+
str3 = (char *) xmlStrdup ((xmlChar *) from->str3);
|
32
72
|
|
33
|
-
|
73
|
+
if (to->message != NULL)
|
74
|
+
xmlFree(to->message);
|
75
|
+
if (to->file != NULL)
|
76
|
+
xmlFree(to->file);
|
77
|
+
if (to->str1 != NULL)
|
78
|
+
xmlFree(to->str1);
|
79
|
+
if (to->str2 != NULL)
|
80
|
+
xmlFree(to->str2);
|
81
|
+
if (to->str3 != NULL)
|
82
|
+
xmlFree(to->str3);
|
83
|
+
to->domain = from->domain;
|
84
|
+
to->code = from->code;
|
85
|
+
to->level = from->level;
|
86
|
+
to->line = from->line;
|
87
|
+
to->node = from->node;
|
88
|
+
to->int1 = from->int1;
|
89
|
+
to->int2 = from->int2;
|
90
|
+
to->node = from->node;
|
91
|
+
to->ctxt = from->ctxt;
|
92
|
+
to->message = message;
|
93
|
+
to->file = file;
|
94
|
+
to->str1 = str1;
|
95
|
+
to->str2 = str2;
|
96
|
+
to->str3 = str3;
|
34
97
|
|
35
|
-
|
36
|
-
|
37
|
-
// return (&_xmlGenericError);
|
38
|
-
// }
|
98
|
+
return 0;
|
99
|
+
}
|
39
100
|
|
40
101
|
/**
|
41
102
|
* __xmlRaiseError:
|
@@ -63,16 +124,112 @@ xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
|
|
63
124
|
*/
|
64
125
|
void XMLCDECL
|
65
126
|
__xmlRaiseError(xmlStructuredErrorFunc schannel,
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
127
|
+
xmlGenericErrorFunc channel, void *data, void *ctx,
|
128
|
+
void *nod, int domain, int code, xmlErrorLevel level,
|
129
|
+
const char *file, int line, const char *str1,
|
130
|
+
const char *str2, const char *str3, int int1, int col,
|
131
|
+
const char *msg, ...)
|
71
132
|
{
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
133
|
+
xmlParserCtxtPtr ctxt = NULL;
|
134
|
+
lxb_dom_node_t_ptr node = (lxb_dom_node_t_ptr)nod;
|
135
|
+
char *str = NULL;
|
136
|
+
xmlParserInputPtr input = NULL;
|
137
|
+
xmlErrorPtr to = &xmlLastError;
|
138
|
+
lxb_dom_node_t_ptr baseptr = NULL;
|
139
|
+
|
140
|
+
if (code == XML_ERR_OK)
|
141
|
+
return;
|
142
|
+
if ((xmlGetWarningsDefaultValue == 0) && (level == XML_ERR_WARNING))
|
143
|
+
return;
|
144
|
+
if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) ||
|
145
|
+
(domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) ||
|
146
|
+
(domain == XML_FROM_IO) || (domain == XML_FROM_VALID))
|
147
|
+
{
|
148
|
+
ctxt = (xmlParserCtxtPtr)ctx;
|
149
|
+
if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) &&
|
150
|
+
(ctxt->sax->initialized == XML_SAX2_MAGIC) &&
|
151
|
+
(ctxt->sax->serror != NULL))
|
152
|
+
{
|
153
|
+
schannel = ctxt->sax->serror;
|
154
|
+
data = ctxt->userData;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
/*
|
158
|
+
* Check if structured error handler set
|
159
|
+
*/
|
160
|
+
if (schannel == NULL)
|
161
|
+
{
|
162
|
+
schannel = xmlStructuredError;
|
163
|
+
/*
|
164
|
+
* if user has defined handler, change data ptr to user's choice
|
165
|
+
*/
|
166
|
+
if (schannel != NULL)
|
167
|
+
data = xmlStructuredErrorContext;
|
168
|
+
}
|
169
|
+
/*
|
170
|
+
* Formatting the message
|
171
|
+
*/
|
172
|
+
if (msg == NULL)
|
173
|
+
{
|
174
|
+
str = (char *)xmlStrdup(BAD_CAST "No error message provided");
|
175
|
+
}
|
176
|
+
else
|
177
|
+
{
|
178
|
+
XML_GET_VAR_STR(msg, str);
|
179
|
+
}
|
180
|
+
|
181
|
+
/*
|
182
|
+
* specific processing if a parser context is provided
|
183
|
+
*/
|
184
|
+
if (ctxt != NULL)
|
185
|
+
{
|
186
|
+
if (file == NULL)
|
187
|
+
{
|
188
|
+
input = ctxt->input;
|
189
|
+
if ((input != NULL) && (input->filename == NULL) &&
|
190
|
+
(ctxt->inputNr > 1))
|
191
|
+
{
|
192
|
+
input = ctxt->inputTab[ctxt->inputNr - 2];
|
193
|
+
}
|
194
|
+
if (input != NULL)
|
195
|
+
{
|
196
|
+
file = input->filename;
|
197
|
+
line = input->line;
|
198
|
+
col = input->col;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
to = &ctxt->lastError;
|
202
|
+
}
|
203
|
+
|
204
|
+
/*
|
205
|
+
* Save the information about the error
|
206
|
+
*/
|
207
|
+
xmlResetError(to);
|
208
|
+
to->domain = domain;
|
209
|
+
to->code = code;
|
210
|
+
to->message = str;
|
211
|
+
to->level = level;
|
212
|
+
if (file != NULL)
|
213
|
+
to->file = (char *)xmlStrdup((const xmlChar *)file);
|
214
|
+
to->line = line;
|
215
|
+
if (str1 != NULL)
|
216
|
+
to->str1 = (char *)xmlStrdup((const xmlChar *)str1);
|
217
|
+
if (str2 != NULL)
|
218
|
+
to->str2 = (char *)xmlStrdup((const xmlChar *)str2);
|
219
|
+
if (str3 != NULL)
|
220
|
+
to->str3 = (char *)xmlStrdup((const xmlChar *)str3);
|
221
|
+
to->int1 = int1;
|
222
|
+
to->int2 = col;
|
223
|
+
to->node = node;
|
224
|
+
to->ctxt = ctx;
|
225
|
+
|
226
|
+
if (to != &xmlLastError)
|
227
|
+
xmlCopyError(to, &xmlLastError);
|
228
|
+
|
229
|
+
if (schannel != NULL)
|
230
|
+
{
|
231
|
+
schannel(data, to);
|
232
|
+
}
|
76
233
|
}
|
77
234
|
|
78
235
|
/**
|
@@ -131,4 +288,45 @@ __xmlSimpleError(int domain, int code, lxb_dom_node_t_ptr node,
|
|
131
288
|
code, XML_ERR_ERROR, NULL, 0, extra,
|
132
289
|
NULL, NULL, 0, 0, msg, extra);
|
133
290
|
}
|
291
|
+
}
|
292
|
+
|
293
|
+
/**
|
294
|
+
* xmlSetGenericErrorFunc:
|
295
|
+
* @ctx: the new error handling context
|
296
|
+
* @handler: the new handler function
|
297
|
+
*
|
298
|
+
* Function to reset the handler and the error context for out of
|
299
|
+
* context error messages.
|
300
|
+
* This simply means that @handler will be called for subsequent
|
301
|
+
* error messages while not parsing nor validating. And @ctx will
|
302
|
+
* be passed as first argument to @handler
|
303
|
+
* One can simply force messages to be emitted to another FILE * than
|
304
|
+
* stderr by setting @ctx to this file handle and @handler to NULL.
|
305
|
+
* For multi-threaded applications, this must be set separately for each thread.
|
306
|
+
*/
|
307
|
+
void
|
308
|
+
xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
|
309
|
+
xmlGenericErrorContext = ctx;
|
310
|
+
if (handler != NULL)
|
311
|
+
xmlGenericError = handler;
|
312
|
+
else
|
313
|
+
xmlGenericError = xmlGenericErrorDefaultFunc;
|
314
|
+
}
|
315
|
+
|
316
|
+
/**
|
317
|
+
* xmlSetStructuredErrorFunc:
|
318
|
+
* @ctx: the new error handling context
|
319
|
+
* @handler: the new handler function
|
320
|
+
*
|
321
|
+
* Function to reset the handler and the error context for out of
|
322
|
+
* context structured error messages.
|
323
|
+
* This simply means that @handler will be called for subsequent
|
324
|
+
* error messages while not parsing nor validating. And @ctx will
|
325
|
+
* be passed as first argument to @handler
|
326
|
+
* For multi-threaded applications, this must be set separately for each thread.
|
327
|
+
*/
|
328
|
+
void
|
329
|
+
xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
|
330
|
+
xmlStructuredErrorContext = ctx;
|
331
|
+
xmlStructuredError = handler;
|
134
332
|
}
|
data/lib/nokolexbor/node.rb
CHANGED
data/lib/nokolexbor/node_set.rb
CHANGED
data/lib/nokolexbor/version.rb
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nokolexbor
|
4
|
+
module XPath
|
5
|
+
class SyntaxError < StandardError
|
6
|
+
attr_reader :domain
|
7
|
+
attr_reader :code
|
8
|
+
attr_reader :level
|
9
|
+
attr_reader :file
|
10
|
+
attr_reader :line
|
11
|
+
attr_reader :str1
|
12
|
+
attr_reader :str2
|
13
|
+
attr_reader :str3
|
14
|
+
attr_reader :int1
|
15
|
+
attr_reader :column
|
16
|
+
|
17
|
+
###
|
18
|
+
# return true if this is a non error
|
19
|
+
def none?
|
20
|
+
level == 0
|
21
|
+
end
|
22
|
+
|
23
|
+
###
|
24
|
+
# return true if this is a warning
|
25
|
+
def warning?
|
26
|
+
level == 1
|
27
|
+
end
|
28
|
+
|
29
|
+
###
|
30
|
+
# return true if this is an error
|
31
|
+
def error?
|
32
|
+
level == 2
|
33
|
+
end
|
34
|
+
|
35
|
+
###
|
36
|
+
# return true if this error is fatal
|
37
|
+
def fatal?
|
38
|
+
level == 3
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_s
|
42
|
+
message = super.chomp
|
43
|
+
[location_to_s, level_to_s, message]
|
44
|
+
.compact.join(": ")
|
45
|
+
.force_encoding(message.encoding)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def level_to_s
|
51
|
+
case level
|
52
|
+
when 3 then "FATAL"
|
53
|
+
when 2 then "ERROR"
|
54
|
+
when 1 then "WARNING"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def nil_or_zero?(attribute)
|
59
|
+
attribute.nil? || attribute.zero?
|
60
|
+
end
|
61
|
+
|
62
|
+
def location_to_s
|
63
|
+
return nil if nil_or_zero?(line) && nil_or_zero?(column)
|
64
|
+
|
65
|
+
"#{line}:#{column}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/nokolexbor.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokolexbor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yicheng Zhou
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
27
41
|
description: Nokolexbor is a high performance HTML5 parser, with support for both
|
28
42
|
CSS selectors and XPath. It's API is designed to be compatible with Nokogiri.
|
29
43
|
email: zyc9012@gmail.com
|
@@ -32,7 +46,8 @@ extensions:
|
|
32
46
|
- ext/nokolexbor/extconf.rb
|
33
47
|
extra_rdoc_files: []
|
34
48
|
files:
|
35
|
-
- ext/nokolexbor/
|
49
|
+
- ext/nokolexbor/CMakeLists.txt
|
50
|
+
- ext/nokolexbor/config.h.cmake.in
|
36
51
|
- ext/nokolexbor/extconf.rb
|
37
52
|
- ext/nokolexbor/libxml.h
|
38
53
|
- ext/nokolexbor/libxml/HTMLparser.h
|
@@ -59,7 +74,7 @@ files:
|
|
59
74
|
- ext/nokolexbor/libxml/xmlmemory.h
|
60
75
|
- ext/nokolexbor/libxml/xmlregexp.h
|
61
76
|
- ext/nokolexbor/libxml/xmlstring.h
|
62
|
-
- ext/nokolexbor/libxml/xmlversion.h
|
77
|
+
- ext/nokolexbor/libxml/xmlversion.h.in
|
63
78
|
- ext/nokolexbor/libxml/xpath.h
|
64
79
|
- ext/nokolexbor/libxml/xpathInternals.h
|
65
80
|
- ext/nokolexbor/libxml/xpointer.h
|
@@ -104,6 +119,7 @@ files:
|
|
104
119
|
- lib/nokolexbor/node.rb
|
105
120
|
- lib/nokolexbor/node_set.rb
|
106
121
|
- lib/nokolexbor/version.rb
|
122
|
+
- lib/nokolexbor/xpath.rb
|
107
123
|
- lib/nokolexbor/xpath_context.rb
|
108
124
|
- patches/0001-lexbor-support-text-pseudo-element.patch
|
109
125
|
- patches/0002-lexbor-match-id-class-case-sensitive.patch
|
@@ -519,8 +535,9 @@ files:
|
|
519
535
|
homepage: https://github.com/serpapi/nokolexbor
|
520
536
|
licenses:
|
521
537
|
- MIT
|
522
|
-
metadata:
|
523
|
-
|
538
|
+
metadata:
|
539
|
+
msys2_mingw_dependencies: cmake
|
540
|
+
post_install_message:
|
524
541
|
rdoc_options: []
|
525
542
|
require_paths:
|
526
543
|
- lib
|
@@ -535,8 +552,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
535
552
|
- !ruby/object:Gem::Version
|
536
553
|
version: '0'
|
537
554
|
requirements: []
|
538
|
-
rubygems_version: 3.1
|
539
|
-
signing_key:
|
555
|
+
rubygems_version: 3.0.3.1
|
556
|
+
signing_key:
|
540
557
|
specification_version: 4
|
541
558
|
summary: High performance HTML5 parser, with support for both CSS selectors and XPath.
|
542
559
|
test_files: []
|