stringio 3.0.6 → 3.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/stringio/extconf.rb +0 -1
- data/ext/stringio/stringio.c +53 -86
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c0b0200f04117b73fd9c58628c8775de264092f0bf620e9275de965a9b5353d
|
4
|
+
data.tar.gz: 47864febb9b35c83ea281a4330222dbd73f9622d6218ec4ac208996b38a04efd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ee084ea64f8565fe66705103a9720f12fd6e0c23e3798705c5395157c0c04794e0b15c36c418e70a8ac3c0d95cb0bd3a0befee02d745b4c05d7938f7dcb28c8
|
7
|
+
data.tar.gz: 25bae0db02e6d737ab323f42c879e8b955ffc5fbf54c847f5cdb4b6fe6087932c8c63a34999fc72a9658acdaa0e53287459ea615fdbc16d169b247ace347827c
|
data/ext/stringio/extconf.rb
CHANGED
data/ext/stringio/stringio.c
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
**********************************************************************/
|
14
14
|
|
15
|
-
#define STRINGIO_VERSION "3.0.
|
15
|
+
#define STRINGIO_VERSION "3.0.8"
|
16
16
|
|
17
17
|
#include "ruby.h"
|
18
18
|
#include "ruby/io.h"
|
@@ -32,86 +32,6 @@
|
|
32
32
|
# define rb_class_new_instance_kw(argc, argv, klass, kw_splat) rb_class_new_instance(argc, argv, klass)
|
33
33
|
#endif
|
34
34
|
|
35
|
-
#ifndef HAVE_RB_IO_EXTRACT_MODEENC
|
36
|
-
#define rb_io_extract_modeenc strio_extract_modeenc
|
37
|
-
static void
|
38
|
-
strio_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash,
|
39
|
-
int *oflags_p, int *fmode_p, struct rb_io_enc_t *convconfig_p)
|
40
|
-
{
|
41
|
-
VALUE mode = *vmode_p;
|
42
|
-
VALUE intmode;
|
43
|
-
int fmode;
|
44
|
-
int has_enc = 0, has_vmode = 0;
|
45
|
-
|
46
|
-
convconfig_p->enc = convconfig_p->enc2 = 0;
|
47
|
-
|
48
|
-
vmode_handle:
|
49
|
-
if (NIL_P(mode)) {
|
50
|
-
fmode = FMODE_READABLE;
|
51
|
-
}
|
52
|
-
else if (!NIL_P(intmode = rb_check_to_integer(mode, "to_int"))) {
|
53
|
-
int flags = NUM2INT(intmode);
|
54
|
-
fmode = rb_io_oflags_fmode(flags);
|
55
|
-
}
|
56
|
-
else {
|
57
|
-
const char *m = StringValueCStr(mode), *n, *e;
|
58
|
-
fmode = rb_io_modestr_fmode(m);
|
59
|
-
n = strchr(m, ':');
|
60
|
-
if (n) {
|
61
|
-
long len;
|
62
|
-
char encname[ENCODING_MAXNAMELEN+1];
|
63
|
-
has_enc = 1;
|
64
|
-
if (fmode & FMODE_SETENC_BY_BOM) {
|
65
|
-
n = strchr(n, '|');
|
66
|
-
}
|
67
|
-
e = strchr(++n, ':');
|
68
|
-
len = e ? e - n : (long)strlen(n);
|
69
|
-
if (len > 0 && len <= ENCODING_MAXNAMELEN) {
|
70
|
-
rb_encoding *enc;
|
71
|
-
if (e) {
|
72
|
-
memcpy(encname, n, len);
|
73
|
-
encname[len] = '\0';
|
74
|
-
n = encname;
|
75
|
-
}
|
76
|
-
enc = rb_enc_find(n);
|
77
|
-
if (e)
|
78
|
-
convconfig_p->enc2 = enc;
|
79
|
-
else
|
80
|
-
convconfig_p->enc = enc;
|
81
|
-
}
|
82
|
-
if (e && (len = strlen(++e)) > 0 && len <= ENCODING_MAXNAMELEN) {
|
83
|
-
convconfig_p->enc = rb_enc_find(e);
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
if (!NIL_P(opthash)) {
|
89
|
-
rb_encoding *extenc = 0, *intenc = 0;
|
90
|
-
VALUE v;
|
91
|
-
if (!has_vmode) {
|
92
|
-
ID id_mode;
|
93
|
-
CONST_ID(id_mode, "mode");
|
94
|
-
v = rb_hash_aref(opthash, ID2SYM(id_mode));
|
95
|
-
if (!NIL_P(v)) {
|
96
|
-
if (!NIL_P(mode)) {
|
97
|
-
rb_raise(rb_eArgError, "mode specified twice");
|
98
|
-
}
|
99
|
-
has_vmode = 1;
|
100
|
-
mode = v;
|
101
|
-
goto vmode_handle;
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
if (rb_io_extract_encoding_option(opthash, &extenc, &intenc, &fmode)) {
|
106
|
-
if (has_enc) {
|
107
|
-
rb_raise(rb_eArgError, "encoding specified twice");
|
108
|
-
}
|
109
|
-
}
|
110
|
-
}
|
111
|
-
*fmode_p = fmode;
|
112
|
-
}
|
113
|
-
#endif
|
114
|
-
|
115
35
|
struct StringIO {
|
116
36
|
VALUE string;
|
117
37
|
rb_encoding *enc;
|
@@ -356,7 +276,7 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
|
|
356
276
|
{
|
357
277
|
VALUE string, vmode, opt;
|
358
278
|
int oflags;
|
359
|
-
|
279
|
+
rb_io_enc_t convconfig;
|
360
280
|
|
361
281
|
argc = rb_scan_args(argc, argv, "02:", &string, &vmode, &opt);
|
362
282
|
rb_io_extract_modeenc(&vmode, 0, opt, &oflags, &ptr->flags, &convconfig);
|
@@ -698,15 +618,19 @@ strio_eof(VALUE self)
|
|
698
618
|
static VALUE
|
699
619
|
strio_copy(VALUE copy, VALUE orig)
|
700
620
|
{
|
701
|
-
struct StringIO *ptr;
|
621
|
+
struct StringIO *ptr, *old_ptr;
|
622
|
+
VALUE old_string = Qundef;
|
702
623
|
|
703
624
|
orig = rb_convert_type(orig, T_DATA, "StringIO", "to_strio");
|
704
625
|
if (copy == orig) return copy;
|
705
626
|
ptr = StringIO(orig);
|
706
|
-
|
707
|
-
|
627
|
+
old_ptr = check_strio(copy);
|
628
|
+
if (old_ptr) {
|
629
|
+
old_string = old_ptr->string;
|
630
|
+
strio_free(old_ptr);
|
708
631
|
}
|
709
632
|
DATA_PTR(copy) = ptr;
|
633
|
+
RB_OBJ_WRITTEN(copy, old_string, ptr->string);
|
710
634
|
RBASIC(copy)->flags &= ~STRIO_READWRITE;
|
711
635
|
RBASIC(copy)->flags |= RBASIC(orig)->flags & STRIO_READWRITE;
|
712
636
|
++ptr->count;
|
@@ -1659,6 +1583,48 @@ strio_read(int argc, VALUE *argv, VALUE self)
|
|
1659
1583
|
return str;
|
1660
1584
|
}
|
1661
1585
|
|
1586
|
+
/*
|
1587
|
+
* call-seq:
|
1588
|
+
* pread(maxlen, offset) -> string
|
1589
|
+
* pread(maxlen, offset, out_string) -> string
|
1590
|
+
*
|
1591
|
+
* See IO#pread.
|
1592
|
+
*/
|
1593
|
+
static VALUE
|
1594
|
+
strio_pread(int argc, VALUE *argv, VALUE self)
|
1595
|
+
{
|
1596
|
+
VALUE rb_len, rb_offset, rb_buf;
|
1597
|
+
rb_scan_args(argc, argv, "21", &rb_len, &rb_offset, &rb_buf);
|
1598
|
+
long len = NUM2LONG(rb_len);
|
1599
|
+
long offset = NUM2LONG(rb_offset);
|
1600
|
+
|
1601
|
+
if (len < 0) {
|
1602
|
+
rb_raise(rb_eArgError, "negative string size (or size too big): %" PRIsVALUE, rb_len);
|
1603
|
+
}
|
1604
|
+
|
1605
|
+
if (offset < 0) {
|
1606
|
+
rb_syserr_fail_str(EINVAL, rb_sprintf("pread: Invalid offset argument: %" PRIsVALUE, rb_offset));
|
1607
|
+
}
|
1608
|
+
|
1609
|
+
struct StringIO *ptr = readable(self);
|
1610
|
+
|
1611
|
+
if (offset >= RSTRING_LEN(ptr->string)) {
|
1612
|
+
rb_eof_error();
|
1613
|
+
}
|
1614
|
+
|
1615
|
+
if (NIL_P(rb_buf)) {
|
1616
|
+
return strio_substr(ptr, offset, len, rb_ascii8bit_encoding());
|
1617
|
+
}
|
1618
|
+
|
1619
|
+
long rest = RSTRING_LEN(ptr->string) - offset;
|
1620
|
+
if (len > rest) len = rest;
|
1621
|
+
rb_str_resize(rb_buf, len);
|
1622
|
+
rb_enc_associate(rb_buf, rb_ascii8bit_encoding());
|
1623
|
+
MEMCPY(RSTRING_PTR(rb_buf), RSTRING_PTR(ptr->string) + offset, char, len);
|
1624
|
+
return rb_buf;
|
1625
|
+
}
|
1626
|
+
|
1627
|
+
|
1662
1628
|
/*
|
1663
1629
|
* call-seq:
|
1664
1630
|
* strio.sysread(integer[, outbuf]) -> string
|
@@ -1819,7 +1785,7 @@ strio_set_encoding(int argc, VALUE *argv, VALUE self)
|
|
1819
1785
|
else {
|
1820
1786
|
enc = rb_find_encoding(ext_enc);
|
1821
1787
|
if (!enc) {
|
1822
|
-
|
1788
|
+
rb_io_enc_t convconfig;
|
1823
1789
|
int oflags, fmode;
|
1824
1790
|
VALUE vmode = rb_str_append(rb_str_new_cstr("r:"), ext_enc);
|
1825
1791
|
rb_io_extract_modeenc(&vmode, 0, Qnil, &oflags, &fmode, &convconfig);
|
@@ -1919,6 +1885,7 @@ Init_stringio(void)
|
|
1919
1885
|
rb_define_method(StringIO, "gets", strio_gets, -1);
|
1920
1886
|
rb_define_method(StringIO, "readlines", strio_readlines, -1);
|
1921
1887
|
rb_define_method(StringIO, "read", strio_read, -1);
|
1888
|
+
rb_define_method(StringIO, "pread", strio_pread, -1);
|
1922
1889
|
|
1923
1890
|
rb_define_method(StringIO, "write", strio_write_m, -1);
|
1924
1891
|
rb_define_method(StringIO, "putc", strio_putc, 1);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stringio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nobu Nakada
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Pseudo `IO` class from/to `String`.
|
15
15
|
email:
|
@@ -36,12 +36,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '2.
|
39
|
+
version: '2.7'
|
40
40
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '
|
44
|
+
version: '0'
|
45
45
|
requirements: []
|
46
46
|
rubygems_version: 3.4.10
|
47
47
|
signing_key:
|