add new tests and fix for #210
This commit is contained in:
parent
4db8941546
commit
98eeb362e2
|
@ -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();
|
||||
|
@ -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)
|
||||
|
|
2
testdata
2
testdata
|
@ -1 +1 @@
|
|||
Subproject commit ba7a0afa6509361e55b0e40b49de5b51a9f0f075
|
||||
Subproject commit 9eaccb5222c68c043eaaaf471617a5aa530394a9
|
Loading…
Reference in New Issue