10000 [DOC] Tweaks for String#byterindex by BurdetteLamar · Pull Request #13485 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

[DOC] Tweaks for String#byterindex #13485

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BurdetteLamar
Copy link
Member

No description provided.

@BurdetteLamar BurdetteLamar added the Documentation Improvements to documentation. label May 31, 2025
/*
* call-seq:
* byterindex(substring, offset = self.bytesize) -> integer or nil
* byterindex(regexp, offset = self.bytesize) -> integer or nil
* byterindex(object, offset = 0) -> integer or nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the new default of offset of 0 is correct.

irb(main):003> "hello".byterindex("l")
=> 3
irb(main):004> "hello".byterindex("l", 0)
=> nil
irb(main):005> "hello".byterindex("l", 10)
=> 3

*
* Returns the Integer byte-based index of the _last_ occurrence of the given +substring+,
* or +nil+ if none found:
* Returns the 0-based integer index of a substring of +self+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's important to mention that it finds the last match in the first sentence.

* 'foo'.byterindex('o', 2) # => 2
* 'foo'.byterindex('o', 3) # => 2
* \Integer argument +offset+, if given, specifies the 0-based index
* of the byte where searching is to begin.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not correct, offset is the index to end the search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements to documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0