Skip to content

Commit 59dcad5

Browse files
Merge branch 'master' into multibyte_chars_doc
2 parents c2bd933 + e8b66f8 commit 59dcad5

11 files changed

Lines changed: 274 additions & 20 deletions

File tree

.github/workflows/macos.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
os:
22-
- macos-13
2322
- macos-14
23+
- macos-15-intel
24+
- macos-15
2425
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
2526
steps:
2627
- name: git config

.github/workflows/ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: bundle exec rake compile
4545
- name: Build gem
4646
run: bundle exec rake build
47-
- uses: actions/upload-artifact@v5
47+
- uses: actions/upload-artifact@v6
4848
with:
4949
name: gem-${{ matrix.os }}-${{ matrix.ruby }}
5050
path: pkg/

NEWS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# News
22

3+
## 3.2.0 - 2025-12-17
4+
5+
### Improvements
6+
7+
* Improved documents.
8+
* GH-179
9+
* GH-188
10+
* GH-189
11+
* GH-190
12+
* GH-191
13+
* GH-192
14+
* GH-193
15+
* GH-194
16+
* Patch by Burdette Lamar
17+
18+
### Thanks
19+
20+
* Burdette Lamar
21+
322
## 3.1.9 - 2025-12-01
423

524
### Improvements

doc/stringio/getbyte.rdoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ Returns +nil+ if at end-of-stream:
1515
Returns a byte, not a character:
1616

1717
s = 'こんにちは'
18-
s.bytes # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
18+
s.bytes
19+
# => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
1920
strio = StringIO.new(s)
2021
strio.getbyte # => 227
2122
strio.getbyte # => 129
2223

23-
Related: StringIO.getc.
24+
Related: #each_byte, #ungetbyte, #getc.

doc/stringio/getc.rdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ in other cases that need not be true:
2727
strio.pos = 5 # => 5 # At third byte of second character; returns byte.
2828
strio.getc # => "\x93"
2929

30-
Related: StringIO.getbyte.
30+
Related: #getbyte, #putc, #ungetc.

doc/stringio/gets.rdoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,5 @@ removes the trailing newline (if any) from the returned line:
9595
strio.gets # => "First line\n"
9696
strio.gets(chomp: true) # => "Second line"
9797

98-
Related: StringIO.each_line.
98+
Related: #each_line, #readlines,
99+
{Kernel#puts}[https://docs.ruby-lang.org/en/master/Kernel.html#method-i-puts].

doc/stringio/pread.rdoc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
**Note**: \Method +pread+ is different from other reading methods
2+
in that it does not modify +self+ in any way;
3+
thus, multiple threads may read safely from the same stream.
4+
5+
Reads up to +maxlen+ bytes from the stream,
6+
beginning at 0-based byte offset +offset+;
7+
returns a string containing the read bytes.
8+
9+
The returned string:
10+
11+
- Contains +maxlen+ bytes from the stream, if available;
12+
otherwise contains all available bytes.
13+
- Has encoding +Encoding::ASCII_8BIT+.
14+
15+
With only arguments +maxlen+ and +offset+ given,
16+
returns a new string:
17+
18+
english = 'Hello' # Five 1-byte characters.
19+
strio = StringIO.new(english)
20+
strio.pread(3, 0) # => "Hel"
21+
strio.pread(3, 2) # => "llo"
22+
strio.pread(0, 0) # => ""
23+
strio.pread(50, 0) # => "Hello"
24+
strio.pread(50, 2) # => "llo"
25+
strio.pread(50, 4) # => "o"
26+
strio.pread(0, 0).encoding
27+
# => #<Encoding:BINARY (ASCII-8BIT)>
28+
29+
russian = 'Привет' # Six 2-byte characters.
30+
strio = StringIO.new(russian)
31+
strio.pread(50, 0) # All 12 bytes.
32+
# => "\xD0\x9F\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82"
33+
strio.pread(3, 0) # => "\xD0\x9F\xD1"
34+
strio.pread(3, 3) # => "\x80\xD0\xB8"
35+
strio.pread(0, 0).encoding
36+
# => #<Encoding:BINARY (ASCII-8BIT)>
37+
38+
japanese = 'こんにちは' # Five 3-byte characters.
39+
strio = StringIO.new(japanese)
40+
strio.pread(50, 0) # All 15 bytes.
41+
# => "\xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF"
42+
strio.pread(6, 0) # => "\xE3\x81\x93\xE3\x82\x93"
43+
strio.pread(1, 2) # => "\x93"
44+
strio.pread(0, 0).encoding
45+
# => #<Encoding:BINARY (ASCII-8BIT)>
46+
47+
Raises an exception if +offset+ is out-of-range:
48+
49+
strio = StringIO.new(english)
50+
strio.pread(5, 50) # Raises EOFError: end of file reached
51+
52+
With string argument +out_string+ given:
53+
54+
- Reads as above.
55+
- Overwrites the content of +out_string+ with the read bytes.
56+
57+
Examples:
58+
59+
out_string = 'Will be overwritten'
60+
out_string.encoding # => #<Encoding:UTF-8>
61+
result = StringIO.new(english).pread(50, 0, out_string)
62+
result.__id__ == out_string.__id__ # => true
63+
out_string # => "Hello"
64+
out_string.encoding # => #<Encoding:BINARY (ASCII-8BIT)>
65+

doc/stringio/putc.rdoc

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Replaces one or more bytes at position +pos+
2+
with bytes of the given argument;
3+
advances the position by the count of bytes written;
4+
returns the argument.
5+
6+
\StringIO object for 1-byte characters.
7+
8+
strio = StringIO.new('foo')
9+
strio.pos # => 0
10+
11+
With 1-byte argument, replaces one byte:
12+
13+
strio.putc('b')
14+
strio.string # => "boo"
15+
strio.pos # => 1
16+
strio.putc('a') # => "a"
17+
strio.string # => "bao"
18+
strio.pos # => 2
19+
strio.putc('r') # => "r"
20+
strio.string # => "bar"
21+
strio.pos # => 3
22+
strio.putc('n') # => "n"
23+
strio.string # => "barn"
24+
strio.pos # => 4
25+
26+
Fills with null characters if necessary:
27+
28+
strio.pos = 6
29+
strio.putc('x') # => "x"
30+
strio.string # => "barn\u0000\u0000x"
31+
strio.pos # => 7
32+
33+
With integer argument, replaces one byte with the low-order byte of the integer:
34+
35+
strio = StringIO.new('foo')
36+
strio.putc(70)
37+
strio.string # => "Foo"
38+
strio.putc(79)
39+
strio.string # => "FOo"
40+
strio.putc(79 + 1024)
41+
strio.string # => "FOO"
42+
43+
\StringIO object for Multi-byte characters:
44+
45+
greek = 'αβγδε' # Five 2-byte characters.
46+
strio = StringIO.new(greek)
47+
strio.string# => "αβγδε"
48+
strio.string.b # => "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5"
49+
strio.string.bytesize # => 10
50+
strio.string.chars # => ["α", "β", "γ", "δ", "ε"]
51+
strio.string.size # => 5
52+
53+
With 1-byte argument, replaces one byte of the string:
54+
55+
strio.putc(' ') # 1-byte ascii space.
56+
strio.pos # => 1
57+
strio.string # => " \xB1βγδε"
58+
strio.string.b # => " \xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5"
59+
strio.string.bytesize # => 10
60+
strio.string.chars # => [" ", "\xB1", "β", "γ", "δ", "ε"]
61+
strio.string.size # => 6
62+
63+
strio.putc(' ')
64+
strio.pos # => 2
65+
strio.string # => " βγδε"
66+
strio.string.b # => " \xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5"
67+
strio.string.bytesize # => 10
68+
strio.string.chars # => [" ", " ", "β", "γ", "δ", "ε"]
69+
strio.string.size # => 6
70+
71+
With 2-byte argument, replaces two bytes of the string:
72+
73+
strio.rewind
74+
strio.putc('α')
75+
strio.pos # => 2
76+
strio.string # => "αβγδε"
77+
strio.string.b # => "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5"
78+
strio.string.bytesize # => 10
79+
strio.string.chars # => ["α", "β", "γ", "δ", "ε"]
80+
strio.string.size # => 5
81+
82+
Related: #getc, #ungetc.

doc/stringio/read.rdoc

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Reads and returns a string containing bytes read from the stream,
2+
beginning at the current position;
3+
advances the position by the count of bytes read.
4+
5+
With no arguments given,
6+
reads all remaining bytes in the stream;
7+
returns a new string containing bytes read:
8+
9+
strio = StringIO.new('Hello') # Five 1-byte characters.
10+
strio.read # => "Hello"
11+
strio.pos # => 5
12+
strio.read # => ""
13+
StringIO.new('').read # => ""
14+
15+
With non-negative argument +maxlen+ given,
16+
reads +maxlen+ bytes as available;
17+
returns a new string containing the bytes read, or +nil+ if none:
18+
19+
strio.rewind
20+
strio.read(3) # => "Hel"
21+
strio.read(3) # => "lo"
22+
strio.read(3) # => nil
23+
24+
russian = 'Привет' # Six 2-byte characters.
25+
russian.b
26+
# => "\xD0\x9F\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82"
27+
strio = StringIO.new(russian)
28+
strio.read(6) # => "\xD0\x9F\xD1\x80\xD0\xB8"
29+
strio.read(6) # => "\xD0\xB2\xD0\xB5\xD1\x82"
30+
strio.read(6) # => nil
31+
32+
japanese = 'こんにちは'
33+
japanese.b
34+
# => "\xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF"
35+
strio = StringIO.new(japanese)
36+
strio.read(9) # => "\xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB"
37+
strio.read(9) # => "\xE3\x81\xA1\xE3\x81\xAF"
38+
strio.read(9) # => nil
39+
40+
With argument +max_len+ as +nil+ and string argument +out_string+ given,
41+
reads the remaining bytes in the stream;
42+
clears +out_string+ and writes the bytes into it;
43+
returns +out_string+:
44+
45+
out_string = 'Will be overwritten'
46+
strio = StringIO.new('Hello')
47+
strio.read(nil, out_string) # => "Hello"
48+
strio.read(nil, out_string) # => ""
49+
50+
With non-negative argument +maxlen+ and string argument +out_string+ given,
51+
reads the +maxlen bytes from the stream, as availble;
52+
clears +out_string+ and writes the bytes into it;
53+
returns +out_string+ if any bytes were read, or +nil+ if none:
54+
55+
out_string = 'Will be overwritten'
56+
strio = StringIO.new('Hello')
57+
strio.read(3, out_string) # => "Hel"
58+
strio.read(3, out_string) # => "lo"
59+
strio.read(3, out_string) # => nil
60+
61+
out_string = 'Will be overwritten'
62+
strio = StringIO.new(russian)
63+
strio.read(6, out_string) # => "При"
64+
strio.read(6, out_string) # => "вет"
65+
strio.read(6, out_string) # => nil
66+
strio.rewind
67+
russian.b
68+
# => "\xD0\x9F\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82"
69+
strio.read(3) # => "\xD0\x9F\xD1"
70+
strio.read(3) # => "\x80\xD0\xB8"
71+
72+
out_string = 'Will be overwritten'
73+
strio = StringIO.new(japanese)
74+
strio.read(9, out_string) # => "こんに"
75+
strio.read(9, out_string) # => "ちは"
76+
strio.read(9, out_string) # => nil
77+
strio.rewind
78+
japanese.b
79+
# => "\xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF"
80+
strio.read(4) # => "\xE3\x81\x93\xE3"
81+
strio.read(4) # => "\x82\x93\xE3\x81"
82+
83+
Related: #gets, #readlines.

ext/java/org/jruby/ext/stringio/StringIO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private StringIOData getPtr() {
102102
}
103103

104104
private static final String
105-
STRINGIO_VERSION = "3.1.10";
105+
STRINGIO_VERSION = "3.2.1";
106106

107107
private static final byte STRIO_READABLE = 1;
108108
private static final byte STRIO_WRITABLE = 2;

0 commit comments

Comments
 (0)