Skip to content

Commit

Permalink
add new tests and fix for #210
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesturk committed May 28, 2024
1 parent 4db8941 commit 98eeb36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/match_rating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use unicode_segmentation::UnicodeSegmentation;

pub fn match_rating_codex(s: &str) -> Result<String, String> {
// match rating only really makes sense on strings

let s = &s.to_uppercase()[..];
let v = UnicodeSegmentation::graphemes(s, true).collect::<FastVec<&str>>();
let mut codex = String::new();
Expand All @@ -24,10 +25,12 @@ pub fn match_rating_codex(s: &str) -> Result<String, String> {
}

if codex.len() > 6 {
let mut newcodex = String::new();
newcodex.push_str(codex.get(..3).unwrap());
newcodex.push_str(codex.get(codex.len() - 3..).unwrap());
return Ok(newcodex);
// not safe to take a slice without conversion to chars() since there
// can be unicode left, this implementation matches the Python one
// even though MRC really shouldn't be used with unicode chars
let first_three: String = codex.chars().take(3).collect();
let last_three: String = codex.chars().rev().take(3).collect::<String>().chars().rev().collect();
return Ok(first_three + &last_three);
}

Ok(codex)
Expand Down
2 changes: 1 addition & 1 deletion testdata

0 comments on commit 98eeb36

Please sign in to comment.