usamin 7.7.2 → 7.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d053f43fdfdf7a7698d45fa5707245c7ea47946c906f3c504f27aabc543f38b1
4
- data.tar.gz: 0d2b48bf5962478bd7ce35c1a4cfca68589881b59b62ccff5fadd6addd59be8b
3
+ metadata.gz: 5cfc0cdfc9880a6f26fc88def407ab4c5d43312be395d427621d895652b53369
4
+ data.tar.gz: d2fc7676aa1dca66ffdcf4ad653a152fba1fceec93a8ad92a9f269f12810c072
5
5
  SHA512:
6
- metadata.gz: baf083e37d53f5ebfd4ca36e39ec239d62f5f0e198c2a9d79c0efcc77060d5483962d1e1de1268a143ff566713f413f8853a29a68cacc9bc9722d5169abb6cde
7
- data.tar.gz: 540f79a2a0015a39b119435b064d683687f248c6405855170dc8fa7469dfcffb4f393df2f33041f4ff1fcd6816f9d2f9808a2249f0ee68f78e685486c6d0c707
6
+ metadata.gz: 3ff8ab25015ae9a00bf8a43ccd943f32bb77075788d66263f0543b5f3e181a4c0d550390af62b518cc6d0360a7f4aacc2dc78d054bd792bcf4e507de0b1e6b46
7
+ data.tar.gz: a2cc8b6eac41f97eacb043359641482238caa2526ca50ddf2d26d78ebea276963df2c04330de73dcf43101a67cbf91eeef49a6a0c51462724ee54472d31c4df1
data/.gitignore CHANGED
@@ -12,6 +12,7 @@
12
12
  *.a
13
13
  mkmf.log
14
14
 
15
+ Gemfile.lock
15
16
  .DS_Store
16
17
  /testdata/
17
18
  /vendor/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usamin (7.7.0)
4
+ usamin (7.7.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -11,7 +11,7 @@ GEM
11
11
  pry (0.11.3)
12
12
  coderay (~> 1.1.0)
13
13
  method_source (~> 0.9.0)
14
- rake (12.3.0)
14
+ rake (12.3.1)
15
15
  rake-compiler (1.0.4)
16
16
  rake
17
17
 
@@ -26,4 +26,4 @@ DEPENDENCIES
26
26
  usamin!
27
27
 
28
28
  BUNDLED WITH
29
- 1.16.1
29
+ 1.16.2
data/README.md CHANGED
@@ -4,6 +4,8 @@ A fast JSON serializer / deserializer for Ruby with [RapidJSON](http://rapidjson
4
4
 
5
5
  The name of "Usamin" is derived from [Nana Abe](https://www.project-imas.com/wiki/Nana_Abe).
6
6
 
7
+ I congratulate her on her election as the [7th Cinderella Girl](https://www.project-imas.com/wiki/THE_iDOLM@STER_Cinderella_Girls_General_Election#7th_Cinderella_Girl_General_Election).
8
+
7
9
  ## Installation
8
10
 
9
11
  Install RapidJSON beforehand. Only header files are necessary, and no need to build.
@@ -1,6 +1,11 @@
1
1
  require 'mkmf'
2
2
 
3
+ RbConfig::MAKEFILE_CONFIG['CXX'] = ENV['CXX'] if ENV['CXX']
3
4
  have_library('stdc++')
4
5
  dir_config('rapidjson')
5
- $CPPFLAGS << ' -O3 -Wall -Wextra -Wvla -std=c++14'
6
+ append_cppflags('-O3')
7
+ append_cppflags('-Wall')
8
+ append_cppflags('-Wextra')
9
+ append_cppflags('-Wvla')
10
+ $CXXFLAGS << ' -std=c++11'
6
11
  create_makefile('usamin/usamin')
@@ -35,7 +35,7 @@ static inline VALUE get_utf8_str(VALUE str) {
35
35
  Check_Type(str, T_STRING);
36
36
  int encoding = rb_enc_get_index(str);
37
37
  if (encoding == utf8index || rb_enc_compatible(str, utf8value) == utf8)
38
- return str;
38
+ return rb_str_dup(str);
39
39
  else
40
40
  return rb_str_conv_enc(str, rb_enc_from_index(encoding), utf8);
41
41
  }
@@ -52,6 +52,25 @@ static inline bool str_compare(const char* str1, const long len1, const char* st
52
52
  return memcmp(str1, str2, len1) == 0;
53
53
  }
54
54
 
55
+ static inline bool str_compare_xx(VALUE &str1, const rapidjson::Value &str2) {
56
+ bool free_flag = true;
57
+ if (RB_TYPE_P(str1, T_STRING)) {
58
+ int encoding = rb_enc_get_index(str1);
59
+ if (encoding == utf8index || rb_enc_compatible(str1, utf8value) == utf8)
60
+ free_flag = false;
61
+ else
62
+ str1 = rb_str_conv_enc(str1, rb_enc_from_index(encoding), utf8);
63
+ } else if (SYMBOL_P(str1)) {
64
+ str1 = rb_sym_to_s(str1);
65
+ } else {
66
+ StringValue(str1);
67
+ }
68
+ bool ret = str_compare(RSTRING_PTR(str1), RSTRING_LEN(str1), str2.GetString(), str2.GetStringLength());
69
+ if (free_flag)
70
+ rb_str_free(str1);
71
+ return ret;
72
+ }
73
+
55
74
  static inline void check_value(UsaminValue *ptr) {
56
75
  if (!ptr || !ptr->value)
57
76
  rb_raise(rb_eUsaminError, "Null Reference.");
@@ -110,7 +129,9 @@ static inline VALUE make_array(UsaminValue *value) {
110
129
 
111
130
  static inline rapidjson::ParseResult parse(rapidjson::Document &doc, const VALUE str, bool fast = false) {
112
131
  VALUE v = get_utf8_str(str);
113
- return fast ? doc.Parse<kParseFastFlags>(RSTRING_PTR(v), RSTRING_LEN(v)) : doc.Parse(RSTRING_PTR(v), RSTRING_LEN(v));
132
+ rapidjson::ParseResult ret = fast ? doc.Parse<kParseFastFlags>(RSTRING_PTR(v), RSTRING_LEN(v)) : doc.Parse(RSTRING_PTR(v), RSTRING_LEN(v));
133
+ rb_str_free(v);
134
+ return ret;
114
135
  }
115
136
 
116
137
 
@@ -214,59 +235,67 @@ static inline VALUE eval_array_r(rapidjson::Value &value) {
214
235
  template <class Writer> static inline void write_str(Writer&, const VALUE);
215
236
  template <class Writer> static inline void write_hash(Writer&, const VALUE);
216
237
  template <class Writer> static inline void write_array(Writer&, const VALUE);
217
- template <class Writer> static inline void write_bignum(Writer&, const VALUE);
218
238
  template <class Writer> static inline void write_struct(Writer&, const VALUE);
219
239
  template <class Writer> static inline void write_usamin(Writer&, const VALUE);
220
240
  template <class Writer> static inline void write_to_s(Writer&, const VALUE);
221
241
 
222
242
  template <class Writer> static void write(Writer &writer, const VALUE value) {
223
- if (value == Qnil) {
224
- writer.Null();
225
- } else if (value == Qfalse) {
226
- writer.Bool(false);
227
- } else if (value == Qtrue) {
228
- writer.Bool(true);
229
- } else if (RB_FIXNUM_P(value)) {
230
- writer.Int64(FIX2LONG(value));
231
- } else if (RB_FLOAT_TYPE_P(value)) {
232
- writer.Double(NUM2DBL(value));
233
- } else if (RB_STATIC_SYM_P(value)) {
234
- write_str(writer, rb_sym_to_s(value));
235
- } else {
236
- switch (RB_BUILTIN_TYPE(value)) {
237
- case T_STRING:
238
- write_str(writer, value);
239
- break;
240
- case T_HASH:
241
- write_hash(writer, value);
242
- break;
243
- case T_ARRAY:
244
- write_array(writer, value);
245
- break;
246
- case T_BIGNUM:
247
- write_bignum(writer, value);
248
- break;
249
- case T_STRUCT:
250
- write_struct(writer, value);
251
- break;
252
- default:
253
- if (rb_obj_is_kind_of(value, rb_cUsaminValue))
254
- write_usamin(writer, value);
255
- else
256
- write_to_s(writer, value);
257
- break;
258
- }
243
+ switch (TYPE(value)) {
244
+ case RUBY_T_NONE:
245
+ case RUBY_T_NIL:
246
+ case RUBY_T_UNDEF:
247
+ writer.Null();
248
+ break;
249
+ case RUBY_T_TRUE:
250
+ writer.Bool(true);
251
+ case RUBY_T_FALSE:
252
+ writer.Bool(false);
253
+ break;
254
+ case RUBY_T_FIXNUM:
255
+ writer.Int64(FIX2LONG(value));
256
+ break;
257
+ case RUBY_T_FLOAT:
258
+ case RUBY_T_RATIONAL:
259
+ writer.Double(NUM2DBL(value));
260
+ break;
261
+ case RUBY_T_STRING:
262
+ write_str(writer, value);
263
+ break;
264
+ case RUBY_T_ARRAY:
265
+ write_array(writer, value);
266
+ break;
267
+ case RUBY_T_HASH:
268
+ write_hash(writer, value);
269
+ break;
270
+ case RUBY_T_STRUCT:
271
+ write_struct(writer, value);
272
+ break;
273
+ case RUBY_T_BIGNUM:
274
+ {
275
+ VALUE v = rb_big2str(value, 10);
276
+ writer.RawValue(RSTRING_PTR(v), static_cast<unsigned int>(RSTRING_LEN(v)), rapidjson::kNumberType);
277
+ rb_str_free(v);
278
+ }
279
+ break;
280
+ default:
281
+ if (rb_obj_is_kind_of(value, rb_cUsaminValue))
282
+ write_usamin(writer, value);
283
+ else
284
+ write_to_s(writer, value);
285
+ break;
259
286
  }
260
287
  }
261
288
 
262
289
  template <class Writer> static inline void write_str(Writer &writer, const VALUE value) {
263
290
  VALUE v = get_utf8_str(value);
264
291
  writer.String(RSTRING_PTR(v), static_cast<unsigned int>(RSTRING_LEN(v)));
292
+ rb_str_free(v);
265
293
  }
266
294
 
267
295
  template <class Writer> static inline void write_key_str(Writer &writer, const VALUE value) {
268
296
  VALUE v = get_utf8_str(value);
269
297
  writer.Key(RSTRING_PTR(v), static_cast<unsigned int>(RSTRING_LEN(v)));
298
+ rb_str_free(v);
270
299
  }
271
300
 
272
301
  template <class Writer> static inline void write_key_to_s(Writer &writer, const VALUE value) {
@@ -298,11 +327,6 @@ template <class Writer> static inline void write_array(Writer &writer, const VAL
298
327
  writer.EndArray();
299
328
  }
300
329
 
301
- template <class Writer> static inline void write_bignum(Writer &writer, const VALUE value) {
302
- VALUE v = rb_big2str(value, 10);
303
- writer.RawValue(RSTRING_PTR(v), static_cast<unsigned int>(RSTRING_LEN(v)), rapidjson::kNumberType);
304
- }
305
-
306
330
  template <class Writer> static inline void write_struct(Writer &writer, const VALUE value) {
307
331
  writer.StartObject();
308
332
  VALUE members = rb_struct_members(value);
@@ -551,13 +575,39 @@ static VALUE w_value_marshal_load(const VALUE self, VALUE source) {
551
575
  static VALUE w_hash_operator_indexer(const VALUE self, VALUE key) {
552
576
  UsaminValue *value = get_value(self);
553
577
  check_object(value);
554
- VALUE kvalue = get_utf8_str(key);
555
578
  for (auto &m : value->value->GetObject())
556
- if (str_compare(RSTRING_PTR(kvalue), RSTRING_LEN(kvalue), m.name.GetString(), m.name.GetStringLength()))
579
+ if (str_compare_xx(key, m.name))
557
580
  return eval(m.value);
558
581
  return Qnil;
559
582
  }
560
583
 
584
+ /*
585
+ * @return [::Array | nil]
586
+ *
587
+ * @note This method has linear time complexity.
588
+ */
589
+ static VALUE w_hash_assoc(const VALUE self, VALUE key) {
590
+ UsaminValue *value = get_value(self);
591
+ check_object(value);
592
+ for (auto &m : value->value->GetObject())
593
+ if (str_compare_xx(key, m.name))
594
+ return rb_assoc_new(eval_str(m.name), eval(m.value));
595
+ return Qnil;
596
+ }
597
+
598
+ /*
599
+ * @return [::Hash]
600
+ */
601
+ static VALUE w_hash_compact(const VALUE self) {
602
+ UsaminValue *value = get_value(self);
603
+ check_object(value);
604
+ VALUE hash = rb_hash_new();
605
+ for (auto &m : value->value->GetObject())
606
+ if (!m.value.IsNull())
607
+ rb_hash_aset(hash, eval(m.name), eval(m.value));
608
+ return hash;
609
+ }
610
+
561
611
  static VALUE hash_enum_size(const VALUE self, VALUE args, VALUE eobj) {
562
612
  return UINT2NUM(get_value(self)->value->MemberCount());
563
613
  }
@@ -632,26 +682,75 @@ static VALUE w_hash_fetch(const int argc, VALUE* argv, const VALUE self) {
632
682
  rb_check_arity(argc, 1, 2);
633
683
  UsaminValue *value = get_value(self);
634
684
  check_object(value);
635
- VALUE kvalue = get_utf8_str(argv[0]);
636
685
  for (auto &m : value->value->GetObject())
637
- if (str_compare(RSTRING_PTR(kvalue), RSTRING_LEN(kvalue), m.name.GetString(), m.name.GetStringLength()))
686
+ if (str_compare_xx(argv[0], m.name))
638
687
  return eval(m.value);
639
688
  return argc == 2 ? argv[1] : rb_block_given_p() ? rb_yield(argv[0]) : Qnil;
640
689
  }
641
690
 
691
+ /*
692
+ * @param [String] key
693
+ * @return [::Array<Object>]
694
+ */
695
+ static VALUE w_hash_fetch_values(const int argc, VALUE *argv, const VALUE self) {
696
+ UsaminValue *value = get_value(self);
697
+ check_object(value);
698
+ VALUE ret = rb_ary_new2(argc);
699
+ for (int i = 0; i < argc; i++) {
700
+ bool found = false;
701
+ for (auto &m : value->value->GetObject()) {
702
+ if (str_compare_xx(argv[i], m.name)) {
703
+ rb_ary_push(ret, eval(m.value));
704
+ found = true;
705
+ break;
706
+ }
707
+ }
708
+ if (!found) {
709
+ if (rb_block_given_p()) {
710
+ rb_ary_push(ret, rb_yield(argv[i]));
711
+ } else {
712
+ rb_ary_free(ret);
713
+ rb_raise(rb_eKeyError, "key not found: \"%s\"", StringValueCStr(argv[i]));
714
+ return Qnil;
715
+ }
716
+ }
717
+ }
718
+ return ret;
719
+ }
720
+
642
721
  /*
643
722
  * @note This method has linear time complexity.
644
723
  */
645
- static VALUE w_hash_haskey(const VALUE self, VALUE name) {
724
+ static VALUE w_hash_haskey(const VALUE self, VALUE key) {
646
725
  UsaminValue *value = get_value(self);
647
726
  check_object(value);
648
- VALUE key = get_utf8_str(name);
649
727
  for (auto &m : value->value->GetObject())
650
- if (str_compare(RSTRING_PTR(key), RSTRING_LEN(key), m.name.GetString(), m.name.GetStringLength()))
728
+ if (str_compare_xx(key, m.name))
651
729
  return Qtrue;
652
730
  return Qfalse;
653
731
  }
654
732
 
733
+ static VALUE w_hash_hasvalue(const VALUE self, VALUE val) {
734
+ UsaminValue *value = get_value(self);
735
+ check_object(value);
736
+ for (auto &m : value->value->GetObject())
737
+ if (rb_equal(val, eval_r(m.value)))
738
+ return Qtrue;
739
+ return Qfalse;
740
+ }
741
+
742
+ /*
743
+ * @return [String | nil]
744
+ */
745
+ static VALUE w_hash_key(const VALUE self, VALUE val) {
746
+ UsaminValue *value = get_value(self);
747
+ check_object(value);
748
+ for (auto &m : value->value->GetObject())
749
+ if (rb_equal(val, eval_r(m.value)))
750
+ return eval_str(m.name);
751
+ return Qnil;
752
+ }
753
+
655
754
  /*
656
755
  * @return [::Array<String>]
657
756
  */
@@ -673,6 +772,18 @@ static VALUE w_hash_length(const VALUE self) {
673
772
  return UINT2NUM(value->value->MemberCount());
674
773
  }
675
774
 
775
+ /*
776
+ * @return [::Array | nil]
777
+ */
778
+ static VALUE w_hash_rassoc(const VALUE self, VALUE val) {
779
+ UsaminValue *value = get_value(self);
780
+ check_object(value);
781
+ for (auto &m : value->value->GetObject())
782
+ if (rb_funcall(val, rb_intern("=="), 1, eval_r(m.value)))
783
+ return rb_assoc_new(eval(m.name), eval(m.value));
784
+ return Qnil;
785
+ }
786
+
676
787
  /*
677
788
  * @yield [key, value]
678
789
  * @yieldparam key [String]
@@ -701,6 +812,51 @@ static VALUE w_hash_select(const VALUE self) {
701
812
  return hash;
702
813
  }
703
814
 
815
+ /*
816
+ * @yield [key, value]
817
+ * @yieldparam key [String]
818
+ * @yieldparam value [Object]
819
+ * @return [Enumerator | ::Hash]
820
+ */
821
+ static VALUE w_hash_reject(const VALUE self) {
822
+ UsaminValue *value = get_value(self);
823
+ check_object(value);
824
+ RETURN_SIZED_ENUMERATOR(self, 0, nullptr, hash_enum_size);
825
+ VALUE hash = rb_hash_new();
826
+ if (rb_proc_arity(rb_block_proc()) > 1) {
827
+ for (auto &m : value->value->GetObject()) {
828
+ VALUE args[] = { eval_str(m.name), eval(m.value) };
829
+ if (!RTEST(rb_yield_values2(2, args)))
830
+ rb_hash_aset(hash, args[0], args[1]);
831
+ }
832
+ } else {
833
+ for (auto &m : value->value->GetObject()) {
834
+ VALUE key = eval_str(m.name);
835
+ VALUE val = eval(m.value);
836
+ if (!RTEST(rb_yield(rb_assoc_new(key, val))))
837
+ rb_hash_aset(hash, key, val);
838
+ }
839
+ }
840
+ return hash;
841
+ }
842
+
843
+ /*
844
+ * @yield [key, value]
845
+ * @yieldparam key [String]
846
+ * @yieldparam value [Object]
847
+ * @return [Enumerator | ::Hash]
848
+ */
849
+ static VALUE w_hash_slice(const int argc, VALUE* argv, const VALUE self) {
850
+ UsaminValue *value = get_value(self);
851
+ check_object(value);
852
+ VALUE hash = rb_hash_new();
853
+ for (int i = 0; i < argc; i++)
854
+ for (auto &m : value->value->GetObject())
855
+ if (str_compare_xx(argv[i], m.name))
856
+ rb_hash_aset(hash, eval_str(m.name), eval(m.value));
857
+ return hash;
858
+ }
859
+
704
860
  /*
705
861
  * Convert to Ruby Hash. Same as {Value#eval}.
706
862
  *
@@ -712,6 +868,18 @@ static VALUE w_hash_eval(const VALUE self) {
712
868
  return eval_object(*(value->value));
713
869
  }
714
870
 
871
+ /*
872
+ * @return [::Array<Object>]
873
+ */
874
+ static VALUE w_hash_to_a(const VALUE self) {
875
+ UsaminValue *value = get_value(self);
876
+ check_object(value);
877
+ VALUE ret = rb_ary_new2(value->value->MemberCount());
878
+ for (auto &m : value->value->GetObject())
879
+ rb_ary_push(ret, rb_assoc_new(eval_str(m.name), eval(m.value)));
880
+ return ret;
881
+ }
882
+
715
883
  /*
716
884
  * @return [::Array<Object>]
717
885
  */
@@ -724,6 +892,56 @@ static VALUE w_hash_values(const VALUE self) {
724
892
  return ret;
725
893
  }
726
894
 
895
+ /*
896
+ * @yield [key]
897
+ * @yieldparam key [String]
898
+ * @return [Enumerator | ::Hash]
899
+ */
900
+ static VALUE w_hash_transform_keys(const VALUE self) {
901
+ UsaminValue *value = get_value(self);
902
+ check_object(value);
903
+ RETURN_SIZED_ENUMERATOR(self, 0, nullptr, hash_enum_size);
904
+ VALUE hash = rb_hash_new();
905
+ for (auto &m : value->value->GetObject())
906
+ rb_hash_aset(hash, rb_yield(eval_str(m.name)), eval(m.value));
907
+ return hash;
908
+ }
909
+
910
+ /*
911
+ * @yield [value]
912
+ * @yieldparam value [Object]
913
+ * @return [Enumerator | ::Hash]
914
+ */
915
+ static VALUE w_hash_transform_values(const VALUE self) {
916
+ UsaminValue *value = get_value(self);
917
+ check_object(value);
918
+ RETURN_SIZED_ENUMERATOR(self, 0, nullptr, hash_enum_size);
919
+ VALUE hash = rb_hash_new();
920
+ for (auto &m : value->value->GetObject())
921
+ rb_hash_aset(hash, eval_str(m.name), rb_yield(eval(m.value)));
922
+ return hash;
923
+ }
924
+
925
+ /*
926
+ * @param [String] keys
927
+ * @return [::Array<Object>]
928
+ */
929
+ static VALUE w_hash_values_at(const int argc, VALUE *argv, const VALUE self) {
930
+ UsaminValue *value = get_value(self);
931
+ check_object(value);
932
+ VALUE ret = rb_ary_new2(argc);
933
+ for (int i = 0; i < argc; i++) {
934
+ VALUE data = Qnil;
935
+ for (auto &m : value->value->GetObject()) {
936
+ if (str_compare_xx(argv[i], m.name)) {
937
+ data = eval(m.value);
938
+ break;
939
+ }
940
+ }
941
+ rb_ary_push(ret, data);
942
+ }
943
+ return ret;
944
+ }
727
945
 
728
946
  /*
729
947
  * @overload [](nth)
@@ -792,6 +1010,19 @@ static VALUE w_array_at(const VALUE self, VALUE nth) {
792
1010
  return Qnil;
793
1011
  }
794
1012
 
1013
+ /*
1014
+ * @return [::Array]
1015
+ */
1016
+ static VALUE w_array_compact(const VALUE self, VALUE nth) {
1017
+ UsaminValue *value = get_value(self);
1018
+ check_array(value);
1019
+ VALUE ret = rb_ary_new2(value->value->Size());
1020
+ for (auto &v : value->value->GetArray())
1021
+ if (!v.IsNull())
1022
+ rb_ary_push(ret, eval(v));
1023
+ return ret;
1024
+ }
1025
+
795
1026
  static VALUE array_enum_size(const VALUE self, VALUE args, VALUE eobj) {
796
1027
  return UINT2NUM(get_value(self)->value->Size());
797
1028
  }
@@ -883,7 +1114,7 @@ static VALUE w_array_find_index(int argc, VALUE* argv, const VALUE self) {
883
1114
 
884
1115
  if (argc == 1) {
885
1116
  for (rapidjson::SizeType i = 0; i < value->value->Size(); i++) {
886
- if (rb_equal(argv[0], eval((*value->value)[i])) == Qtrue)
1117
+ if (rb_equal(argv[0], eval_r((*value->value)[i])) == Qtrue)
887
1118
  return UINT2NUM(i);
888
1119
  }
889
1120
  return Qnil;
@@ -939,6 +1170,18 @@ static VALUE w_array_first(const int argc, VALUE* argv, const VALUE self) {
939
1170
  }
940
1171
  }
941
1172
 
1173
+ /*
1174
+ * @return [Boolean]
1175
+ */
1176
+ static VALUE w_array_include(const VALUE self, VALUE val) {
1177
+ UsaminValue *value = get_value(self);
1178
+ check_array(value);
1179
+ for (auto &v : value->value->GetArray())
1180
+ if (rb_equal(val, eval_r(v)))
1181
+ return Qtrue;
1182
+ return Qfalse;
1183
+ }
1184
+
942
1185
  /*
943
1186
  * @overload last
944
1187
  * @return [Object | nil]
@@ -1043,12 +1286,11 @@ static VALUE w_pretty_generate(const int argc, VALUE *argv, const VALUE self) {
1043
1286
  long l = FIX2LONG(v_indent);
1044
1287
  indent_count = l > 0 ? static_cast<unsigned int>(l) : 0;
1045
1288
  } else {
1046
- VALUE v = get_utf8_str(v_indent);
1047
- long vlen = RSTRING_LEN(v);
1289
+ long vlen = RSTRING_LEN(v_indent);
1048
1290
  if (vlen == 0) {
1049
1291
  indent_count = 0;
1050
1292
  } else {
1051
- const char *indent_str = RSTRING_PTR(v);
1293
+ const char *indent_str = RSTRING_PTR(v_indent);
1052
1294
  switch (indent_str[0]) {
1053
1295
  case ' ':
1054
1296
  case '\t':
@@ -1109,24 +1351,37 @@ extern "C" void Init_usamin(void) {
1109
1351
  rb_define_alloc_func(rb_cUsaminHash, usamin_alloc);
1110
1352
  rb_undef_method(rb_cUsaminHash, "initialize");
1111
1353
  rb_define_method(rb_cUsaminHash, "[]", RUBY_METHOD_FUNC(w_hash_operator_indexer), 1);
1112
- rb_define_method(rb_cUsaminHash, "assoc", RUBY_METHOD_FUNC(w_hash_operator_indexer), 1);
1354
+ rb_define_method(rb_cUsaminHash, "assoc", RUBY_METHOD_FUNC(w_hash_assoc), 1);
1355
+ rb_define_method(rb_cUsaminHash, "compact", RUBY_METHOD_FUNC(w_hash_compact), 0);
1113
1356
  rb_define_method(rb_cUsaminHash, "each", RUBY_METHOD_FUNC(w_hash_each), 0);
1114
1357
  rb_define_method(rb_cUsaminHash, "each_pair", RUBY_METHOD_FUNC(w_hash_each), 0);
1115
1358
  rb_define_method(rb_cUsaminHash, "each_key", RUBY_METHOD_FUNC(w_hash_each_key), 0);
1116
1359
  rb_define_method(rb_cUsaminHash, "each_value", RUBY_METHOD_FUNC(w_hash_each_value), 0);
1117
1360
  rb_define_method(rb_cUsaminHash, "empty?", RUBY_METHOD_FUNC(w_hash_isempty), 0);
1118
1361
  rb_define_method(rb_cUsaminHash, "fetch", RUBY_METHOD_FUNC(w_hash_fetch), -1);
1362
+ rb_define_method(rb_cUsaminHash, "fetch_values", RUBY_METHOD_FUNC(w_hash_fetch_values), -1);
1119
1363
  rb_define_method(rb_cUsaminHash, "has_key?", RUBY_METHOD_FUNC(w_hash_haskey), 1);
1120
1364
  rb_define_method(rb_cUsaminHash, "include?", RUBY_METHOD_FUNC(w_hash_haskey), 1);
1121
1365
  rb_define_method(rb_cUsaminHash, "key?", RUBY_METHOD_FUNC(w_hash_haskey), 1);
1122
1366
  rb_define_method(rb_cUsaminHash, "member?", RUBY_METHOD_FUNC(w_hash_haskey), 1);
1367
+ rb_define_method(rb_cUsaminHash, "has_value?", RUBY_METHOD_FUNC(w_hash_hasvalue), 1);
1368
+ rb_define_method(rb_cUsaminHash, "value?", RUBY_METHOD_FUNC(w_hash_hasvalue), 1);
1369
+ rb_define_method(rb_cUsaminHash, "key", RUBY_METHOD_FUNC(w_hash_key), 1);
1370
+ rb_define_method(rb_cUsaminHash, "index", RUBY_METHOD_FUNC(w_hash_key), 1);
1123
1371
  rb_define_method(rb_cUsaminHash, "keys", RUBY_METHOD_FUNC(w_hash_keys), 0);
1124
1372
  rb_define_method(rb_cUsaminHash, "length", RUBY_METHOD_FUNC(w_hash_length), 0);
1125
1373
  rb_define_method(rb_cUsaminHash, "size", RUBY_METHOD_FUNC(w_hash_length), 0);
1374
+ rb_define_method(rb_cUsaminHash, "rassoc", RUBY_METHOD_FUNC(w_hash_rassoc), 1);
1375
+ rb_define_method(rb_cUsaminHash, "reject", RUBY_METHOD_FUNC(w_hash_reject), 0);
1126
1376
  rb_define_method(rb_cUsaminHash, "select", RUBY_METHOD_FUNC(w_hash_select), 0);
1377
+ rb_define_method(rb_cUsaminHash, "slice", RUBY_METHOD_FUNC(w_hash_slice), -1);
1378
+ rb_define_method(rb_cUsaminHash, "to_a", RUBY_METHOD_FUNC(w_hash_to_a), 0);
1127
1379
  rb_define_method(rb_cUsaminHash, "to_h", RUBY_METHOD_FUNC(w_hash_eval), 0);
1128
1380
  rb_define_method(rb_cUsaminHash, "to_hash", RUBY_METHOD_FUNC(w_hash_eval), 0);
1381
+ rb_define_method(rb_cUsaminHash, "transform_keys", RUBY_METHOD_FUNC(w_hash_transform_keys), 0);
1382
+ rb_define_method(rb_cUsaminHash, "transform_values", RUBY_METHOD_FUNC(w_hash_transform_values), 0);
1129
1383
  rb_define_method(rb_cUsaminHash, "values", RUBY_METHOD_FUNC(w_hash_values), 0);
1384
+ rb_define_method(rb_cUsaminHash, "values_at", RUBY_METHOD_FUNC(w_hash_values_at), -1);
1130
1385
 
1131
1386
  rb_cUsaminArray = rb_define_class_under(rb_mUsamin, "Array", rb_cUsaminValue);
1132
1387
  rb_include_module(rb_cUsaminArray, rb_mEnumerable);
@@ -1134,6 +1389,7 @@ extern "C" void Init_usamin(void) {
1134
1389
  rb_undef_method(rb_cUsaminArray, "initialize");
1135
1390
  rb_define_method(rb_cUsaminArray, "[]", RUBY_METHOD_FUNC(w_array_operator_indexer), -1);
1136
1391
  rb_define_method(rb_cUsaminArray, "at", RUBY_METHOD_FUNC(w_array_at), 1);
1392
+ rb_define_method(rb_cUsaminArray, "compact", RUBY_METHOD_FUNC(w_array_compact), 0);
1137
1393
  rb_define_method(rb_cUsaminArray, "each", RUBY_METHOD_FUNC(w_array_each), 0);
1138
1394
  rb_define_method(rb_cUsaminArray, "each_index", RUBY_METHOD_FUNC(w_array_each_index), 0);
1139
1395
  rb_define_method(rb_cUsaminArray, "empty?", RUBY_METHOD_FUNC(w_array_isempty), 0);
@@ -1141,6 +1397,7 @@ extern "C" void Init_usamin(void) {
1141
1397
  rb_define_method(rb_cUsaminArray, "find_index", RUBY_METHOD_FUNC(w_array_find_index), -1);
1142
1398
  rb_define_method(rb_cUsaminArray, "index", RUBY_METHOD_FUNC(w_array_index), -1);
1143
1399
  rb_define_method(rb_cUsaminArray, "first", RUBY_METHOD_FUNC(w_array_first), -1);
1400
+ rb_define_method(rb_cUsaminArray, "include?", RUBY_METHOD_FUNC(w_array_include), 1);
1144
1401
  rb_define_method(rb_cUsaminArray, "last", RUBY_METHOD_FUNC(w_array_last), -1);
1145
1402
  rb_define_method(rb_cUsaminArray, "length", RUBY_METHOD_FUNC(w_array_length), 0);
1146
1403
  rb_define_method(rb_cUsaminArray, "size", RUBY_METHOD_FUNC(w_array_length), 0);
@@ -1,3 +1,3 @@
1
1
  module Usamin
2
- VERSION = "7.7.2"
2
+ VERSION = "7.7.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usamin
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.7.2
4
+ version: 7.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ishotihadus
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-26 00:00:00.000000000 Z
11
+ date: 2018-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler