Skip to content

Commit

Permalink
str::is_char_boundary has been stable since Rust 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jun 29, 2017
1 parent ebc9ea7 commit d9ff7db
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions examples/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn fuzz() {
fn random_boundary<R: Rng>(rng: &mut R, text: &str) -> usize {
loop {
let i = Range::new(0, text.len()+1).ind_sample(rng);
if is_char_boundary(text, i) {
if text.is_char_boundary(i) {
return i;
}
}
Expand All @@ -115,25 +115,16 @@ fn random_slice<R: Rng>(rng: &mut R, text: &str) -> (usize, usize) {
loop {
let start = Range::new(0, text.len()+1).ind_sample(rng);
let end = Range::new(start, text.len()+1).ind_sample(rng);
if !is_char_boundary(text, start) {
if !text.is_char_boundary(start) {
continue;
}
if end < text.len() && !is_char_boundary(text, end) {
if end < text.len() && !text.is_char_boundary(end) {
continue;
}
return (start, end);
}
}

// Copy of the str::is_char_boundary method, which is unstable.
fn is_char_boundary(s: &str, index: usize) -> bool {
if index == s.len() { return true; }
match s.as_bytes().get(index) {
None => false,
Some(&b) => b < 128 || b >= 192,
}
}

static TEXT: &'static str =
"It was from the artists and poets that the pertinent answers came, and I \
know that panic would have broken loose had they been able to compare notes. \
Expand Down

0 comments on commit d9ff7db

Please sign in to comment.