Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lowercase small words that are uppercase #7

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Lowercase small words that are uppercase
Fixes #6
  • Loading branch information
wezm committed Aug 30, 2022
commit e7ca3d62da24daaa78401732f57b2f4f9da9fa6c
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ const SMALL_WORDS: &[&str] = &[
/// ```
pub fn titlecase(input: &str) -> String {
lazy_static! {
static ref SMALL_RE: Regex = Regex::new(&format!(r"\A(?:{})\z", SMALL_WORDS.join("|")))
static ref SMALL_RE: Regex = Regex::new(&format!(r"(?i)\A(?:{})\z", SMALL_WORDS.join("|")))
.expect("unable to compile small words regex");
static ref CONTAINS_LOWERCASE: Regex =
Regex::new(r"[[:lower:]]").expect("unable to compile lowercase regex");
static ref WORDS: Regex = Regex::new(
r"(?x)
(_*)
([\w'’.:/@\[\]/()]+)
([\w'’.:/@\[\]/()&]+)
(_*)",
)
.expect("unable to compile regex");
Expand Down Expand Up @@ -424,4 +424,10 @@ mod tests {
"Jonathan Kim on Alex Gibney’s ‘Steve Jobs: The man in the machine’",
"Jonathan Kim on Alex Gibney’s ‘Steve Jobs: The Man in the Machine’"
);

testcase!(
lower_small_words,
"Way Of The Dragon makes Of In An A lowercase",
"Way of the Dragon Makes of in an a Lowercase"
);
}