Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This project follows [Semantic Versioning](https://semver.org/).
- `with_locale("en")` tries `en`, then `en_US`, then `en_GB`
- macOS `with_locale` stores the installed language tag that matched, and accepts a bare language when only a regional tag is installed
- Linux tokenization uses Hunspell `WORDCHARS`/`ICONV`, keeps curly apostrophes in words, trims edge quotes, and skips URLs and emails
- `is_correct` requires a single whitespace-delimited token with a letter or digit; empty and punctuation-only inputs are false

## [0.4.0] - 2026-08-25

Expand Down
27 changes: 26 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,28 @@ impl Checker {
self.0.check(text).map(SpellingError)
}

/// Returns true if `word` is spelled correctly.
/// Returns true if `word` is a single spelled-correctly token.
///
/// The input is trimmed. It must be exactly one whitespace-delimited token
/// that contains at least one letter or digit. Otherwise this returns
/// `false` (empty input, `"!!!"`, `"hello world"`, etc.).
pub fn is_correct(&self, word: &str) -> bool {
let word = word.trim();
if word.is_empty() {
return false;
}

let mut tokens = word.split_whitespace();
let Some(token) = tokens.next() else {
return false;
};
if tokens.next().is_some() {
return false;
}
if !token.chars().any(|c| c.is_alphanumeric()) {
return false;
}

self.check(word).next().is_none()
}

Expand Down Expand Up @@ -540,6 +560,11 @@ mod tests {
let checker = Checker::with_locale("en_US").unwrap();
assert!(checker.is_correct("believe"));
assert!(!checker.is_correct("beleeve"));
assert!(!checker.is_correct(""));
assert!(!checker.is_correct(" "));
assert!(!checker.is_correct("!!!"));
assert!(!checker.is_correct("hello world"));
assert!(checker.is_correct(" believe "));
}

#[test]
Expand Down
Loading