stringio 0.1.0 → 3.0.1
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.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/ext/stringio/stringio.c +37 -72
- metadata +8 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 709966f48107a3b3ab9c8b6195ffc21e7e887b7e02c139e4608b20e265ce63c5
|
4
|
+
data.tar.gz: '087dda134d3df50928ebb2a941032a4b5a94fafb1a2dc15057a801a3bfff2d65'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38f467c080782fdca0e76f32c75aac445457d653eea491bd3219f412682889e6613c363062700901948cc372af9227dceba622cc77a84b01455fd6af38247c69
|
7
|
+
data.tar.gz: f17f06857188c5f7cac5810fb6c98cbf2615832a785ea0b19e3e91d6754d9136498694da628e61ba4a5ceb39ba7b7afad63d443c473c49364f423d08d0e19e75
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# StringIO
|
2
2
|
|
3
|
-
|
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
|
|
data/ext/stringio/stringio.c
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/* -*- mode: c; indent-tabs-mode: t -*- */
|
1
2
|
/**********************************************************************
|
2
3
|
|
3
4
|
stringio.c -
|
@@ -11,7 +12,7 @@
|
|
11
12
|
|
12
13
|
**********************************************************************/
|
13
14
|
|
14
|
-
#define STRINGIO_VERSION "0.1
|
15
|
+
#define STRINGIO_VERSION "3.0.1"
|
15
16
|
|
16
17
|
#include "ruby.h"
|
17
18
|
#include "ruby/io.h"
|
@@ -64,7 +65,7 @@ strio_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash,
|
|
64
65
|
n = strchr(n, '|');
|
65
66
|
}
|
66
67
|
e = strchr(++n, ':');
|
67
|
-
len = e ? e - n : strlen(n);
|
68
|
+
len = e ? e - n : (long)strlen(n);
|
68
69
|
if (len > 0 && len <= ENCODING_MAXNAMELEN) {
|
69
70
|
if (e) {
|
70
71
|
memcpy(encname, n, len);
|
@@ -363,7 +364,12 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
|
|
363
364
|
rb_str_resize(string, 0);
|
364
365
|
}
|
365
366
|
ptr->string = string;
|
366
|
-
|
367
|
+
if (argc == 1) {
|
368
|
+
ptr->enc = rb_enc_get(string);
|
369
|
+
}
|
370
|
+
else {
|
371
|
+
ptr->enc = convconfig.enc;
|
372
|
+
}
|
367
373
|
ptr->pos = 0;
|
368
374
|
ptr->lineno = 0;
|
369
375
|
if (ptr->flags & FMODE_SETENC_BY_BOM) set_encoding_by_bom(ptr);
|
@@ -594,6 +600,14 @@ strio_closed_write(VALUE self)
|
|
594
600
|
return Qtrue;
|
595
601
|
}
|
596
602
|
|
603
|
+
static struct StringIO *
|
604
|
+
strio_to_read(VALUE self)
|
605
|
+
{
|
606
|
+
struct StringIO *ptr = readable(self);
|
607
|
+
if (ptr->pos < RSTRING_LEN(ptr->string)) return ptr;
|
608
|
+
return NULL;
|
609
|
+
}
|
610
|
+
|
597
611
|
/*
|
598
612
|
* call-seq:
|
599
613
|
* strio.eof -> true or false
|
@@ -605,8 +619,7 @@ strio_closed_write(VALUE self)
|
|
605
619
|
static VALUE
|
606
620
|
strio_eof(VALUE self)
|
607
621
|
{
|
608
|
-
|
609
|
-
if (ptr->pos < RSTRING_LEN(ptr->string)) return Qfalse;
|
622
|
+
if (strio_to_read(self)) return Qfalse;
|
610
623
|
return Qtrue;
|
611
624
|
}
|
612
625
|
|
@@ -816,29 +829,17 @@ strio_get_sync(VALUE self)
|
|
816
829
|
static VALUE
|
817
830
|
strio_each_byte(VALUE self)
|
818
831
|
{
|
819
|
-
struct StringIO *ptr
|
832
|
+
struct StringIO *ptr;
|
820
833
|
|
821
834
|
RETURN_ENUMERATOR(self, 0, 0);
|
822
835
|
|
823
|
-
while (ptr
|
836
|
+
while ((ptr = strio_to_read(self)) != NULL) {
|
824
837
|
char c = RSTRING_PTR(ptr->string)[ptr->pos++];
|
825
838
|
rb_yield(CHR2FIX(c));
|
826
839
|
}
|
827
840
|
return self;
|
828
841
|
}
|
829
842
|
|
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
843
|
/*
|
843
844
|
* call-seq:
|
844
845
|
* strio.getc -> string or nil
|
@@ -1052,18 +1053,6 @@ strio_each_char(VALUE self)
|
|
1052
1053
|
return self;
|
1053
1054
|
}
|
1054
1055
|
|
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
1056
|
/*
|
1068
1057
|
* call-seq:
|
1069
1058
|
* strio.each_codepoint {|c| block } -> strio
|
@@ -1083,31 +1072,15 @@ strio_each_codepoint(VALUE self)
|
|
1083
1072
|
|
1084
1073
|
ptr = readable(self);
|
1085
1074
|
enc = get_enc(ptr);
|
1086
|
-
|
1087
|
-
if (ptr->pos >= RSTRING_LEN(ptr->string)) {
|
1088
|
-
return self;
|
1089
|
-
}
|
1090
|
-
|
1075
|
+
while ((ptr = strio_to_read(self)) != NULL) {
|
1091
1076
|
c = rb_enc_codepoint_len(RSTRING_PTR(ptr->string)+ptr->pos,
|
1092
1077
|
RSTRING_END(ptr->string), &n, enc);
|
1093
|
-
rb_yield(UINT2NUM(c));
|
1094
1078
|
ptr->pos += n;
|
1079
|
+
rb_yield(UINT2NUM(c));
|
1095
1080
|
}
|
1096
1081
|
return self;
|
1097
1082
|
}
|
1098
1083
|
|
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
1084
|
/* Boyer-Moore search: copied from regex.c */
|
1112
1085
|
static void
|
1113
1086
|
bm_init_skip(long *skip, const char *pat, long m)
|
@@ -1358,18 +1331,6 @@ strio_each(int argc, VALUE *argv, VALUE self)
|
|
1358
1331
|
return self;
|
1359
1332
|
}
|
1360
1333
|
|
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
1334
|
/*
|
1374
1335
|
* call-seq:
|
1375
1336
|
* strio.readlines(sep=$/, chomp: false) -> array
|
@@ -1424,13 +1385,18 @@ strio_write(VALUE self, VALUE str)
|
|
1424
1385
|
long len, olen;
|
1425
1386
|
rb_encoding *enc, *enc2;
|
1426
1387
|
rb_encoding *const ascii8bit = rb_ascii8bit_encoding();
|
1388
|
+
rb_encoding *usascii = 0;
|
1427
1389
|
|
1428
1390
|
if (!RB_TYPE_P(str, T_STRING))
|
1429
1391
|
str = rb_obj_as_string(str);
|
1430
1392
|
enc = get_enc(ptr);
|
1431
1393
|
enc2 = rb_enc_get(str);
|
1432
|
-
if (enc != enc2 && enc != ascii8bit) {
|
1433
|
-
|
1394
|
+
if (enc != enc2 && enc != ascii8bit && enc != (usascii = rb_usascii_encoding())) {
|
1395
|
+
VALUE converted = rb_str_conv_enc(str, enc2, enc);
|
1396
|
+
if (converted == str && enc2 != ascii8bit && enc2 != usascii) { /* conversion failed */
|
1397
|
+
rb_enc_check(rb_enc_from_encoding(enc), str);
|
1398
|
+
}
|
1399
|
+
str = converted;
|
1434
1400
|
}
|
1435
1401
|
len = RSTRING_LEN(str);
|
1436
1402
|
if (len == 0) return 0;
|
@@ -1527,7 +1493,6 @@ strio_read(int argc, VALUE *argv, VALUE self)
|
|
1527
1493
|
long len;
|
1528
1494
|
int binary = 0;
|
1529
1495
|
|
1530
|
-
rb_check_arity(argc, 0, 2);
|
1531
1496
|
switch (argc) {
|
1532
1497
|
case 2:
|
1533
1498
|
str = argv[1];
|
@@ -1567,6 +1532,8 @@ strio_read(int argc, VALUE *argv, VALUE self)
|
|
1567
1532
|
len -= ptr->pos;
|
1568
1533
|
}
|
1569
1534
|
break;
|
1535
|
+
default:
|
1536
|
+
rb_error_arity(argc, 0, 2);
|
1570
1537
|
}
|
1571
1538
|
if (NIL_P(str)) {
|
1572
1539
|
rb_encoding *enc = binary ? rb_ascii8bit_encoding() : get_enc(ptr);
|
@@ -1759,9 +1726,6 @@ strio_set_encoding_by_bom(VALUE self)
|
|
1759
1726
|
{
|
1760
1727
|
struct StringIO *ptr = StringIO(self);
|
1761
1728
|
|
1762
|
-
if (ptr->enc) {
|
1763
|
-
rb_raise(rb_eArgError, "encoding conversion is set");
|
1764
|
-
}
|
1765
1729
|
if (!set_encoding_by_bom(ptr)) return Qnil;
|
1766
1730
|
return rb_enc_from_encoding(ptr->enc);
|
1767
1731
|
}
|
@@ -1790,7 +1754,12 @@ void
|
|
1790
1754
|
Init_stringio(void)
|
1791
1755
|
{
|
1792
1756
|
#undef rb_intern
|
1793
|
-
|
1757
|
+
|
1758
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
1759
|
+
rb_ext_ractor_safe(true);
|
1760
|
+
#endif
|
1761
|
+
|
1762
|
+
VALUE StringIO = rb_define_class("StringIO", rb_cObject);
|
1794
1763
|
|
1795
1764
|
rb_define_const(StringIO, "VERSION", rb_str_new_cstr(STRINGIO_VERSION));
|
1796
1765
|
|
@@ -1835,13 +1804,9 @@ Init_stringio(void)
|
|
1835
1804
|
|
1836
1805
|
rb_define_method(StringIO, "each", strio_each, -1);
|
1837
1806
|
rb_define_method(StringIO, "each_line", strio_each, -1);
|
1838
|
-
rb_define_method(StringIO, "lines", strio_lines, -1);
|
1839
1807
|
rb_define_method(StringIO, "each_byte", strio_each_byte, 0);
|
1840
|
-
rb_define_method(StringIO, "bytes", strio_bytes, 0);
|
1841
1808
|
rb_define_method(StringIO, "each_char", strio_each_char, 0);
|
1842
|
-
rb_define_method(StringIO, "chars", strio_chars, 0);
|
1843
1809
|
rb_define_method(StringIO, "each_codepoint", strio_each_codepoint, 0);
|
1844
|
-
rb_define_method(StringIO, "codepoints", strio_codepoints, 0);
|
1845
1810
|
rb_define_method(StringIO, "getc", strio_getc, 0);
|
1846
1811
|
rb_define_method(StringIO, "ungetc", strio_ungetc, 1);
|
1847
1812
|
rb_define_method(StringIO, "ungetbyte", strio_ungetbyte, 1);
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stringio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nobu Nakada
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake-compiler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
11
|
+
date: 2021-10-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: Pseudo `IO` class from/to `String`.
|
28
14
|
email: nobu@ruby-lang.org
|
29
15
|
executables: []
|
@@ -36,9 +22,10 @@ files:
|
|
36
22
|
- ext/stringio/stringio.c
|
37
23
|
homepage: https://github.com/ruby/stringio
|
38
24
|
licenses:
|
25
|
+
- Ruby
|
39
26
|
- BSD-2-Clause
|
40
27
|
metadata: {}
|
41
|
-
post_install_message:
|
28
|
+
post_install_message:
|
42
29
|
rdoc_options: []
|
43
30
|
require_paths:
|
44
31
|
- lib
|
@@ -53,8 +40,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
40
|
- !ruby/object:Gem::Version
|
54
41
|
version: '2.6'
|
55
42
|
requirements: []
|
56
|
-
rubygems_version: 3.0.
|
57
|
-
signing_key:
|
43
|
+
rubygems_version: 3.3.0.dev
|
44
|
+
signing_key:
|
58
45
|
specification_version: 4
|
59
46
|
summary: Pseudo IO on String
|
60
47
|
test_files: []
|