stringio 3.0.4 → 3.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/ext/stringio/extconf.rb +0 -1
- data/ext/stringio/stringio.c +86 -123
- metadata +8 -8
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/README.md
CHANGED
@@ -12,6 +12,7 @@ This library is based on MoonWolf version written in Ruby. Thanks a lot.
|
|
12
12
|
|
13
13
|
* `fileno` raises `NotImplementedError`.
|
14
14
|
* encoding conversion is not implemented, and ignored silently.
|
15
|
+
* there is no `#to_io` method because this is not an `IO.
|
15
16
|
|
16
17
|
## Installation
|
17
18
|
|
@@ -31,7 +32,7 @@ Or install it yourself as:
|
|
31
32
|
|
32
33
|
## Development
|
33
34
|
|
34
|
-
|
35
|
+
Run `bundle install` to install dependencies and then `bundle exec rake test` to run the tests.
|
35
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
38
|
|
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;
|
@@ -171,7 +91,7 @@ static const rb_data_type_t strio_data_type = {
|
|
171
91
|
strio_free,
|
172
92
|
strio_memsize,
|
173
93
|
},
|
174
|
-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
94
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
|
175
95
|
};
|
176
96
|
|
177
97
|
#define check_strio(self) ((struct StringIO*)rb_check_typeddata((self), &strio_data_type))
|
@@ -263,7 +183,7 @@ strio_s_allocate(VALUE klass)
|
|
263
183
|
* Note that +mode+ defaults to <tt>'r'</tt> if +string+ is frozen.
|
264
184
|
*
|
265
185
|
* Returns a new \StringIO instance formed from +string+ and +mode+;
|
266
|
-
* see {Access Modes}[
|
186
|
+
* see {Access Modes}[rdoc-ref:File@Access+Modes]:
|
267
187
|
*
|
268
188
|
* strio = StringIO.new # => #<StringIO>
|
269
189
|
* strio.close
|
@@ -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);
|
@@ -379,7 +299,7 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
|
|
379
299
|
if (ptr->flags & FMODE_TRUNC) {
|
380
300
|
rb_str_resize(string, 0);
|
381
301
|
}
|
382
|
-
ptr->string
|
302
|
+
RB_OBJ_WRITE(self, &ptr->string, string);
|
383
303
|
if (argc == 1) {
|
384
304
|
ptr->enc = rb_enc_get(string);
|
385
305
|
}
|
@@ -397,7 +317,7 @@ static VALUE
|
|
397
317
|
strio_finalize(VALUE self)
|
398
318
|
{
|
399
319
|
struct StringIO *ptr = StringIO(self);
|
400
|
-
ptr->string
|
320
|
+
RB_OBJ_WRITE(self, &ptr->string, Qnil);
|
401
321
|
ptr->flags &= ~FMODE_READWRITE;
|
402
322
|
return self;
|
403
323
|
}
|
@@ -409,7 +329,7 @@ strio_finalize(VALUE self)
|
|
409
329
|
* Note that +mode+ defaults to <tt>'r'</tt> if +string+ is frozen.
|
410
330
|
*
|
411
331
|
* Creates a new \StringIO instance formed from +string+ and +mode+;
|
412
|
-
* see {Access Modes}[
|
332
|
+
* see {Access Modes}[rdoc-ref:File@Access+Modes].
|
413
333
|
*
|
414
334
|
* With no block, returns the new instance:
|
415
335
|
*
|
@@ -563,7 +483,8 @@ strio_set_string(VALUE self, VALUE string)
|
|
563
483
|
ptr->flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE;
|
564
484
|
ptr->pos = 0;
|
565
485
|
ptr->lineno = 0;
|
566
|
-
|
486
|
+
RB_OBJ_WRITE(self, &ptr->string, string);
|
487
|
+
return string;
|
567
488
|
}
|
568
489
|
|
569
490
|
/*
|
@@ -682,11 +603,9 @@ strio_to_read(VALUE self)
|
|
682
603
|
* eof? -> true or false
|
683
604
|
*
|
684
605
|
* Returns +true+ if positioned at end-of-stream, +false+ otherwise;
|
685
|
-
* see {Position}[
|
606
|
+
* see {Position}[rdoc-ref:File@Position].
|
686
607
|
*
|
687
608
|
* Raises IOError if the stream is not opened for reading.
|
688
|
-
*
|
689
|
-
* StreamIO#eof is an alias for StreamIO#eof?.
|
690
609
|
*/
|
691
610
|
static VALUE
|
692
611
|
strio_eof(VALUE self)
|
@@ -699,15 +618,19 @@ strio_eof(VALUE self)
|
|
699
618
|
static VALUE
|
700
619
|
strio_copy(VALUE copy, VALUE orig)
|
701
620
|
{
|
702
|
-
struct StringIO *ptr;
|
621
|
+
struct StringIO *ptr, *old_ptr;
|
622
|
+
VALUE old_string = Qundef;
|
703
623
|
|
704
624
|
orig = rb_convert_type(orig, T_DATA, "StringIO", "to_strio");
|
705
625
|
if (copy == orig) return copy;
|
706
626
|
ptr = StringIO(orig);
|
707
|
-
|
708
|
-
|
627
|
+
old_ptr = check_strio(copy);
|
628
|
+
if (old_ptr) {
|
629
|
+
old_string = old_ptr->string;
|
630
|
+
strio_free(old_ptr);
|
709
631
|
}
|
710
632
|
DATA_PTR(copy) = ptr;
|
633
|
+
RB_OBJ_WRITTEN(copy, old_string, ptr->string);
|
711
634
|
RBASIC(copy)->flags &= ~STRIO_READWRITE;
|
712
635
|
RBASIC(copy)->flags |= RBASIC(orig)->flags & STRIO_READWRITE;
|
713
636
|
++ptr->count;
|
@@ -719,7 +642,7 @@ strio_copy(VALUE copy, VALUE orig)
|
|
719
642
|
* lineno -> current_line_number
|
720
643
|
*
|
721
644
|
* Returns the current line number in +self+;
|
722
|
-
* see {Line Number}[
|
645
|
+
* see {Line Number}[rdoc-ref:IO@Line+Number].
|
723
646
|
*/
|
724
647
|
static VALUE
|
725
648
|
strio_get_lineno(VALUE self)
|
@@ -732,7 +655,7 @@ strio_get_lineno(VALUE self)
|
|
732
655
|
* lineno = new_line_number -> new_line_number
|
733
656
|
*
|
734
657
|
* Sets the current line number in +self+ to the given +new_line_number+;
|
735
|
-
* see {Line Number}[
|
658
|
+
* see {Line Number}[rdoc-ref:IO@Line+Number].
|
736
659
|
*/
|
737
660
|
static VALUE
|
738
661
|
strio_set_lineno(VALUE self, VALUE lineno)
|
@@ -746,7 +669,7 @@ strio_set_lineno(VALUE self, VALUE lineno)
|
|
746
669
|
* binmode -> self
|
747
670
|
*
|
748
671
|
* Sets the data mode in +self+ to binary mode;
|
749
|
-
* see {Data Mode}[
|
672
|
+
* see {Data Mode}[rdoc-ref:File@Data+Mode].
|
750
673
|
*
|
751
674
|
*/
|
752
675
|
static VALUE
|
@@ -807,9 +730,7 @@ strio_reopen(int argc, VALUE *argv, VALUE self)
|
|
807
730
|
* pos -> stream_position
|
808
731
|
*
|
809
732
|
* Returns the current position (in bytes);
|
810
|
-
* see {Position}[
|
811
|
-
*
|
812
|
-
* StringIO#tell is an alias for StringIO#pos.
|
733
|
+
* see {Position}[rdoc-ref:IO@Position].
|
813
734
|
*/
|
814
735
|
static VALUE
|
815
736
|
strio_get_pos(VALUE self)
|
@@ -822,7 +743,7 @@ strio_get_pos(VALUE self)
|
|
822
743
|
* pos = new_position -> new_position
|
823
744
|
*
|
824
745
|
* Sets the current position (in bytes);
|
825
|
-
* see {Position}[
|
746
|
+
* see {Position}[rdoc-ref:IO@Position].
|
826
747
|
*/
|
827
748
|
static VALUE
|
828
749
|
strio_set_pos(VALUE self, VALUE pos)
|
@@ -841,8 +762,8 @@ strio_set_pos(VALUE self, VALUE pos)
|
|
841
762
|
* rewind -> 0
|
842
763
|
*
|
843
764
|
* Sets the current position and line number to zero;
|
844
|
-
* see {Position}[
|
845
|
-
* and {Line Number}[
|
765
|
+
* see {Position}[rdoc-ref:IO@Position]
|
766
|
+
* and {Line Number}[rdoc-ref:IO@Line+Number].
|
846
767
|
*/
|
847
768
|
static VALUE
|
848
769
|
strio_rewind(VALUE self)
|
@@ -859,7 +780,7 @@ strio_rewind(VALUE self)
|
|
859
780
|
*
|
860
781
|
* Sets the current position to the given integer +offset+ (in bytes),
|
861
782
|
* with respect to a given constant +whence+;
|
862
|
-
* see {Position}[
|
783
|
+
* see {Position}[rdoc-ref:IO@Position].
|
863
784
|
*/
|
864
785
|
static VALUE
|
865
786
|
strio_seek(int argc, VALUE *argv, VALUE self)
|
@@ -915,7 +836,7 @@ strio_get_sync(VALUE self)
|
|
915
836
|
* each_byte {|byte| ... } -> self
|
916
837
|
*
|
917
838
|
* With a block given, calls the block with each remaining byte in the stream;
|
918
|
-
* see {Byte IO}[
|
839
|
+
* see {Byte IO}[rdoc-ref:IO@Byte+IO].
|
919
840
|
*
|
920
841
|
* With no block given, returns an enumerator.
|
921
842
|
*/
|
@@ -938,7 +859,7 @@ strio_each_byte(VALUE self)
|
|
938
859
|
* getc -> character or nil
|
939
860
|
*
|
940
861
|
* Reads and returns the next character from the stream;
|
941
|
-
* see {Character IO}[
|
862
|
+
* see {Character IO}[rdoc-ref:IO@Character+IO].
|
942
863
|
*/
|
943
864
|
static VALUE
|
944
865
|
strio_getc(VALUE self)
|
@@ -964,7 +885,7 @@ strio_getc(VALUE self)
|
|
964
885
|
* getbyte -> byte or nil
|
965
886
|
*
|
966
887
|
* Reads and returns the next 8-bit byte from the stream;
|
967
|
-
* see {Byte IO}[
|
888
|
+
* see {Byte IO}[rdoc-ref:IO@Byte+IO].
|
968
889
|
*/
|
969
890
|
static VALUE
|
970
891
|
strio_getbyte(VALUE self)
|
@@ -1003,7 +924,7 @@ strio_extend(struct StringIO *ptr, long pos, long len)
|
|
1003
924
|
* ungetc(character) -> nil
|
1004
925
|
*
|
1005
926
|
* Pushes back ("unshifts") a character or integer onto the stream;
|
1006
|
-
* see {Character IO}[
|
927
|
+
* see {Character IO}[rdoc-ref:IO@Character+IO].
|
1007
928
|
*/
|
1008
929
|
static VALUE
|
1009
930
|
strio_ungetc(VALUE self, VALUE c)
|
@@ -1041,7 +962,7 @@ strio_ungetc(VALUE self, VALUE c)
|
|
1041
962
|
* ungetbyte(byte) -> nil
|
1042
963
|
*
|
1043
964
|
* Pushes back ("unshifts") an 8-bit byte onto the stream;
|
1044
|
-
* see {Byte IO}[
|
965
|
+
* see {Byte IO}[rdoc-ref:IO@Byte+IO].
|
1045
966
|
*/
|
1046
967
|
static VALUE
|
1047
968
|
strio_ungetbyte(VALUE self, VALUE c)
|
@@ -1104,7 +1025,7 @@ strio_unget_bytes(struct StringIO *ptr, const char *cp, long cl)
|
|
1104
1025
|
* readchar -> string
|
1105
1026
|
*
|
1106
1027
|
* Like +getc+, but raises an exception if already at end-of-stream;
|
1107
|
-
* see {Character IO}[
|
1028
|
+
* see {Character IO}[rdoc-ref:IO@Character+IO].
|
1108
1029
|
*/
|
1109
1030
|
static VALUE
|
1110
1031
|
strio_readchar(VALUE self)
|
@@ -1119,7 +1040,7 @@ strio_readchar(VALUE self)
|
|
1119
1040
|
* readbyte -> byte
|
1120
1041
|
*
|
1121
1042
|
* Like +getbyte+, but raises an exception if already at end-of-stream;
|
1122
|
-
* see {Byte IO}[
|
1043
|
+
* see {Byte IO}[rdoc-ref:IO@Byte+IO].
|
1123
1044
|
*/
|
1124
1045
|
static VALUE
|
1125
1046
|
strio_readbyte(VALUE self)
|
@@ -1134,7 +1055,7 @@ strio_readbyte(VALUE self)
|
|
1134
1055
|
* each_char {|c| ... } -> self
|
1135
1056
|
*
|
1136
1057
|
* With a block given, calls the block with each remaining character in the stream;
|
1137
|
-
* see {Character IO}[
|
1058
|
+
* see {Character IO}[rdoc-ref:IO@Character+IO].
|
1138
1059
|
*
|
1139
1060
|
* With no block given, returns an enumerator.
|
1140
1061
|
*/
|
@@ -1156,7 +1077,7 @@ strio_each_char(VALUE self)
|
|
1156
1077
|
* each_codepoint {|codepoint| ... } -> self
|
1157
1078
|
*
|
1158
1079
|
* With a block given, calls the block with each remaining codepoint in the stream;
|
1159
|
-
* see {Codepoint IO}[
|
1080
|
+
* see {Codepoint IO}[rdoc-ref:IO@Codepoint+IO].
|
1160
1081
|
*
|
1161
1082
|
* With no block given, returns an enumerator.
|
1162
1083
|
*/
|
@@ -1340,8 +1261,9 @@ strio_getline(struct getline_arg *arg, struct StringIO *ptr)
|
|
1340
1261
|
str = strio_substr(ptr, ptr->pos, e - s - w, enc);
|
1341
1262
|
}
|
1342
1263
|
else {
|
1343
|
-
if (n < e - s) {
|
1344
|
-
|
1264
|
+
if (n < e - s + arg->chomp) {
|
1265
|
+
/* unless chomping, RS at the end does not matter */
|
1266
|
+
if (e - s < 1024 || n == e - s) {
|
1345
1267
|
for (p = s; p + n <= e; ++p) {
|
1346
1268
|
if (MEMCMP(p, RSTRING_PTR(str), char, n) == 0) {
|
1347
1269
|
e = p + n;
|
@@ -1374,7 +1296,7 @@ strio_getline(struct getline_arg *arg, struct StringIO *ptr)
|
|
1374
1296
|
*
|
1375
1297
|
* Reads and returns a line from the stream;
|
1376
1298
|
* assigns the return value to <tt>$_</tt>;
|
1377
|
-
* see {Line IO}[
|
1299
|
+
* see {Line IO}[rdoc-ref:IO@Line+IO].
|
1378
1300
|
*/
|
1379
1301
|
static VALUE
|
1380
1302
|
strio_gets(int argc, VALUE *argv, VALUE self)
|
@@ -1399,7 +1321,7 @@ strio_gets(int argc, VALUE *argv, VALUE self)
|
|
1399
1321
|
* readline(sep, limit, chomp: false) -> string
|
1400
1322
|
*
|
1401
1323
|
* Reads a line as with IO#gets, but raises EOFError if already at end-of-file;
|
1402
|
-
* see {Line IO}[
|
1324
|
+
* see {Line IO}[rdoc-ref:IO@Line+IO].
|
1403
1325
|
*/
|
1404
1326
|
static VALUE
|
1405
1327
|
strio_readline(int argc, VALUE *argv, VALUE self)
|
@@ -1418,9 +1340,7 @@ strio_readline(int argc, VALUE *argv, VALUE self)
|
|
1418
1340
|
* Calls the block with each remaining line read from the stream;
|
1419
1341
|
* does nothing if already at end-of-file;
|
1420
1342
|
* returns +self+.
|
1421
|
-
* See {Line IO}[
|
1422
|
-
*
|
1423
|
-
* StringIO#each is an alias for StringIO#each_line.
|
1343
|
+
* See {Line IO}[rdoc-ref:IO@Line+IO].
|
1424
1344
|
*/
|
1425
1345
|
static VALUE
|
1426
1346
|
strio_each(int argc, VALUE *argv, VALUE self)
|
@@ -1663,6 +1583,48 @@ strio_read(int argc, VALUE *argv, VALUE self)
|
|
1663
1583
|
return str;
|
1664
1584
|
}
|
1665
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
|
+
|
1666
1628
|
/*
|
1667
1629
|
* call-seq:
|
1668
1630
|
* strio.sysread(integer[, outbuf]) -> string
|
@@ -1823,7 +1785,7 @@ strio_set_encoding(int argc, VALUE *argv, VALUE self)
|
|
1823
1785
|
else {
|
1824
1786
|
enc = rb_find_encoding(ext_enc);
|
1825
1787
|
if (!enc) {
|
1826
|
-
|
1788
|
+
rb_io_enc_t convconfig;
|
1827
1789
|
int oflags, fmode;
|
1828
1790
|
VALUE vmode = rb_str_append(rb_str_new_cstr("r:"), ext_enc);
|
1829
1791
|
rb_io_extract_modeenc(&vmode, 0, Qnil, &oflags, &fmode, &convconfig);
|
@@ -1849,8 +1811,8 @@ strio_set_encoding_by_bom(VALUE self)
|
|
1849
1811
|
|
1850
1812
|
/*
|
1851
1813
|
* \IO streams for strings, with access similar to
|
1852
|
-
* {IO}[
|
1853
|
-
* see {IO}[
|
1814
|
+
* {IO}[rdoc-ref:IO];
|
1815
|
+
* see {IO}[rdoc-ref:IO].
|
1854
1816
|
*
|
1855
1817
|
* === About the Examples
|
1856
1818
|
*
|
@@ -1923,6 +1885,7 @@ Init_stringio(void)
|
|
1923
1885
|
rb_define_method(StringIO, "gets", strio_gets, -1);
|
1924
1886
|
rb_define_method(StringIO, "readlines", strio_readlines, -1);
|
1925
1887
|
rb_define_method(StringIO, "read", strio_read, -1);
|
1888
|
+
rb_define_method(StringIO, "pread", strio_pread, -1);
|
1926
1889
|
|
1927
1890
|
rb_define_method(StringIO, "write", strio_write_m, -1);
|
1928
1891
|
rb_define_method(StringIO, "putc", strio_putc, 1);
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
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
|
8
8
|
- Charles Oliver Nutter
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
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:
|
@@ -28,7 +28,7 @@ licenses:
|
|
28
28
|
- Ruby
|
29
29
|
- BSD-2-Clause
|
30
30
|
metadata: {}
|
31
|
-
post_install_message:
|
31
|
+
post_install_message:
|
32
32
|
rdoc_options: []
|
33
33
|
require_paths:
|
34
34
|
- lib
|
@@ -36,15 +36,15 @@ 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
|
-
rubygems_version: 3.
|
47
|
-
signing_key:
|
46
|
+
rubygems_version: 3.4.10
|
47
|
+
signing_key:
|
48
48
|
specification_version: 4
|
49
49
|
summary: Pseudo IO on String
|
50
50
|
test_files: []
|