Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhanced RDoc for String#succ #3590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 49 additions & 21 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -4160,27 +4160,55 @@ static VALUE str_succ(VALUE str);

/*
* call-seq:
* str.succ -> new_str
* str.next -> new_str
*
* Returns the successor to <i>str</i>. The successor is calculated by
* incrementing characters starting from the rightmost alphanumeric (or
* the rightmost character if there are no alphanumerics) in the
* string. Incrementing a digit always results in another digit, and
* incrementing a letter results in another letter of the same case.
* Incrementing nonalphanumerics uses the underlying character set's
* collating sequence.
*
* If the increment generates a ``carry,'' the character to the left of
* it is incremented. This process repeats until there is no carry,
* adding an additional character if necessary.
*
* "abcd".succ #=> "abce"
* "THX1138".succ #=> "THX1139"
* "<<koala>>".succ #=> "<<koalb>>"
* "1999zzz".succ #=> "2000aaa"
* "ZZZ9999".succ #=> "AAAA0000"
* "***".succ #=> "**+"
* string.succ -> new_str
*
* Returns the successor to +self+. The successor is calculated by
* incrementing characters.
*
* The first character to be incremented is the rightmost alphanumeric:
* or, if no alphanumerics, the rightmost character:
* 'THX1138'.succ # => "THX1139"
* '<<koala>>'.succ # => "<<koalb>>"
* '***'.succ # => '**+'
*
* The successor to a digit is another digit, "carrying" to the next-left
* character for a "rollover" from 9 to 0, and prepending another digit
* if necessary:
* '00'.succ # => "01"
* '09'.succ # => "10"
* '99'.succ # => "100"
*
* The successor to a letter is another letter of the same case,
* carrying to the next-left character for a rollover,
* and prepending another same-case letter if necessary:
* 'aa'.succ # => "ab"
* 'az'.succ # => "ba"
* 'zz'.succ # => "aaa"
* 'AA'.succ # => "AB"
* 'AZ'.succ # => "BA"
* 'ZZ'.succ # => "AAA"
*
* The successor to a non-alphanumeric character is the next character
* in the underlying character set's collating sequence,
* carrying to the next-left character for a rollover,
* and prepending another character if necessary:
* s = 0.chr * 3
* s # => "\x00\x00\x00"
* s.succ # => "\x00\x00\x01"
* s = 255.chr * 3
* s # => "\xFF\xFF\xFF"
* s.succ # => "\x01\x00\x00\x00"
*
* Carrying can occur between and among mixtures of alphanumeric characters:
* s = 'zz99zz99'
* s.succ # => "aaa00aa00"
* s = '99zz99zz'
* s.succ # => "100aa00aa"
*
* The successor to an empty \String is a new empty \String:
* ''.succ # => ""
*
* String#next is an alias for String#succ.
*/

VALUE
Expand Down