stringio 3.0.8 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/stringio/extconf.rb +5 -1
- data/ext/stringio/stringio.c +51 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67351f85af240c4189d6d1eaf805bfade85b9aae65d930326ec1c6930c5ba9c9
|
4
|
+
data.tar.gz: 51016af4762d130788a7f80798fafd346225f67c86096f95e7f3f2f5244d8b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e15df64d01a1592cf7ca5f0024cdd693494c5db5c5cfcf9e7d4662c3f8a8c8cdadf2032e72c80d1baa2110c6310f4e6e0fdc96926eee53095ddf443caab9b5c
|
7
|
+
data.tar.gz: 50dafc1b4c0de2e659860b00b6d6e6ef43eedba1cf059956d86acc9f9bb6c28c3924ef5ff3e5b7ba8719afc5366bf1cebf9a0e67b1e1a918a1347aa28f18ea0c
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ Or install it yourself as:
|
|
34
34
|
|
35
35
|
Run `bundle install` to install dependencies and then `bundle exec rake test` to run the tests.
|
36
36
|
|
37
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, author a NEWS.md section, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
38
|
|
39
39
|
## Contributing
|
40
40
|
|
data/ext/stringio/extconf.rb
CHANGED
data/ext/stringio/stringio.c
CHANGED
@@ -12,7 +12,8 @@
|
|
12
12
|
|
13
13
|
**********************************************************************/
|
14
14
|
|
15
|
-
|
15
|
+
static const char *const
|
16
|
+
STRINGIO_VERSION = "3.1.0";
|
16
17
|
|
17
18
|
#include "ruby.h"
|
18
19
|
#include "ruby/io.h"
|
@@ -603,7 +604,7 @@ strio_to_read(VALUE self)
|
|
603
604
|
* eof? -> true or false
|
604
605
|
*
|
605
606
|
* Returns +true+ if positioned at end-of-stream, +false+ otherwise;
|
606
|
-
* see {Position}[rdoc-ref:
|
607
|
+
* see {Position}[rdoc-ref:IO@Position].
|
607
608
|
*
|
608
609
|
* Raises IOError if the stream is not opened for reading.
|
609
610
|
*/
|
@@ -1142,38 +1143,57 @@ struct getline_arg {
|
|
1142
1143
|
};
|
1143
1144
|
|
1144
1145
|
static struct getline_arg *
|
1145
|
-
prepare_getline_args(struct getline_arg *arg, int argc, VALUE *argv)
|
1146
|
+
prepare_getline_args(struct StringIO *ptr, struct getline_arg *arg, int argc, VALUE *argv)
|
1146
1147
|
{
|
1147
|
-
VALUE
|
1148
|
+
VALUE rs, lim, opts;
|
1148
1149
|
long limit = -1;
|
1149
1150
|
int respect_chomp;
|
1150
1151
|
|
1151
|
-
argc = rb_scan_args(argc, argv, "02:", &
|
1152
|
-
respect_chomp = argc == 0 || !NIL_P(
|
1152
|
+
argc = rb_scan_args(argc, argv, "02:", &rs, &lim, &opts);
|
1153
|
+
respect_chomp = argc == 0 || !NIL_P(rs);
|
1153
1154
|
switch (argc) {
|
1154
1155
|
case 0:
|
1155
|
-
|
1156
|
+
rs = rb_rs;
|
1156
1157
|
break;
|
1157
1158
|
|
1158
1159
|
case 1:
|
1159
|
-
|
1160
|
-
|
1160
|
+
if (!NIL_P(rs) && !RB_TYPE_P(rs, T_STRING)) {
|
1161
|
+
VALUE tmp = rb_check_string_type(rs);
|
1161
1162
|
if (NIL_P(tmp)) {
|
1162
|
-
|
1163
|
-
|
1163
|
+
limit = NUM2LONG(rs);
|
1164
|
+
rs = rb_rs;
|
1164
1165
|
}
|
1165
1166
|
else {
|
1166
|
-
|
1167
|
+
rs = tmp;
|
1167
1168
|
}
|
1168
1169
|
}
|
1169
1170
|
break;
|
1170
1171
|
|
1171
1172
|
case 2:
|
1172
|
-
|
1173
|
+
if (!NIL_P(rs)) StringValue(rs);
|
1173
1174
|
if (!NIL_P(lim)) limit = NUM2LONG(lim);
|
1174
1175
|
break;
|
1175
1176
|
}
|
1176
|
-
|
1177
|
+
if (!NIL_P(rs)) {
|
1178
|
+
rb_encoding *enc_rs, *enc_io;
|
1179
|
+
enc_rs = rb_enc_get(rs);
|
1180
|
+
enc_io = get_enc(ptr);
|
1181
|
+
if (enc_rs != enc_io &&
|
1182
|
+
(rb_enc_str_coderange(rs) != ENC_CODERANGE_7BIT ||
|
1183
|
+
(RSTRING_LEN(rs) > 0 && !rb_enc_asciicompat(enc_io)))) {
|
1184
|
+
if (rs == rb_rs) {
|
1185
|
+
rs = rb_enc_str_new(0, 0, enc_io);
|
1186
|
+
rb_str_buf_cat_ascii(rs, "\n");
|
1187
|
+
rs = rs;
|
1188
|
+
}
|
1189
|
+
else {
|
1190
|
+
rb_raise(rb_eArgError, "encoding mismatch: %s IO with %s RS",
|
1191
|
+
rb_enc_name(enc_io),
|
1192
|
+
rb_enc_name(enc_rs));
|
1193
|
+
}
|
1194
|
+
}
|
1195
|
+
}
|
1196
|
+
arg->rs = rs;
|
1177
1197
|
arg->limit = limit;
|
1178
1198
|
arg->chomp = 0;
|
1179
1199
|
if (!NIL_P(opts)) {
|
@@ -1301,15 +1321,15 @@ strio_getline(struct getline_arg *arg, struct StringIO *ptr)
|
|
1301
1321
|
static VALUE
|
1302
1322
|
strio_gets(int argc, VALUE *argv, VALUE self)
|
1303
1323
|
{
|
1324
|
+
struct StringIO *ptr = readable(self);
|
1304
1325
|
struct getline_arg arg;
|
1305
1326
|
VALUE str;
|
1306
1327
|
|
1307
|
-
if (prepare_getline_args(&arg, argc, argv)->limit == 0) {
|
1308
|
-
struct StringIO *ptr = readable(self);
|
1328
|
+
if (prepare_getline_args(ptr, &arg, argc, argv)->limit == 0) {
|
1309
1329
|
return rb_enc_str_new(0, 0, get_enc(ptr));
|
1310
1330
|
}
|
1311
1331
|
|
1312
|
-
str = strio_getline(&arg,
|
1332
|
+
str = strio_getline(&arg, ptr);
|
1313
1333
|
rb_lastline_set(str);
|
1314
1334
|
return str;
|
1315
1335
|
}
|
@@ -1346,16 +1366,16 @@ static VALUE
|
|
1346
1366
|
strio_each(int argc, VALUE *argv, VALUE self)
|
1347
1367
|
{
|
1348
1368
|
VALUE line;
|
1369
|
+
struct StringIO *ptr = readable(self);
|
1349
1370
|
struct getline_arg arg;
|
1350
1371
|
|
1351
|
-
StringIO(self);
|
1352
1372
|
RETURN_ENUMERATOR(self, argc, argv);
|
1353
1373
|
|
1354
|
-
if (prepare_getline_args(&arg, argc, argv)->limit == 0) {
|
1374
|
+
if (prepare_getline_args(ptr, &arg, argc, argv)->limit == 0) {
|
1355
1375
|
rb_raise(rb_eArgError, "invalid limit: 0 for each_line");
|
1356
1376
|
}
|
1357
1377
|
|
1358
|
-
while (!NIL_P(line = strio_getline(&arg,
|
1378
|
+
while (!NIL_P(line = strio_getline(&arg, ptr))) {
|
1359
1379
|
rb_yield(line);
|
1360
1380
|
}
|
1361
1381
|
return self;
|
@@ -1373,15 +1393,15 @@ static VALUE
|
|
1373
1393
|
strio_readlines(int argc, VALUE *argv, VALUE self)
|
1374
1394
|
{
|
1375
1395
|
VALUE ary, line;
|
1396
|
+
struct StringIO *ptr = readable(self);
|
1376
1397
|
struct getline_arg arg;
|
1377
1398
|
|
1378
|
-
|
1379
|
-
ary = rb_ary_new();
|
1380
|
-
if (prepare_getline_args(&arg, argc, argv)->limit == 0) {
|
1399
|
+
if (prepare_getline_args(ptr, &arg, argc, argv)->limit == 0) {
|
1381
1400
|
rb_raise(rb_eArgError, "invalid limit: 0 for readlines");
|
1382
1401
|
}
|
1383
1402
|
|
1384
|
-
|
1403
|
+
ary = rb_ary_new();
|
1404
|
+
while (!NIL_P(line = strio_getline(&arg, ptr))) {
|
1385
1405
|
rb_ary_push(ary, line);
|
1386
1406
|
}
|
1387
1407
|
return ary;
|
@@ -1602,6 +1622,13 @@ strio_pread(int argc, VALUE *argv, VALUE self)
|
|
1602
1622
|
rb_raise(rb_eArgError, "negative string size (or size too big): %" PRIsVALUE, rb_len);
|
1603
1623
|
}
|
1604
1624
|
|
1625
|
+
if (len == 0) {
|
1626
|
+
if (NIL_P(rb_buf)) {
|
1627
|
+
return rb_str_new("", 0);
|
1628
|
+
}
|
1629
|
+
return rb_buf;
|
1630
|
+
}
|
1631
|
+
|
1605
1632
|
if (offset < 0) {
|
1606
1633
|
rb_syserr_fail_str(EINVAL, rb_sprintf("pread: Invalid offset argument: %" PRIsVALUE, rb_offset));
|
1607
1634
|
}
|
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.1.0
|
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-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Pseudo `IO` class from/to `String`.
|
15
15
|
email:
|