stringio 0.1.0 → 3.0.0

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

Potentially problematic release.


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

Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/ext/stringio/stringio.c +22 -61
  4. metadata +18 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7968119a0c6ab844f6b3ad11ffa51f7b4065af10a2d73ad79ecbee496e8f352a
4
- data.tar.gz: 11c767a84c56493cf7cd0adf6fddda81f3d6a630ad947c3eddc385b00587311e
3
+ metadata.gz: 41c6ce121bb7eb707f594272b5665080732c7eb7d5ae868f95bb633dc83711ae
4
+ data.tar.gz: d7c1e9260fa0095a95a31e7170264d0d40b4e0093b6bccd0ee84fc80e3c4f005
5
5
  SHA512:
6
- metadata.gz: 69ecd5af25b6334a5dfc7013779f57f6171dec1694f3f0272f05ec51404edc5d4ccac8df78c9f28c8c635bf49afffc2db50dad13ea8a78bf019265390ec0c121
7
- data.tar.gz: 7ae636d1c423605e568349440f6a2e185a05bb1402569f185456dde23130eeefacd7a37768b6ed64ae99fc578799aabb4aeeede35df4d555b75d6cbbdebd7570
6
+ metadata.gz: c19e3fa54ab666fe1ac76a398637e7181ca7e5948bb3576a2504e3a79253ab995dbf515bbaa52f01a6aec112f28102c002353038eced204ddeba0b15ea930544
7
+ data.tar.gz: 3d67ea8a7975013bdf361bf8ab80cd208187b6f4396a118fd16f1d6e9134ab0b596d4b7453b5bdaa0a7f232e08c0103ae3da638258f98baf2e4bd5bcaf5e35f8
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # StringIO
2
2
 
3
- [![Build Status](https://travis-ci.org/ruby/stringio.svg?branch=master)](https://travis-ci.org/ruby/stringio)
3
+ ![ubuntu](https://github.com/ruby/stringio/workflows/ubuntu/badge.svg?branch=master&event=push)
4
+ ![macos](https://github.com/ruby/stringio/workflows/macos/badge.svg?branch=master&event=push)
5
+ ![windows](https://github.com/ruby/stringio/workflows/windows/badge.svg?branch=master&event=push)
4
6
 
5
7
  Pseudo `IO` class from/to `String`.
6
8
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  **********************************************************************/
13
13
 
14
- #define STRINGIO_VERSION "0.1.0"
14
+ #define STRINGIO_VERSION "3.0.0"
15
15
 
16
16
  #include "ruby.h"
17
17
  #include "ruby/io.h"
@@ -363,7 +363,12 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
363
363
  rb_str_resize(string, 0);
364
364
  }
365
365
  ptr->string = string;
366
- ptr->enc = convconfig.enc;
366
+ if (argc == 1) {
367
+ ptr->enc = rb_enc_get(string);
368
+ }
369
+ else {
370
+ ptr->enc = convconfig.enc;
371
+ }
367
372
  ptr->pos = 0;
368
373
  ptr->lineno = 0;
369
374
  if (ptr->flags & FMODE_SETENC_BY_BOM) set_encoding_by_bom(ptr);
@@ -827,18 +832,6 @@ strio_each_byte(VALUE self)
827
832
  return self;
828
833
  }
829
834
 
830
- /*
831
- * This is a deprecated alias for #each_byte.
832
- */
833
- static VALUE
834
- strio_bytes(VALUE self)
835
- {
836
- rb_warn("StringIO#bytes is deprecated; use #each_byte instead");
837
- if (!rb_block_given_p())
838
- return rb_enumeratorize(self, ID2SYM(rb_intern("each_byte")), 0, 0);
839
- return strio_each_byte(self);
840
- }
841
-
842
835
  /*
843
836
  * call-seq:
844
837
  * strio.getc -> string or nil
@@ -1052,18 +1045,6 @@ strio_each_char(VALUE self)
1052
1045
  return self;
1053
1046
  }
1054
1047
 
1055
- /*
1056
- * This is a deprecated alias for #each_char.
1057
- */
1058
- static VALUE
1059
- strio_chars(VALUE self)
1060
- {
1061
- rb_warn("StringIO#chars is deprecated; use #each_char instead");
1062
- if (!rb_block_given_p())
1063
- return rb_enumeratorize(self, ID2SYM(rb_intern("each_char")), 0, 0);
1064
- return strio_each_char(self);
1065
- }
1066
-
1067
1048
  /*
1068
1049
  * call-seq:
1069
1050
  * strio.each_codepoint {|c| block } -> strio
@@ -1090,24 +1071,12 @@ strio_each_codepoint(VALUE self)
1090
1071
 
1091
1072
  c = rb_enc_codepoint_len(RSTRING_PTR(ptr->string)+ptr->pos,
1092
1073
  RSTRING_END(ptr->string), &n, enc);
1093
- rb_yield(UINT2NUM(c));
1094
1074
  ptr->pos += n;
1075
+ rb_yield(UINT2NUM(c));
1095
1076
  }
1096
1077
  return self;
1097
1078
  }
1098
1079
 
1099
- /*
1100
- * This is a deprecated alias for #each_codepoint.
1101
- */
1102
- static VALUE
1103
- strio_codepoints(VALUE self)
1104
- {
1105
- rb_warn("StringIO#codepoints is deprecated; use #each_codepoint instead");
1106
- if (!rb_block_given_p())
1107
- return rb_enumeratorize(self, ID2SYM(rb_intern("each_codepoint")), 0, 0);
1108
- return strio_each_codepoint(self);
1109
- }
1110
-
1111
1080
  /* Boyer-Moore search: copied from regex.c */
1112
1081
  static void
1113
1082
  bm_init_skip(long *skip, const char *pat, long m)
@@ -1358,18 +1327,6 @@ strio_each(int argc, VALUE *argv, VALUE self)
1358
1327
  return self;
1359
1328
  }
1360
1329
 
1361
- /*
1362
- * This is a deprecated alias for #each_line.
1363
- */
1364
- static VALUE
1365
- strio_lines(int argc, VALUE *argv, VALUE self)
1366
- {
1367
- rb_warn("StringIO#lines is deprecated; use #each_line instead");
1368
- if (!rb_block_given_p())
1369
- return rb_enumeratorize(self, ID2SYM(rb_intern("each_line")), argc, argv);
1370
- return strio_each(argc, argv, self);
1371
- }
1372
-
1373
1330
  /*
1374
1331
  * call-seq:
1375
1332
  * strio.readlines(sep=$/, chomp: false) -> array
@@ -1424,13 +1381,18 @@ strio_write(VALUE self, VALUE str)
1424
1381
  long len, olen;
1425
1382
  rb_encoding *enc, *enc2;
1426
1383
  rb_encoding *const ascii8bit = rb_ascii8bit_encoding();
1384
+ rb_encoding *usascii = 0;
1427
1385
 
1428
1386
  if (!RB_TYPE_P(str, T_STRING))
1429
1387
  str = rb_obj_as_string(str);
1430
1388
  enc = get_enc(ptr);
1431
1389
  enc2 = rb_enc_get(str);
1432
- if (enc != enc2 && enc != ascii8bit) {
1433
- str = rb_str_conv_enc(str, enc2, enc);
1390
+ if (enc != enc2 && enc != ascii8bit && enc != (usascii = rb_usascii_encoding())) {
1391
+ VALUE converted = rb_str_conv_enc(str, enc2, enc);
1392
+ if (converted == str && enc2 != ascii8bit && enc2 != usascii) { /* conversion failed */
1393
+ rb_enc_check(rb_enc_from_encoding(enc), str);
1394
+ }
1395
+ str = converted;
1434
1396
  }
1435
1397
  len = RSTRING_LEN(str);
1436
1398
  if (len == 0) return 0;
@@ -1527,7 +1489,6 @@ strio_read(int argc, VALUE *argv, VALUE self)
1527
1489
  long len;
1528
1490
  int binary = 0;
1529
1491
 
1530
- rb_check_arity(argc, 0, 2);
1531
1492
  switch (argc) {
1532
1493
  case 2:
1533
1494
  str = argv[1];
@@ -1567,6 +1528,8 @@ strio_read(int argc, VALUE *argv, VALUE self)
1567
1528
  len -= ptr->pos;
1568
1529
  }
1569
1530
  break;
1531
+ default:
1532
+ rb_error_arity(argc, 0, 2);
1570
1533
  }
1571
1534
  if (NIL_P(str)) {
1572
1535
  rb_encoding *enc = binary ? rb_ascii8bit_encoding() : get_enc(ptr);
@@ -1759,9 +1722,6 @@ strio_set_encoding_by_bom(VALUE self)
1759
1722
  {
1760
1723
  struct StringIO *ptr = StringIO(self);
1761
1724
 
1762
- if (ptr->enc) {
1763
- rb_raise(rb_eArgError, "encoding conversion is set");
1764
- }
1765
1725
  if (!set_encoding_by_bom(ptr)) return Qnil;
1766
1726
  return rb_enc_from_encoding(ptr->enc);
1767
1727
  }
@@ -1790,6 +1750,11 @@ void
1790
1750
  Init_stringio(void)
1791
1751
  {
1792
1752
  #undef rb_intern
1753
+
1754
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
1755
+ rb_ext_ractor_safe(true);
1756
+ #endif
1757
+
1793
1758
  VALUE StringIO = rb_define_class("StringIO", rb_cData);
1794
1759
 
1795
1760
  rb_define_const(StringIO, "VERSION", rb_str_new_cstr(STRINGIO_VERSION));
@@ -1835,13 +1800,9 @@ Init_stringio(void)
1835
1800
 
1836
1801
  rb_define_method(StringIO, "each", strio_each, -1);
1837
1802
  rb_define_method(StringIO, "each_line", strio_each, -1);
1838
- rb_define_method(StringIO, "lines", strio_lines, -1);
1839
1803
  rb_define_method(StringIO, "each_byte", strio_each_byte, 0);
1840
- rb_define_method(StringIO, "bytes", strio_bytes, 0);
1841
1804
  rb_define_method(StringIO, "each_char", strio_each_char, 0);
1842
- rb_define_method(StringIO, "chars", strio_chars, 0);
1843
1805
  rb_define_method(StringIO, "each_codepoint", strio_each_codepoint, 0);
1844
- rb_define_method(StringIO, "codepoints", strio_codepoints, 0);
1845
1806
  rb_define_method(StringIO, "getc", strio_getc, 0);
1846
1807
  rb_define_method(StringIO, "ungetc", strio_ungetc, 1);
1847
1808
  rb_define_method(StringIO, "ungetbyte", strio_ungetbyte, 1);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-30 00:00:00.000000000 Z
11
+ date: 2020-12-18 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: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Pseudo `IO` class from/to `String`.
28
42
  email: nobu@ruby-lang.org
29
43
  executables: []
@@ -36,6 +50,7 @@ files:
36
50
  - ext/stringio/stringio.c
37
51
  homepage: https://github.com/ruby/stringio
38
52
  licenses:
53
+ - Ruby
39
54
  - BSD-2-Clause
40
55
  metadata: {}
41
56
  post_install_message:
@@ -53,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
68
  - !ruby/object:Gem::Version
54
69
  version: '2.6'
55
70
  requirements: []
56
- rubygems_version: 3.0.3
71
+ rubygems_version: 3.1.4
57
72
  signing_key:
58
73
  specification_version: 4
59
74
  summary: Pseudo IO on String