Don't panic in ceil_char_boundary
This commit is contained in:
parent
e94bda3bf1
commit
43453a8ebf
1 changed files with 3 additions and 4 deletions
|
|
@ -271,14 +271,13 @@ impl str {
|
|||
|
||||
/// Finds the closest `x` not below `index` where `is_char_boundary(x)` is `true`.
|
||||
///
|
||||
/// If `x` is greater than the length of the string, this returns the length of the string.
|
||||
///
|
||||
/// This method is the natural complement to [`floor_char_boundary`]. See that method
|
||||
/// for more details.
|
||||
///
|
||||
/// [`floor_char_boundary`]: str::floor_char_boundary
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `index > self.len()`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
@ -296,7 +295,7 @@ impl str {
|
|||
#[inline]
|
||||
pub fn ceil_char_boundary(&self, index: usize) -> usize {
|
||||
if index > self.len() {
|
||||
slice_error_fail(self, index, index)
|
||||
self.len()
|
||||
} else {
|
||||
let upper_bound = Ord::min(index + 4, self.len());
|
||||
self.as_bytes()[index..upper_bound]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue