Skip to content

Commit

Permalink
Rollup merge of #72773 - Rantanen:is_char_boundary-docs, r=joshtriplett
Browse files Browse the repository at this point in the history
Fix is_char_boundary documentation

Given the "start _and/or end_" wording in the original, the way I understood it was that the `str::is_char_boundary` method would also return `true` for the last byte in a UTF-8 code point sequence. (Which would have meant that for a string consisting of nothing but 1 and 2 byte UTF-8 code point sequences, it would return nothing but `true`.)

In practice the method returns `true` only for the starting byte of each sequence and the end of the string: [Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e9f5fc4d6bf2f1bf57a75f3c9a180770)

I was also somewhat tempted to remove the _The start and end of the string are considered to be boundaries_, since that's implied by the first sentence, but I decided to avoid bikeshedding over it and left it as it was since it's not wrong in relation to how the method behaves.
  • Loading branch information
RalfJung authored May 30, 2020
2 parents 356d1e9 + 66e9984 commit b7f6a0b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2270,12 +2270,11 @@ impl str {
self.len() == 0
}

/// Checks that `index`-th byte lies at the start and/or end of a
/// UTF-8 code point sequence.
/// Checks that `index`-th byte is the first byte in a UTF-8 code point
/// sequence or the end of the string.
///
/// The start and end of the string (when `index == self.len()`) are
/// considered to be
/// boundaries.
/// considered to be boundaries.
///
/// Returns `false` if `index` is greater than `self.len()`.
///
Expand Down

0 comments on commit b7f6a0b

Please sign in to comment.