Skip to content

Commit

Permalink
Closer to correct indexing for arbitrary utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
tjpalmer committed Dec 9, 2018
1 parent 23619d5 commit e236547
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 2018/02/rust/compare/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> Try<()> {
let id = line?;
'others: for other in ids.iter() {
let mut diff_index = -1;
for (index, (c0, c1)) in id.chars().zip(other.chars()).enumerate() {
for ((index, c0), c1) in id.char_indices().zip(other.chars()) {
if c0 != c1 {
if diff_index >= 0 {
// More than one different.
Expand All @@ -21,7 +21,7 @@ fn main() -> Try<()> {
if diff_index >= 0 {
// If we get here, it's because we had only one different.
let (a, b) = id.split_at(diff_index as usize);
let c: String = b.chars().skip(1).collect();
let (_, c) = b.split_at(1);
println!("{}{}", a, c);
break 'lines;
}
Expand Down

0 comments on commit e236547

Please sign in to comment.