diff --git a/NEWS.md b/NEWS.md index f847fe6817821d..047bdeeb3e235f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -182,7 +182,7 @@ The following default gems are updated. * RubyGems 4.0.0.dev * bundler 4.0.0.dev -* erb 5.1.1 +* erb 5.1.3 * etc 1.4.6 * fcntl 1.3.0 * io-console 0.8.1 diff --git a/doc/string/sum.rdoc b/doc/string/sum.rdoc index 5de24e6402f692..125611411e34ab 100644 --- a/doc/string/sum.rdoc +++ b/doc/string/sum.rdoc @@ -1,4 +1,4 @@ -Returns a basic +n+-bit checksum of the characters in +self+; +Returns a basic +n+-bit {checksum}[https://en.wikipedia.org/wiki/Checksum] of the characters in +self+; the checksum is the sum of the binary value of each byte in +self+, modulo 2**n - 1: @@ -9,3 +9,5 @@ modulo 2**n - 1: 'こんにちは'.sum # => 2582 This is not a particularly strong checksum. + +Related: see {Querying}[rdoc-ref:String@Querying]. diff --git a/doc/string/swapcase.rdoc b/doc/string/swapcase.rdoc new file mode 100644 index 00000000000000..93859ec8237fcc --- /dev/null +++ b/doc/string/swapcase.rdoc @@ -0,0 +1,19 @@ +Returns a string containing the characters in +self+, with cases reversed: + +- Each uppercase character is downcased. +- Each lowercase character is upcased. + +Examples: + + 'Hello World!'.swapcase # => "hELLO wORLD!" + 'тест'.swapcase # => "ТЕСТ" + +Some characters (and even character sets) do not have casing: + + '12345'.swapcase # => "12345" + 'こんにちは'.swapcase # => "こんにちは" + +The casing may be affected by the given +mapping+; +see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. + +Related: see {Converting to New String}[rdoc-ref:String@Converting+to+New+String]. diff --git a/doc/stringio/each_byte.rdoc b/doc/stringio/each_byte.rdoc new file mode 100644 index 00000000000000..65e81c53a7cd0f --- /dev/null +++ b/doc/stringio/each_byte.rdoc @@ -0,0 +1,34 @@ +With a block given, calls the block with each remaining byte in the stream; +positions the stream at end-of-file; +returns +self+: + + bytes = [] + strio = StringIO.new('hello') # Five 1-byte characters. + strio.each_byte {|byte| bytes.push(byte) } + strio.eof? # => true + bytes # => [104, 101, 108, 108, 111] + bytes = [] + strio = StringIO.new('тест') # Four 2-byte characters. + strio.each_byte {|byte| bytes.push(byte) } + bytes # => [209, 130, 208, 181, 209, 129, 209, 130] + bytes = [] + strio = StringIO.new('こんにちは') # Five 3-byte characters. + strio.each_byte {|byte| bytes.push(byte) } + bytes # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175] + +The position in the stream matters: + + bytes = [] + strio = StringIO.new('こんにちは') + strio.getc # => "こ" + strio.pos # => 3 # 3-byte character was read. + strio.each_byte {|byte| bytes.push(byte) } + bytes # => [227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175] + +If at end-of-file, does not call the block: + + strio.eof? # => true + strio.each_byte {|byte| fail 'Boo!' } + strio.eof? # => true + +With no block given, returns a new {Enumerator}[rdoc-ref:Enumerator]. diff --git a/doc/stringio/each_char.rdoc b/doc/stringio/each_char.rdoc new file mode 100644 index 00000000000000..d0b5e4082cc4d3 --- /dev/null +++ b/doc/stringio/each_char.rdoc @@ -0,0 +1,34 @@ +With a block given, calls the block with each remaining character in the stream; +positions the stream at end-of-file; +returns +self+: + + chars = [] + strio = StringIO.new('hello') + strio.each_char {|char| chars.push(char) } + strio.eof? # => true + chars # => ["h", "e", "l", "l", "o"] + chars = [] + strio = StringIO.new('тест') + strio.each_char {|char| chars.push(char) } + chars # => ["т", "е", "с", "т"] + chars = [] + strio = StringIO.new('こんにちは') + strio.each_char {|char| chars.push(char) } + chars # => ["こ", "ん", "に", "ち", "は"] + +Stream position matters: + + chars = [] + strio = StringIO.new('こんにちは') + strio.getc # => "こ" + strio.pos # => 3 # 3-byte character was read. + strio.each_char {|char| chars.push(char) } + chars # => ["ん", "に", "ち", "は"] + +When at end-of-stream does not call the block: + + strio.eof? # => true + strio.each_char {|char| fail 'Boo!' } + strio.eof? # => true + +With no block given, returns a new {Enumerator}[rdoc-ref:Enumerator]. diff --git a/doc/stringio/each_codepoint.rdoc b/doc/stringio/each_codepoint.rdoc new file mode 100644 index 00000000000000..ede16de599cf0c --- /dev/null +++ b/doc/stringio/each_codepoint.rdoc @@ -0,0 +1,36 @@ +With a block given, calls the block with each successive codepoint from self; +sets the position to end-of-stream; +returns +self+. + +Each codepoint is the integer value for a character; returns self: + + codepoints = [] + strio = StringIO.new('hello') + strio.each_codepoint {|codepoint| codepoints.push(codepoint) } + strio.eof? # => true + codepoints # => [104, 101, 108, 108, 111] + codepoints = [] + strio = StringIO.new('тест') + strio.each_codepoint {|codepoint| codepoints.push(codepoint) } + codepoints # => [1090, 1077, 1089, 1090] + codepoints = [] + strio = StringIO.new('こんにちは') + strio.each_codepoint {|codepoint| codepoints.push(codepoint) } + codepoints # => [12371, 12435, 12395, 12385, 12399] + +Position in the stream matters: + + codepoints = [] + strio = StringIO.new('こんにちは') + strio.getc # => "こ" + strio.pos # => 3 + strio.each_codepoint {|codepoint| codepoints.push(codepoint) } + codepoints # => [12435, 12395, 12385, 12399] + +When at end-of-stream, the block is not called: + + strio.eof? # => true + strio.each_codepoint {|codepoint| fail 'Boo!' } + strio.eof? # => true + +With no block given, returns a new {Enumerator}[rdoc-ref:Enumerator]. diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index b6ab8cd6cfdeb7..b96010dfbf3f96 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -936,10 +936,9 @@ strio_get_sync(VALUE self) * call-seq: * each_byte {|byte| ... } -> self * - * With a block given, calls the block with each remaining byte in the stream; - * see {Byte IO}[rdoc-ref:IO@Byte+IO]. + * :include: stringio/each_byte.rdoc * - * With no block given, returns an enumerator. + * Related: StringIO#each_char, StringIO#each_codepoint, StringIO#each_line. */ static VALUE strio_each_byte(VALUE self) @@ -1162,12 +1161,11 @@ strio_readbyte(VALUE self) /* * call-seq: - * each_char {|c| ... } -> self + * each_char {|char| ... } -> self * - * With a block given, calls the block with each remaining character in the stream; - * see {Character IO}[rdoc-ref:IO@Character+IO]. + * :include: stringio/each_char.rdoc * - * With no block given, returns an enumerator. + * Related: StringIO#each_byte, StringIO#each_codepoint, StringIO#each_line. */ static VALUE strio_each_char(VALUE self) @@ -1186,10 +1184,9 @@ strio_each_char(VALUE self) * call-seq: * each_codepoint {|codepoint| ... } -> self * - * With a block given, calls the block with each remaining codepoint in the stream; - * see {Codepoint IO}[rdoc-ref:IO@Codepoint+IO]. + * :include: stringio/each_codepoint.rdoc * - * With no block given, returns an enumerator. + * Related: StringIO#each_byte, StringIO#each_char, StringIO#each_line. */ static VALUE strio_each_codepoint(VALUE self) @@ -1630,7 +1627,7 @@ strio_readline(int argc, VALUE *argv, VALUE self) * "Fifth line" * ``` * - * With no block given, returns a new {Enumerator}[rdoc-ref:Enumerator]. + * With no block given, returns a new {Enumerator}[rdoc-ref:Enumerator]. * * Related: StringIO.each_byte, StringIO.each_char, StringIO.each_codepoint. */ diff --git a/lib/erb/version.rb b/lib/erb/version.rb index ceca10731e4ce4..138bf3988206fc 100644 --- a/lib/erb/version.rb +++ b/lib/erb/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class ERB # The string \ERB version. - VERSION = '5.1.1' + VERSION = '5.1.3' end diff --git a/string.c b/string.c index b4585fd3205913..fa6ce7f3ec1d07 100644 --- a/string.c +++ b/string.c @@ -6190,7 +6190,7 @@ rb_pat_search(VALUE pat, VALUE str, long pos, int set_backref_str) * * Like String#sub, except that: * - * - Changed are made to +self+, not to copy of +self+. + * - Changes are made to +self+, not to copy of +self+. * - Returns +self+ if any changes are made, +nil+ otherwise. * * Related: see {Modifying}[rdoc-ref:String@Modifying]. @@ -8203,20 +8203,12 @@ rb_str_capitalize(int argc, VALUE *argv, VALUE str) * call-seq: * swapcase!(mapping) -> self or nil * - * Upcases each lowercase character in +self+; - * downcases uppercase character; - * returns +self+ if any changes were made, +nil+ otherwise: - * - * s = 'Hello World!' # => "Hello World!" - * s.swapcase! # => "hELLO wORLD!" - * s # => "hELLO wORLD!" - * ''.swapcase! # => nil + * Like String#swapcase, except that: * - * The casing may be affected by the given +mapping+; - * see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. - * - * Related: String#swapcase. + * - Changes are made to +self+, not to copy of +self+. + * - Returns +self+ if any changes are made, +nil+ otherwise. * + * Related: see {Modifying}[rdoc-ref:String@Modifying]. */ static VALUE @@ -8240,19 +8232,9 @@ rb_str_swapcase_bang(int argc, VALUE *argv, VALUE str) /* * call-seq: - * swapcase(mapping) -> string - * - * Returns a string containing the characters in +self+, with cases reversed; - * each uppercase character is downcased; - * each lowercase character is upcased: - * - * s = 'Hello World!' # => "Hello World!" - * s.swapcase # => "hELLO wORLD!" - * - * The casing may be affected by the given +mapping+; - * see {Case Mapping}[rdoc-ref:case_mapping.rdoc]. + * swapcase(mapping) -> new_string * - * Related: String#swapcase!. + * :include: doc/string/swapcase.rdoc * */