ox 2.7.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ox might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75309ac947bc1f273ca4f6f65096f8fd114bf4ab
4
- data.tar.gz: 481e35498618a38fde11809e04abf896024ab43f
3
+ metadata.gz: af2271c3c5cd6947ce101436041312351fd0d4f5
4
+ data.tar.gz: c1589595a362f3fe1111fc633c33626e529c6792
5
5
  SHA512:
6
- metadata.gz: 3fa20f3ffd22f25b93984ac9f89948a76f90b6398e085980b7295ed634e0e1baf4399c43e2612821da8f47dd2ea8c0da01ae9712923f7042ab646ac7c463c406
7
- data.tar.gz: d2769754eea05431e2e0b6be87bc0bed35992d28ab0b159d967a2198dcaa44489d538f48d96de1a4d8152f2a72ad2d5563b580a2f9064281ef876eb55d9fb5d3
6
+ metadata.gz: 62b558973eb617a8cc52c44b222babfaf8315433385265deea21abca52cbd5994146befbfbb785bc3878663aa2e2fc053fe101bf7e0982c0464f06d9114e9b41
7
+ data.tar.gz: e86031b3635268f92f19f9e17f2a1619a0729e01c3bde9652f26097c24a3a9665335b4a49d6a5840ade33d7690d41c17a3d27088d08166b54e0aad1ca111d680
@@ -1,4 +1,9 @@
1
1
 
2
+ ## 2.8.0 - September 22, 2017
3
+
4
+ - Added :skip_off mode to make sax callback on every none empty string even
5
+ if there are not other non-whitespace characters present.
6
+
2
7
  ## 2.7.0 - August 18, 2017
3
8
 
4
9
  - Two new load modes added, :hash and :hash_no_attrs. Both load an XML
@@ -0,0 +1,26 @@
1
+ /* encode.h
2
+ * Copyright (c) 2011, Peter Ohler
3
+ * All rights reserved.
4
+ */
5
+
6
+ #ifndef __OX_ENCODE_H__
7
+ #define __OX_ENCODE_H__
8
+
9
+ #include "ruby.h"
10
+ #if HAS_ENCODING_SUPPORT
11
+ #include "ruby/encoding.h"
12
+ #endif
13
+
14
+ static inline VALUE
15
+ ox_encode(VALUE rstr) {
16
+ #if HAS_ENCODING_SUPPORT
17
+ rb_enc_associate(rstr, ox_utf8_encoding);
18
+ #else
19
+ if (Qnil != ox_utf8_encoding) {
20
+ rstr = rb_funcall(ox_utf8_encoding, ox_iconv_id, 1, rstr);
21
+ }
22
+ #endif
23
+ return rstr;
24
+ }
25
+
26
+ #endif /* __OX_ENCODE_H__ */
@@ -129,6 +129,7 @@ static VALUE opt_format_sym;
129
129
  static VALUE optimized_sym;
130
130
  static VALUE overlay_sym;
131
131
  static VALUE skip_none_sym;
132
+ static VALUE skip_off_sym;
132
133
  static VALUE skip_return_sym;
133
134
  static VALUE skip_sym;
134
135
  static VALUE skip_white_sym;
@@ -278,7 +279,7 @@ hints_to_overlay(Hints hints) {
278
279
  * - _:mode_ [:object|:generic|:limited|:hash|:hash_no_attrs|nil] load method to use for XML
279
280
  * - _:effort_ [:strict|:tolerant|:auto_define] set the tolerance level for loading
280
281
  * - _:symbolize_keys_ [true|false|nil] symbolize element attribute keys or leave as Strings
281
- * - _:skip_ [:skip_none|:skip_return|:skip_white] determines how to handle white space in text
282
+ * - _:skip_ [:skip_none|:skip_return|:skip_white|:skip_off] determines how to handle white space in text
282
283
  * - _:smart_ [true|false|nil] flag indicating the SAX parser uses hints if available (use with html)
283
284
  * - _:convert_special_ [true|false|nil] flag indicating special characters like < are converted with the SAX parser
284
285
  * - _:invalid_replace_ [nil|String] replacement string for invalid XML characters on dump. nil indicates include anyway as hex. A string, limited to 10 characters will replace the invalid character with the replace.
@@ -330,6 +331,7 @@ get_def_opts(VALUE self) {
330
331
  default: rb_hash_aset(opts, effort_sym, Qnil); break;
331
332
  }
332
333
  switch (ox_default_options.skip) {
334
+ case OffSkip: rb_hash_aset(opts, skip_sym, skip_off_sym); break;
333
335
  case NoSkip: rb_hash_aset(opts, skip_sym, skip_none_sym); break;
334
336
  case CrSkip: rb_hash_aset(opts, skip_sym, skip_return_sym); break;
335
337
  case SpcSkip: rb_hash_aset(opts, skip_sym, skip_white_sym); break;
@@ -413,7 +415,7 @@ sax_html_overlay(VALUE self) {
413
415
  * - _:mode_ [:object|:generic|:limited|:hash|:hash_no_attrs|nil] load method to use for XML
414
416
  * - _:effort_ [:strict|:tolerant|:auto_define] set the tolerance level for loading
415
417
  * - _:symbolize_keys_ [true|false|nil] symbolize element attribute keys or leave as Strings
416
- * - _:skip_ [:skip_none|:skip_return|:skip_white] determines how to handle white space in text
418
+ * - _:skip_ [:skip_none|:skip_return|:skip_white|:skip_off] determines how to handle white space in text
417
419
  * - _:smart_ [true|false|nil] flag indicating the SAX parser uses hints if available (use with html)
418
420
  * - _:invalid_replace_ [nil|String] replacement string for invalid XML characters on dump. nil indicates include anyway as hex. A string, limited to 10 characters will replace the invalid character with the replace.
419
421
  * - _:strip_namespace_ [nil|String|true|false] "" or false result in no namespace stripping. A string of "*" or true will strip all namespaces. Any other non-empty string indicates that matching namespaces will be stripped.
@@ -503,6 +505,8 @@ set_def_opts(VALUE self, VALUE opts) {
503
505
  v = rb_hash_aref(opts, skip_sym);
504
506
  if (Qnil == v) {
505
507
  ox_default_options.skip = NoSkip;
508
+ } else if (skip_off_sym == v) {
509
+ ox_default_options.skip = OffSkip;
506
510
  } else if (skip_none_sym == v) {
507
511
  ox_default_options.skip = NoSkip;
508
512
  } else if (skip_return_sym == v) {
@@ -510,7 +514,7 @@ set_def_opts(VALUE self, VALUE opts) {
510
514
  } else if (skip_white_sym == v) {
511
515
  ox_default_options.skip = SpcSkip;
512
516
  } else {
513
- rb_raise(ox_parse_error_class, ":skip must be :skip_none, :skip_return, :skip_white, or nil.\n");
517
+ rb_raise(ox_parse_error_class, ":skip must be :skip_none, :skip_return, :skip_white, :skip_off, or nil.\n");
514
518
  }
515
519
 
516
520
  v = rb_hash_lookup(opts, convert_special_sym);
@@ -732,12 +736,14 @@ load(char *xml, int argc, VALUE *argv, VALUE self, VALUE encoding, Err err) {
732
736
  if (Qnil != (v = rb_hash_lookup(h, skip_sym))) {
733
737
  if (skip_none_sym == v) {
734
738
  options.skip = NoSkip;
739
+ } else if (skip_off_sym == v) {
740
+ options.skip = OffSkip;
735
741
  } else if (skip_return_sym == v) {
736
742
  options.skip = CrSkip;
737
743
  } else if (skip_white_sym == v) {
738
744
  options.skip = SpcSkip;
739
745
  } else {
740
- rb_raise(ox_parse_error_class, ":skip must be :skip_none, :skip_return, or :skip_white.\n");
746
+ rb_raise(ox_parse_error_class, ":skip must be :skip_none, :skip_return, :skip_white, or :skip_off.\n");
741
747
  }
742
748
  }
743
749
 
@@ -996,7 +1002,7 @@ load_file(int argc, VALUE *argv, VALUE self) {
996
1002
  * - *:convert_special* [true|false] flag indicating special characters like < are converted
997
1003
  * - *:symbolize* [true|false] flag indicating the parser symbolize element and attribute names
998
1004
  * - *:smart* [true|false] flag indicating the parser uses hints if available (use with html)
999
- * - *:skip* [:skip_none|:skip_return|:skip_white] flag indicating the parser skips \\r or collpase white space into a single space. Default (skip space)
1005
+ * - *:skip* [:skip_none|:skip_return|:skip_white|:skip_off] flag indicating the parser skips \\r or collpase white space into a single space. Default (skip space)
1000
1006
  * - *:strip_namespace* [nil|String|true|false] "" or false result in no namespace stripping. A string of "*" or true will strip all namespaces. Any other non-empty string indicates that matching namespaces will be stripped.
1001
1007
  */
1002
1008
  static VALUE
@@ -1033,6 +1039,8 @@ sax_parse(int argc, VALUE *argv, VALUE self) {
1033
1039
  options.skip = SpcSkip;
1034
1040
  } else if (skip_none_sym == v) {
1035
1041
  options.skip = NoSkip;
1042
+ } else if (skip_off_sym == v) {
1043
+ options.skip = OffSkip;
1036
1044
  }
1037
1045
  }
1038
1046
  if (Qnil != (v = rb_hash_lookup(h, strip_namespace_sym))) {
@@ -1069,7 +1077,7 @@ sax_parse(int argc, VALUE *argv, VALUE self) {
1069
1077
  * - +options+ [Hash] options parse options
1070
1078
  * - *:convert_special* [true|false] flag indicating special characters like < are converted
1071
1079
  * - *:symbolize* [true|false] flag indicating the parser symbolize element and attribute names
1072
- * - *:skip* [:skip_none|:skip_return|:skip_white] flag indicating the parser skips \\r or collapse white space into a single space. Default (skip space)
1080
+ * - *:skip* [:skip_none|:skip_return|:skip_white|:skip_off] flag indicating the parser skips \\r or collapse white space into a single space. Default (skip space)
1073
1081
  * - *:overlay* [Hash] a Hash of keys that match html element names and values that are one of
1074
1082
  * - _:active_ - make the normal callback for the element
1075
1083
  * - _:nest_ok_ - active but ignore nest check
@@ -1113,6 +1121,8 @@ sax_html(int argc, VALUE *argv, VALUE self) {
1113
1121
  options.skip = SpcSkip;
1114
1122
  } else if (skip_none_sym == v) {
1115
1123
  options.skip = NoSkip;
1124
+ } else if (skip_off_sym == v) {
1125
+ options.skip = OffSkip;
1116
1126
  }
1117
1127
  }
1118
1128
  if (Qnil != (v = rb_hash_lookup(h, overlay_sym))) {
@@ -1455,6 +1465,7 @@ void Init_ox() {
1455
1465
  ox_standalone_sym = ID2SYM(rb_intern("standalone")); rb_gc_register_address(&ox_standalone_sym);
1456
1466
  ox_version_sym = ID2SYM(rb_intern("version")); rb_gc_register_address(&ox_version_sym);
1457
1467
  skip_none_sym = ID2SYM(rb_intern("skip_none")); rb_gc_register_address(&skip_none_sym);
1468
+ skip_off_sym = ID2SYM(rb_intern("skip_off")); rb_gc_register_address(&skip_off_sym);
1458
1469
  skip_return_sym = ID2SYM(rb_intern("skip_return")); rb_gc_register_address(&skip_return_sym);
1459
1470
  skip_sym = ID2SYM(rb_intern("skip")); rb_gc_register_address(&skip_sym);
1460
1471
  skip_white_sym = ID2SYM(rb_intern("skip_white")); rb_gc_register_address(&skip_white_sym);
@@ -96,6 +96,7 @@ typedef enum {
96
96
  } LoadMode;
97
97
 
98
98
  typedef enum {
99
+ OffSkip = 'o',
99
100
  NoSkip = 'n',
100
101
  CrSkip = 'r',
101
102
  SpcSkip = 's',
@@ -124,7 +124,7 @@ ox_parse(char *xml, ParseCallbacks pcb, char **endp, Options options, Err err) {
124
124
  /* initialize parse info */
125
125
  helper_stack_init(&pi.helpers);
126
126
  // Protect against GC
127
- wrap = rb_data_object_wrap(rb_cObject, &pi, mark_pi_cb, NULL);
127
+ wrap = Data_Wrap_Struct(rb_cObject, mark_pi_cb, NULL, &pi);
128
128
 
129
129
  err_init(&pi.err);
130
130
  pi.str = xml;
@@ -617,6 +617,7 @@ read_element(PInfo pi) {
617
617
  *start = '\0';
618
618
  break;
619
619
  case NoSkip:
620
+ case OffSkip:
620
621
  default:
621
622
  break;
622
623
  }
@@ -745,6 +746,7 @@ read_text(PInfo pi) {
745
746
  }
746
747
  break;
747
748
  case NoSkip:
749
+ case OffSkip:
748
750
  default:
749
751
  *b++ = c;
750
752
  break;
@@ -175,11 +175,7 @@ sax_drive_init(SaxDrive dr, VALUE handler, VALUE io, SaxOptions options) {
175
175
  dr->buf.dr = dr;
176
176
  stack_init(&dr->stack);
177
177
  dr->handler = handler;
178
- #if HAS_DATA_OBJECT_WRAP
179
- dr->value_obj = rb_data_object_wrap(ox_sax_value_class, dr, 0, 0);
180
- #else
181
- dr->value_obj = rb_data_object_alloc(ox_sax_value_class, dr, 0, 0);
182
- #endif
178
+ dr->value_obj = Data_Wrap_Struct(ox_sax_value_class, 0, 0, dr);
183
179
  rb_gc_register_address(&dr->value_obj);
184
180
  dr->options = *options;
185
181
  dr->err = 0;
@@ -1157,7 +1153,9 @@ read_text(SaxDrive dr) {
1157
1153
  int isEnd = ('/' == buf_get(&dr->buf));
1158
1154
 
1159
1155
  buf_backup(&dr->buf);
1160
- if (NoSkip == dr->options.skip && dr->has.text && !isEnd) {
1156
+ if (dr->has.text &&
1157
+ ((NoSkip == dr->options.skip && !isEnd) ||
1158
+ (OffSkip == dr->options.skip))) {
1161
1159
  args[0] = rb_str_new2(dr->buf.str);
1162
1160
  #if HAS_ENCODING_SUPPORT
1163
1161
  if (0 != dr->encoding) {
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '2.7.0'
4
+ VERSION = '2.8.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-18 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "A fast XML parser and object serializer that uses only standard C lib.\n
14
14
  \ \nOptimized XML (Ox), as the name implies was written to provide speed
@@ -35,6 +35,7 @@ files:
35
35
  - ext/ox/cache8.c
36
36
  - ext/ox/cache8.h
37
37
  - ext/ox/dump.c
38
+ - ext/ox/encode.h
38
39
  - ext/ox/err.c
39
40
  - ext/ox/err.h
40
41
  - ext/ox/extconf.rb