|
|
|
|
@ -47,7 +47,7 @@ pub(crate) fn split_words_and_numbers(s: &str) -> Vec<&str> {
|
|
|
|
|
for (idx, c) in s.char_indices() {
|
|
|
|
|
match word_start {
|
|
|
|
|
Some((start, start_c)) => {
|
|
|
|
|
if c.is_alphanumeric() || c == '_' {
|
|
|
|
|
if c.is_alphanumeric() || c == '-' || c == '_' {
|
|
|
|
|
// Word character, add to the current word if it's
|
|
|
|
|
// not a number.
|
|
|
|
|
if c.is_ascii_digit() == start_c.is_ascii_digit() {
|
|
|
|
|
@ -93,6 +93,13 @@ mod tests {
|
|
|
|
|
assert_eq!(res, vec!["example", ".", "com"])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_split_words_hyphens() {
|
|
|
|
|
let s = "foo -bar-baz-";
|
|
|
|
|
let res = split_words(s);
|
|
|
|
|
assert_eq!(res, vec!["foo", " ", "-bar-baz-"])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_split_words_punctuation() {
|
|
|
|
|
let s = "example..";
|
|
|
|
|
@ -142,6 +149,13 @@ mod tests {
|
|
|
|
|
assert_eq!(res, vec!["a", "123", "b"])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_split_words_and_numbers_hyphens() {
|
|
|
|
|
let s = "a-b -c-";
|
|
|
|
|
let res = split_words_and_numbers(s);
|
|
|
|
|
assert_eq!(res, vec!["a-b", " ", "-c-"])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_split_words_and_numbers_spaces() {
|
|
|
|
|
let s = "foo bar";
|
|
|
|
|
|