Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

refactor: compact token/lint content & char comparison (#2957)

Andrew Dunbar0cb715711e9a
diff --git a/harper-cli/src/lint.rs b/harper-cli/src/lint.rs
index d7330cf0e..b0c191819 100644
--- a/harper-cli/src/lint.rs
+++ b/harper-cli/src/lint.rs
@@ -480,7 +480,7 @@ fn lint_one_input(
for lint in rule_lints {
let (line, column) =
char_index_to_line_col(source_chars, lint.span.start);
- let matched_text = lint.span.get_content_string(source_chars);
+ let matched_text = lint.get_str(source_chars);
let suggestions: Vec<String> =
lint.suggestions.iter().map(|s| format!("{s}")).collect();
lints.push(JsonLint {
@@ -611,7 +611,7 @@ fn collect_spellos(
.get("SpellCheck")
.into_iter()
.flatten()
- .map(|lint| lint.span.get_content_string(source))
+ .map(|lint| lint.get_str(source))
.fold(HashMap::new(), |mut acc, spello| {
*acc.entry(spello).or_insert(0) += 1;
acc
@@ -768,7 +768,7 @@ fn find_longest_doc_line(toks: &[Token]) -> usize {
curr_len_chars = 0;
current_line_start_tok_idx = idx + 1;
} else if matches!(tok.kind, TokenKind::Unlintable) {
- // TODO would be more accurate to scan for \n in the tok.span.get_content(src)
+ // TODO would be more accurate to scan for \n in the tok.get_ch(src)
} else {
curr_len_chars += tok.span.len();
}
diff --git a/harper-core/src/char_string.rs b/harper-core/src/char_string.rs
index 3182e1e3a..72bebe345 100644
--- a/harper-core/src/char_string.rs
+++ b/harper-core/src/char_string.rs
@@ -29,11 +29,11 @@ pub trait CharStringExt: private::Sealed {
/// Case-insensitive comparison with a character slice, assuming the right-hand side is lowercase ASCII.
/// Only normalizes the left side to lowercase and avoids allocations.
- fn eq_ignore_ascii_case_chars(&self, other: &[char]) -> bool;
+ fn eq_ch(&self, other: &[char]) -> bool;
/// Case-insensitive comparison with a string slice, assuming the right-hand side is lowercase ASCII.
/// Only normalizes the left side to lowercase and avoids allocations.
- fn eq_ignore_ascii_case_str(&self, other: &str) -> bool;
+ fn eq_str(&self, other: &str) -> bool;
/// Case-insensitive comparison with any of a list of string slices, assuming the right-hand side is lowercase ASCII.
/// Only normalizes the left side to lowercase and avoids allocations.
@@ -100,7 +100,7 @@ impl CharStringExt for [char] {
}
}
- fn eq_ignore_ascii_case_str(&self, other: &str) -> bool {
+ fn eq_str(&self, other: &str) -> bool {
let mut chit = self.iter();
let mut strit = other.chars();
@@ -118,7 +118,7 @@ impl CharStringExt for [char] {
}
}
- fn eq_ignore_ascii_case_chars(&self, other: &[char]) -> bool {
+ fn eq_ch(&self, other: &[char]) -> bool {
self.len() == other.len()
&& self
.iter()
@@ -127,13 +127,11 @@ impl CharStringExt for [char] {
}
fn eq_any_ignore_ascii_case_str(&self, others: &[&str]) -> bool {
- others.iter().any(|str| self.eq_ignore_ascii_case_str(str))
+ others.iter().any(|str| self.eq_str(str))
}
fn eq_any_ignore_ascii_case_chars(&self, others: &[&[char]]) -> bool {
- others
- .iter()
- .any(|chars| self.eq_ignore_ascii_case_chars(chars))
+ others.iter().any(|chars| self.eq_ch(chars))
}
fn starts_with_ignore_ascii_case_str(&self, prefix: &str) -> bool {
@@ -206,22 +204,22 @@ mod tests {
#[test]
fn eq_ignore_ascii_case_chars_matches_lowercase() {
- assert!(['H', 'e', 'l', 'l', 'o'].eq_ignore_ascii_case_chars(&['h', 'e', 'l', 'l', 'o']));
+ assert!(['H', 'e', 'l', 'l', 'o'].eq_ch(&['h', 'e', 'l', 'l', 'o']));
}
#[test]
fn eq_ignore_ascii_case_chars_does_not_match_different_word() {
- assert!(!['H', 'e', 'l', 'l', 'o'].eq_ignore_ascii_case_chars(&['w', 'o', 'r', 'l', 'd']));
+ assert!(!['H', 'e', 'l', 'l', 'o'].eq_ch(&['w', 'o', 'r', 'l', 'd']));
}
#[test]
fn eq_ignore_ascii_case_str_matches_lowercase() {
- assert!(['H', 'e', 'l', 'l', 'o'].eq_ignore_ascii_case_str("hello"));
+ assert!(['H', 'e', 'l', 'l', 'o'].eq_str("hello"));
}
#[test]
fn eq_ignore_ascii_case_str_does_not_match_different_word() {
- assert!(!['H', 'e', 'l', 'l', 'o'].eq_ignore_ascii_case_str("world"));
+ assert!(!['H', 'e', 'l', 'l', 'o'].eq_str("world"));
}
#[test]
@@ -249,11 +247,11 @@ mod tests {
#[test]
fn differs_only_by_length_1() {
- assert!(!['b', 'b'].eq_ignore_ascii_case_str("b"));
+ assert!(!['b', 'b'].eq_str("b"));
}
#[test]
fn differs_only_by_length_2() {
- assert!(!['c'].eq_ignore_ascii_case_str("cc"));
+ assert!(!['c'].eq_str("cc"));
}
}
diff --git a/harper-core/src/document.rs b/harper-core/src/document.rs
index dd8638ed4..34adf59e5 100644
--- a/harper-core/src/document.rs
+++ b/harper-core/src/document.rs
@@ -187,31 +187,38 @@ impl Document {
let token_strings: Vec<_> = sent
.iter()
.filter(|t| !t.kind.is_whitespace())
- .map(|t| t.span.get_content_string(&self.source))
+ .map(|t| t.get_str(&self.source))
.collect();
let token_tags = tagger.tag_sentence(&token_strings);
let np_flags = chunker.chunk_sentence(&token_strings, &token_tags);
- let mut i = 0;
-
// Annotate DictWord metadata
+ let word_sources: Vec<_> = sent
+ .iter()
+ .filter(|t| matches!(t.kind, TokenKind::Word(_)))
+ .map(|t| t.get_ch(&self.source))
+ .collect();
+
+ let mut ti = 0; // Index for token_tags/np_flags (all non-whitespace tokens)
+ let mut wi = 0; // Index for word_sources (only word tokens)
for token in sent.iter_mut() {
if let TokenKind::Word(meta) = &mut token.kind {
- let word_source = token.span.get_content(&self.source);
+ let word_source = word_sources[wi];
let mut found_meta = dictionary
.get_word_metadata(word_source)
.map(|c| c.into_owned());
if let Some(inner) = &mut found_meta {
- inner.pos_tag = token_tags[i].or_else(|| inner.infer_pos_tag());
- inner.np_member = Some(np_flags[i]);
+ inner.pos_tag = token_tags[ti].or_else(|| inner.infer_pos_tag());
+ inner.np_member = Some(np_flags[ti]);
}
*meta = found_meta;
- i += 1;
+ ti += 1;
+ wi += 1;
} else if !token.kind.is_whitespace() {
- i += 1;
+ ti += 1;
}
}
}
@@ -672,7 +679,7 @@ impl Document {
|| (l.is_some_and(|t| t.kind.is_open_round())
&& r.is_some_and(|t| t.kind.is_close_round())))
&& {
- let ext_chars = x.span.get_content(&self.source);
+ let ext_chars = x.get_ch(&self.source);
ext_chars.iter().all(|c| c.is_ascii_lowercase())
|| ext_chars.iter().all(|c| c.is_ascii_uppercase())
};
@@ -735,13 +742,11 @@ impl Document {
let is_tld_chunk = d.kind.is_period()
&& tld.kind.is_word()
&& tld
- .span
- .get_content(&self.source)
+ .get_ch(&self.source)
.iter()
.all(|c| c.is_ascii_alphabetic())
&& tld
- .span
- .get_content(&self.source)
+ .get_ch(&self.source)
.eq_any_ignore_ascii_case_str(COMMON_TOP_LEVEL_DOMAINS)
&& ((l.is_none_or(|t| t.kind.is_whitespace())
&& r.is_none_or(|t| t.kind.is_whitespace()))
@@ -774,17 +779,13 @@ impl Document {
let is_tldr_chunk = tl.kind.is_word()
&& tl.span.len() == 2
- && tl
- .span
- .get_content(&self.source)
- .eq_ignore_ascii_case_chars(&['t', 'l'])
+ && tl.get_ch(&self.source).eq_ch(&['t', 'l'])
&& simicolon.kind.is_semicolon()
&& dr.kind.is_word()
&& dr.span.len() >= 2
&& dr.span.len() <= 3
&& dr
- .span
- .get_content(&self.source)
+ .get_ch(&self.source)
.eq_any_ignore_ascii_case_chars(&[&['d', 'r'], &['d', 'r', 's']]);
if is_tldr_chunk {
@@ -842,8 +843,8 @@ impl Document {
if is_delimited_chunk {
let (l1, l2) = (
- l1.span.get_content(&self.source).first(),
- l2.span.get_content(&self.source).first(),
+ l1.get_ch(&self.source).first(),
+ l2.get_ch(&self.source).first(),
);
let is_valid_pair = match (l1, l2) {
@@ -1313,10 +1314,10 @@ mod tests {
let tldrs = doc
.tokens
.iter()
- .filter(|t| t.span.get_content(&doc.source).contains(&';'))
+ .filter(|t| t.get_ch(&doc.source).contains(&';'))
.collect_vec();
assert!(tldrs.len() == 1);
- assert!(tldrs[0].span.get_content_string(&doc.source) == "TL;DRs");
+ assert!(tldrs[0].get_str(&doc.source) == "TL;DRs");
}
#[test]
@@ -1383,7 +1384,7 @@ mod tests {
Document::new_plain_english_curated("A Q&A platform software for teams at any scales.");
assert!(doc.tokens.len() >= 3);
assert!(doc.tokens[2].kind.is_word());
- assert!(doc.tokens[2].span.get_content_string(&doc.source) == "Q&A");
+ assert!(doc.tokens[2].get_str(&doc.source) == "Q&A");
}
#[test]
diff --git a/harper-core/src/expr/mergeable_words.rs b/harper-core/src/expr/mergeable_words.rs
index f63e3ab0d..4af163ecc 100644
--- a/harper-core/src/expr/mergeable_words.rs
+++ b/harper-core/src/expr/mergeable_words.rs
@@ -39,8 +39,8 @@ impl MergeableWords {
word_b: &Token,
source: &[char],
) -> Option<CharString> {
- let a_chars: CharString = word_a.span.get_content(source).into();
- let b_chars: CharString = word_b.span.get_content(source).into();
+ let a_chars: CharString = word_a.get_ch(source).into();
+ let b_chars: CharString = word_b.get_ch(source).into();
// First check if the open compound exists in the dictionary
let mut compound = a_chars.clone();
diff --git a/harper-core/src/expr/sequence_expr.rs b/harper-core/src/expr/sequence_expr.rs
index bd43d7a9e..8a0393069 100644
--- a/harper-core/src/expr/sequence_expr.rs
+++ b/harper-core/src/expr/sequence_expr.rs
@@ -298,10 +298,7 @@ impl SequenceExpr {
/// Match any word except the ones in `words`.
pub fn then_word_except(self, words: &'static [&'static str]) -> Self {
self.then(move |tok: &Token, src: &[char]| {
- !tok.kind.is_word()
- || !words
- .iter()
- .any(|&word| tok.span.get_content(src).eq_ignore_ascii_case_str(word))
+ !tok.kind.is_word() || !words.iter().any(|&word| tok.get_ch(src).eq_str(word))
})
}
@@ -332,10 +329,7 @@ impl SequenceExpr {
F: Fn(&TokenKind) -> bool + Send + Sync + 'static,
{
self.then(move |tok: &Token, src: &[char]| {
- pred_is(&tok.kind)
- && !ex
- .iter()
- .any(|&word| tok.span.get_content(src).eq_ignore_ascii_case_str(word))
+ pred_is(&tok.kind) && !ex.iter().any(|&word| tok.get_ch(src).eq_str(word))
})
}
@@ -396,9 +390,7 @@ impl SequenceExpr {
self.then(move |tok: &Token, src: &[char]| {
pred_is(&tok.kind)
&& !pred_not(&tok.kind)
- && !ex
- .iter()
- .any(|&word| tok.span.get_content(src).eq_ignore_ascii_case_str(word))
+ && !ex.iter().any(|&word| tok.get_ch(src).eq_str(word))
})
}
@@ -432,9 +424,7 @@ impl SequenceExpr {
self.then(move |tok: &Token, src: &[char]| {
pred_is(&tok.kind)
&& !preds_isnt.iter().any(|pred| pred(&tok.kind))
- && !ex
- .iter()
- .any(|&word| tok.span.get_content(src).eq_ignore_ascii_case_str(word))
+ && !ex.iter().any(|&word| tok.get_ch(src).eq_str(word))
})
}
@@ -486,9 +476,7 @@ impl SequenceExpr {
{
self.then(move |tok: &Token, src: &[char]| {
preds_is.iter().any(|pred| pred(&tok.kind))
- && !ex
- .iter()
- .any(|&word| tok.span.get_content(src).eq_ignore_ascii_case_str(word))
+ && !ex.iter().any(|&word| tok.get_ch(src).eq_str(word))
})
}
@@ -504,9 +492,7 @@ impl SequenceExpr {
{
self.then(move |tok: &Token, src: &[char]| {
preds.iter().any(|pred| pred(&tok.kind))
- || words
- .iter()
- .any(|&word| tok.span.get_content(src).eq_ignore_ascii_case_str(word))
+ || words.iter().any(|&word| tok.get_ch(src).eq_str(word))
})
}
@@ -525,9 +511,7 @@ impl SequenceExpr {
self.then(move |tok: &Token, src: &[char]| {
preds_is.iter().any(|pred| pred(&tok.kind))
&& !pred_not(&tok.kind)
- && !ex
- .iter()
- .any(|&word| tok.span.get_content(src).eq_ignore_ascii_case_str(word))
+ && !ex.iter().any(|&word| tok.get_ch(src).eq_str(word))
})
}
diff --git a/harper-core/src/expr/word_expr_group.rs b/harper-core/src/expr/word_expr_group.rs
index 2e05a49d6..d0dc95e61 100644
--- a/harper-core/src/expr/word_expr_group.rs
+++ b/harper-core/src/expr/word_expr_group.rs
@@ -45,7 +45,7 @@ where
return None;
}
- let word_chars = first.span.get_content(source);
+ let word_chars = first.get_ch(source);
let inner_pattern = self.exprs.get(word_chars)?;
inner_pattern.run(cursor, tokens, source)
diff --git a/harper-core/src/language_detection.rs b/harper-core/src/language_detection.rs
index 0408012cb..a2bd86268 100644
--- a/harper-core/src/language_detection.rs
+++ b/harper-core/src/language_detection.rs
@@ -21,7 +21,7 @@ pub fn is_likely_english(toks: &[Token], source: &[char], dict: &impl Dictionary
TokenKind::Word(_) => {
total_words += 1;
- let word_content = token.span.get_content(source);
+ let word_content = token.get_ch(source);
if dict.contains_word(word_content) {
valid_words += 1;
}
diff --git a/harper-core/src/linting/addicting.rs b/harper-core/src/linting/addicting.rs
index 9b2d0df9e..7a414b821 100644
--- a/harper-core/src/linting/addicting.rs
+++ b/harper-core/src/linting/addicting.rs
@@ -49,7 +49,7 @@ impl ExprLinter for Addicting {
lint_kind: LintKind::Style,
suggestions: vec![Suggestion::replace_with_match_case(
"addictive".chars().collect(),
- tok.span.get_content(src),
+ tok.get_ch(src),
)],
message: "When used as an adjective, `addictive` is the traditional and more f form."
.to_owned(),
diff --git a/harper-core/src/linting/adjective_double_degree.rs b/harper-core/src/linting/adjective_double_degree.rs
index aabcce5d4..afd41c6a7 100644
--- a/harper-core/src/linting/adjective_double_degree.rs
+++ b/harper-core/src/linting/adjective_double_degree.rs
@@ -32,10 +32,10 @@ impl ExprLinter for AdjectiveDoubleDegree {
let phrase_span = toks.span()?;
let phrase_chars = phrase_span.get_content(src);
- let adj_chars = toks.last()?.span.get_content(src);
+ let adj_chars = toks.last()?.get_ch(src);
let (lint_kind, message, suggestions) = match (
- &toks.first()?.span.get_content(src).to_lower().as_ref(),
+ &toks.first()?.get_ch(src).to_lower().as_ref(),
toks.last()?.kind.is_comparative_adjective(),
toks.last()?.kind.is_superlative_adjective(),
) {
diff --git a/harper-core/src/linting/all_intents_and_purposes.rs b/harper-core/src/linting/all_intents_and_purposes.rs
index 6d33853cf..c467d15dc 100644
--- a/harper-core/src/linting/all_intents_and_purposes.rs
+++ b/harper-core/src/linting/all_intents_and_purposes.rs
@@ -60,12 +60,12 @@ impl ExprLinter for AllIntentsAndPurposes {
return None;
}
- let prep_text = toks.first().unwrap().span.get_content(src);
+ let prep_text = toks.first().unwrap().get_ch(src);
let mut suggs = LEGIT.to_vec();
// Suggest "to" first if the text uses "to", otherwise "for" first
- if prep_text.eq_ignore_ascii_case_chars(&['t', 'o']) {
+ if prep_text.eq_ch(&['t', 'o']) {
suggs.swap(0, 1);
}
diff --git a/harper-core/src/linting/allow_to.rs b/harper-core/src/linting/allow_to.rs
index 0eaed50d2..59b5be822 100644
--- a/harper-core/src/linting/allow_to.rs
+++ b/harper-core/src/linting/allow_to.rs
@@ -32,7 +32,7 @@ impl ExprLinter for AllowTo {
fn match_to_lint(&self, toks: &[Token], _src: &[char]) -> Option<Lint> {
let span = toks.span()?;
let first = toks.first()?;
- let allow = first.span.get_content_string(_src);
+ let allow = first.get_str(_src);
let message = format!(
"For correct usage, either add a subject between `{allow}` and `to` (e.g., `{allow} someone to do`) or use the present participle (e.g., `{allow} doing`)."
diff --git a/harper-core/src/linting/and_in.rs b/harper-core/src/linting/and_in.rs
index cf578610a..bc10e7cfe 100644
--- a/harper-core/src/linting/and_in.rs
+++ b/harper-core/src/linting/and_in.rs
@@ -33,7 +33,7 @@ impl ExprLinter for AndIn {
message: "Did you mean `and in`?".to_string(),
suggestions: vec![Suggestion::replace_with_match_case(
['a', 'n', 'd'].to_vec(),
- toks[2].span.get_content(src),
+ toks[2].get_ch(src),
)],
..Default::default()
})
diff --git a/harper-core/src/linting/and_the_like.rs b/harper-core/src/linting/and_the_like.rs
index 7f4457dd5..ac5c811bb 100644
--- a/harper-core/src/linting/and_the_like.rs
+++ b/harper-core/src/linting/and_the_like.rs
@@ -45,13 +45,13 @@ impl ExprLinter for AndTheLike {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let (conj, ws) = (&toks[0], &toks[1]);
- let conj = if conj.span.get_content(src)[0] == 'a' {
+ let conj = if conj.get_ch(src)[0] == 'a' {
"and"
} else {
"or"
};
- let corrected = format!("{}{}the like", conj, ws.span.get_content_string(src));
+ let corrected = format!("{}{}the like", conj, ws.get_str(src));
Some(Lint {
span: toks.span()?,
diff --git a/harper-core/src/linting/ask_no_preposition.rs b/harper-core/src/linting/ask_no_preposition.rs
index 9e31bd956..3e08cbcd0 100644
--- a/harper-core/src/linting/ask_no_preposition.rs
+++ b/harper-core/src/linting/ask_no_preposition.rs
@@ -41,7 +41,7 @@ impl ExprLinter for AskNoPreposition {
return None;
}
- let verb = toks[0].span.get_content_string(src).to_lowercase();
+ let verb = toks[0].get_str(src).to_lowercase();
let span = Span::new(toks[2].span.start, toks[3].span.end);
Some(Lint {
diff --git a/harper-core/src/linting/bought.rs b/harper-core/src/linting/bought.rs
index b1c8d3b7a..dbc0285ae 100644
--- a/harper-core/src/linting/bought.rs
+++ b/harper-core/src/linting/bought.rs
@@ -36,7 +36,7 @@ impl ExprLinter for Bought {
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case(
"bought".chars().collect(),
- typo.span.get_content(source),
+ typo.get_ch(source),
)],
message: "Prefer the past-tense form `bought` here.".to_owned(),
priority: 31,
@@ -58,7 +58,7 @@ impl Bought {
return false;
}
- let text = token.span.get_content_string(source);
+ let text = token.get_str(source);
let lower = text.to_ascii_lowercase();
let Some((stem, suffix)) = lower.split_once('\'') else {
diff --git a/harper-core/src/linting/cant.rs b/harper-core/src/linting/cant.rs
index 0e38c3094..b3dc7985d 100644
--- a/harper-core/src/linting/cant.rs
+++ b/harper-core/src/linting/cant.rs
@@ -40,12 +40,10 @@ impl ExprLinter for Cant {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let token = find_the_only_token_matching(toks, src, |tok, src| {
- tok.span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['c', 'a', 'n', 't'])
+ tok.get_ch(src).eq_ch(&['c', 'a', 'n', 't'])
})?;
- let jargon = token.span.get_content(src);
+ let jargon = token.get_ch(src);
let cannot = "can't";
Some(Lint {
diff --git a/harper-core/src/linting/comma_fixes.rs b/harper-core/src/linting/comma_fixes.rs
index 15e9ca8b3..7905c7942 100644
--- a/harper-core/src/linting/comma_fixes.rs
+++ b/harper-core/src/linting/comma_fixes.rs
@@ -36,7 +36,7 @@ impl Linter for CommaFixes {
let kinds = (
toks.0.map(|t| &t.kind),
toks.1.map(|t| &t.kind),
- *toks.2.span.get_content(source).first().unwrap(),
+ *toks.2.get_ch(source).first().unwrap(),
toks.3.map(|t| &t.kind),
toks.4.map(|t| &t.kind),
);
diff --git a/harper-core/src/linting/compound_nouns/compound_noun_after_det_adj.rs b/harper-core/src/linting/compound_nouns/compound_noun_after_det_adj.rs
index 154b394c5..299fa8cae 100644
--- a/harper-core/src/linting/compound_nouns/compound_noun_after_det_adj.rs
+++ b/harper-core/src/linting/compound_nouns/compound_noun_after_det_adj.rs
@@ -26,7 +26,7 @@ impl Default for CompoundNounAfterDetAdj {
fn default() -> Self {
let context_expr = SequenceExpr::with(|tok: &Token, src: &[char]| {
tok.kind.is_determiner()
- || (tok.kind.is_adjective() && *tok.span.get_content(src).to_lower() != ['g', 'o'])
+ || (tok.kind.is_adjective() && *tok.get_ch(src).to_lower() != ['g', 'o'])
})
.t_ws()
.then(is_content_word)
@@ -60,7 +60,7 @@ impl ExprLinter for CompoundNounAfterDetAdj {
.first()?
.span
.get_content(source)
- .eq_ignore_ascii_case_str("that")
+ .eq_str("that")
{
return None;
}
diff --git a/harper-core/src/linting/compound_nouns/compound_noun_before_aux_verb.rs b/harper-core/src/linting/compound_nouns/compound_noun_before_aux_verb.rs
index 235000df6..620c36e9c 100644
--- a/harper-core/src/linting/compound_nouns/compound_noun_before_aux_verb.rs
+++ b/harper-core/src/linting/compound_nouns/compound_noun_before_aux_verb.rs
@@ -58,7 +58,7 @@ impl ExprLinter for CompoundNounBeforeAuxVerb {
suggestions: vec![Suggestion::replace_with_match_case(word.to_vec(), orig)],
message: format!(
"The auxiliary verb “{}” implies the existence of the closed compound noun “{}”.",
- matched_tokens[4].span.get_content(source).to_string(),
+ matched_tokens[4].get_ch(source).to_string(),
word.to_string()
),
priority: 63,
diff --git a/harper-core/src/linting/compound_nouns/mod.rs b/harper-core/src/linting/compound_nouns/mod.rs
index c45ab8291..e7f2642ec 100644
--- a/harper-core/src/linting/compound_nouns/mod.rs
+++ b/harper-core/src/linting/compound_nouns/mod.rs
@@ -14,7 +14,7 @@ pub(crate) fn is_content_word(tok: &Token, src: &[char]) -> bool {
tok.span.len() > 1
&& (meta.is_noun() || meta.is_adjective() || meta.is_verb() || meta.is_adverb())
&& !(meta.is_determiner() || meta.is_conjunction())
- && (!meta.preposition || tok.span.get_content(src).eq_ignore_ascii_case_str("bar"))
+ && (!meta.preposition || tok.get_ch(src).eq_str("bar"))
}
pub(crate) fn predicate(
diff --git a/harper-core/src/linting/compound_subject_i.rs b/harper-core/src/linting/compound_subject_i.rs
index 3c7cf55d9..e5bbb664a 100644
--- a/harper-core/src/linting/compound_subject_i.rs
+++ b/harper-core/src/linting/compound_subject_i.rs
@@ -46,13 +46,9 @@ impl ExprLinter for CompoundSubjectI {
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let pronoun = matched_tokens.iter().find(|tok| {
- tok.kind.is_word()
- && tok
- .span
- .get_content_string(source)
- .eq_ignore_ascii_case("me")
- })?;
+ let pronoun = matched_tokens
+ .iter()
+ .find(|tok| tok.kind.is_word() && tok.get_str(source).eq_ignore_ascii_case("me"))?;
Some(Lint {
span: pronoun.span,
lint_kind: LintKind::Grammar,
diff --git a/harper-core/src/linting/cure_for.rs b/harper-core/src/linting/cure_for.rs
index ecf99e01a..6ac1e982c 100644
--- a/harper-core/src/linting/cure_for.rs
+++ b/harper-core/src/linting/cure_for.rs
@@ -30,7 +30,7 @@ impl ExprLinter for CureFor {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let against = matched_tokens.last()?;
- let template: Vec<char> = against.span.get_content(source).to_vec();
+ let template: Vec<char> = against.get_ch(source).to_vec();
let suggestion = Suggestion::replace_with_match_case_str("for", &template);
Some(Lint {
diff --git a/harper-core/src/linting/damages.rs b/harper-core/src/linting/damages.rs
index f164ed064..cc71076bc 100644
--- a/harper-core/src/linting/damages.rs
+++ b/harper-core/src/linting/damages.rs
@@ -52,7 +52,7 @@ impl ExprLinter for Damages {
// Singular noun/verb lemma is not an error but during development we'll print uses of it
// to observe its context.
- if damage_chars.eq_ignore_ascii_case_chars(&['d', 'a', 'm', 'a', 'g', 'e']) {
+ if damage_chars.eq_ch(&['d', 'a', 'm', 'a', 'g', 'e']) {
return None;
}
@@ -88,10 +88,7 @@ impl ExprLinter for Damages {
if (prev_word.kind.is_adjective()
|| prev_word.kind.is_determiner()
|| prev_word.kind.is_preposition())
- && !prev_word
- .span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
+ && !prev_word.get_ch(src).eq_ch(&['t', 'o'])
{
can = CanPrecede::Noun;
}
@@ -135,15 +132,13 @@ impl ExprLinter for Damages {
// 1. "If you encounter any issues, errors, or damages resulting from the use of these templates,
// the repository author assumes no responsibility or liability."
// 2. "The author will not be liable for any losses and/or damages in connection with the use of our website"
- if pretoks.iter().any(|t| {
- t.span
- .get_content(src)
- .eq_any_ignore_ascii_case_str(KEYWORDS)
- }) || postoks.iter().any(|t| {
- t.span
- .get_content(src)
- .eq_any_ignore_ascii_case_str(KEYWORDS)
- }) {
+ if pretoks
+ .iter()
+ .any(|t| t.get_ch(src).eq_any_ignore_ascii_case_str(KEYWORDS))
+ || postoks
+ .iter()
+ .any(|t| t.get_ch(src).eq_any_ignore_ascii_case_str(KEYWORDS))
+ {
return None;
}
diff --git a/harper-core/src/linting/day_and_age.rs b/harper-core/src/linting/day_and_age.rs
index 2f19183f2..2174b56fb 100644
--- a/harper-core/src/linting/day_and_age.rs
+++ b/harper-core/src/linting/day_and_age.rs
@@ -44,8 +44,7 @@ impl ExprLinter for DayAndAge {
&& last.kind.is_whitespace()
&& (penult.kind.is_preposition()
|| penult
- .span
- .get_content(src)
+ .get_ch(src)
.eq_any_ignore_ascii_case_chars(&[&['i', 's'], &['i', 't']]))
{
Some(penult.span)
@@ -68,13 +67,13 @@ impl ExprLinter for DayAndAge {
let bads: Vec<bool> = chars
.iter()
.zip(good.iter())
- .map(|(actual, &good)| !actual.eq_ignore_ascii_case_chars(good))
+ .map(|(actual, &good)| !actual.eq_ch(good))
.collect();
let good_main = !bads.iter().any(|&b| b);
let (span, replacement): (Span<char>, &str) = if prep_chars
- .is_some_and(|p| p.eq_ignore_ascii_case_chars(&['s', 'i', 'n', 'c', 'e']))
+ .is_some_and(|p| p.eq_ch(&['s', 'i', 'n', 'c', 'e']))
{
// "since" is a preposition but it's also a conjunction, so keep it but add "in" after it
(main_span, "in this day and age")
diff --git a/harper-core/src/linting/despite_it_is.rs b/harper-core/src/linting/despite_it_is.rs
index 19e599cf4..2217ff646 100644
--- a/harper-core/src/linting/despite_it_is.rs
+++ b/harper-core/src/linting/despite_it_is.rs
@@ -66,8 +66,8 @@ impl ExprLinter for DespiteItIs {
return None;
}
- let subj_chars = subj.span.get_content(src);
- let be_chars = be.span.get_content(src);
+ let subj_chars = subj.get_ch(src);
+ let be_chars = be.get_ch(src);
let pron_be_toks = &toks[2..5];
let subj_pers = subj_kind.get_pronoun_person()?;
@@ -90,9 +90,9 @@ impl ExprLinter for DespiteItIs {
(Person::Second, true, true) => ("you", "your"),
(Person::Third, false, true) => ("them", "their"),
(Person::Third, true, false) => match subj_chars {
- chs if chs.eq_ignore_ascii_case_chars(&['h', 'e']) => ("him", "his"),
- chs if chs.eq_ignore_ascii_case_chars(&['s', 'h', 'e']) => ("her", "her"),
- chs if chs.eq_ignore_ascii_case_chars(&['i', 't']) => ("it", "its"),
+ chs if chs.eq_ch(&['h', 'e']) => ("him", "his"),
+ chs if chs.eq_ch(&['s', 'h', 'e']) => ("her", "her"),
+ chs if chs.eq_ch(&['i', 't']) => ("it", "its"),
_ => return None,
},
_ => return None,
diff --git a/harper-core/src/linting/didnt.rs b/harper-core/src/linting/didnt.rs
index f34700a37..acb99985e 100644
--- a/harper-core/src/linting/didnt.rs
+++ b/harper-core/src/linting/didnt.rs
@@ -33,7 +33,7 @@ impl ExprLinter for Didnt {
lint_kind: LintKind::Typo,
suggestions: vec![Suggestion::replace_with_match_case_str(
"didn't",
- suspect.span.get_content(src),
+ suspect.get_ch(src),
)],
message: "Consider using `didn't` here.".to_string(),
priority: 63,
diff --git a/harper-core/src/linting/disjoint_prefixes.rs b/harper-core/src/linting/disjoint_prefixes.rs
index 91210a0b6..c726d2498 100644
--- a/harper-core/src/linting/disjoint_prefixes.rs
+++ b/harper-core/src/linting/disjoint_prefixes.rs
@@ -85,9 +85,9 @@ where
// that could result from naively using toks.span()?.get_content_string(src)
let original = format!(
"{}{}{}",
- toks[0].span.get_content_string(src),
+ toks[0].get_str(src),
if toks[1].kind.is_hyphen() { '-' } else { ' ' },
- toks[2].span.get_content_string(src)
+ toks[2].get_str(src)
);
// If the original form is in the dictionary, return None
@@ -97,17 +97,9 @@ where
let mut hyphenated = None;
if !toks[1].kind.is_hyphen() {
- hyphenated = Some(format!(
- "{}-{}",
- toks[0].span.get_content_string(src),
- toks[2].span.get_content_string(src)
- ));
+ hyphenated = Some(format!("{}-{}", toks[0].get_str(src), toks[2].get_str(src)));
}
- let joined = Some(format!(
- "{}{}",
- toks[0].span.get_content_string(src),
- toks[2].span.get_content_string(src)
- ));
+ let joined = Some(format!("{}{}", toks[0].get_str(src), toks[2].get_str(src)));
// Check if either joined or hyphenated form is in the dictionary
let joined_valid = joined
diff --git a/harper-core/src/linting/do_mistake.rs b/harper-core/src/linting/do_mistake.rs
index 162868031..69cdc914e 100644
--- a/harper-core/src/linting/do_mistake.rs
+++ b/harper-core/src/linting/do_mistake.rs
@@ -60,13 +60,13 @@ impl ExprLinter for DoMistake {
return None;
}
- let make = if chars.eq_ignore_ascii_case_str("do") {
+ let make = if chars.eq_str("do") {
"make"
- } else if chars.eq_ignore_ascii_case_str("did") || chars.eq_ignore_ascii_case_str("done") {
+ } else if chars.eq_str("did") || chars.eq_str("done") {
"made"
- } else if chars.eq_ignore_ascii_case_str("does") {
+ } else if chars.eq_str("does") {
"makes"
- } else if chars.eq_ignore_ascii_case_str("doing") {
+ } else if chars.eq_str("doing") {
"making"
} else {
return None;
diff --git a/harper-core/src/linting/dot_initialisms.rs b/harper-core/src/linting/dot_initialisms.rs
index b883a3d5b..827059aa7 100644
--- a/harper-core/src/linting/dot_initialisms.rs
+++ b/harper-core/src/linting/dot_initialisms.rs
@@ -45,7 +45,7 @@ impl ExprLinter for DotInitialisms {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let found_word_tok = matched_tokens.first()?;
- let found_word = found_word_tok.span.get_content_string(source);
+ let found_word = found_word_tok.get_str(source);
let correction = self.corrections.get(found_word.as_str())?;
diff --git a/harper-core/src/linting/double_click.rs b/harper-core/src/linting/double_click.rs
index e02de158c..55972e94d 100644
--- a/harper-core/src/linting/double_click.rs
+++ b/harper-core/src/linting/double_click.rs
@@ -62,8 +62,8 @@ impl ExprLinter for DoubleClick {
let span = matched_tokens.get(double_idx..=click_idx)?.span()?;
let template = span.get_content(source);
- let double_word = matched_tokens.get(double_idx)?.span.get_content(source);
- let click_word = matched_tokens.get(click_idx)?.span.get_content(source);
+ let double_word = matched_tokens.get(double_idx)?.get_ch(source);
+ let click_word = matched_tokens.get(click_idx)?.get_ch(source);
let replacement: Vec<char> = double_word
.iter()
diff --git a/harper-core/src/linting/double_modal.rs b/harper-core/src/linting/double_modal.rs
index 8488640fd..769c802a8 100644
--- a/harper-core/src/linting/double_modal.rs
+++ b/harper-core/src/linting/double_modal.rs
@@ -29,8 +29,8 @@ impl ExprLinter for DoubleModal {
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let first_chars = matched_tokens.first()?.span.get_content(source);
- let second_chars = matched_tokens.last()?.span.get_content(source);
+ let first_chars = matched_tokens.first()?.get_ch(source);
+ let second_chars = matched_tokens.last()?.get_ch(source);
Some(Lint {
span: matched_tokens.span()?,
diff --git a/harper-core/src/linting/everyday.rs b/harper-core/src/linting/everyday.rs
index 75e69a225..516206192 100644
--- a/harper-core/src/linting/everyday.rs
+++ b/harper-core/src/linting/everyday.rs
@@ -129,7 +129,7 @@ impl ExprLinter for Everyday {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
// Helper functions make the match tables more compact and readable.
- let norm = |i: usize| toks[i].span.get_content_string(src).to_lowercase();
+ let norm = |i: usize| toks[i].get_str(src).to_lowercase();
let isws = |i: usize| toks[i].kind.is_whitespace();
let tokspan = |i: usize| toks[i].span;
let slicespan = |i: usize| toks[i..i + 3].span().unwrap();
diff --git a/harper-core/src/linting/except_of.rs b/harper-core/src/linting/except_of.rs
index 1e4cc552d..6b88cf391 100644
--- a/harper-core/src/linting/except_of.rs
+++ b/harper-core/src/linting/except_of.rs
@@ -28,15 +28,12 @@ impl ExprLinter for ExceptOf {
src: &[char],
ctx: Option<(&[Token], &[Token])>,
) -> Option<Lint> {
- if followed_by_word(ctx, |t| {
- t.span.get_content(src).eq_ignore_ascii_case_str("course")
- }) {
+ if followed_by_word(ctx, |t| t.get_ch(src).eq_str("course")) {
return None;
}
let (span, replacement, msg) = if preceded_by_word(ctx, |t| {
- t.span
- .get_content(src)
+ t.get_ch(src)
.eq_any_ignore_ascii_case_str(&["the", "notable", "possible"])
}) {
(
diff --git a/harper-core/src/linting/far_be_it.rs b/harper-core/src/linting/far_be_it.rs
index 09c5480dd..7f6d0bf51 100644
--- a/harper-core/src/linting/far_be_it.rs
+++ b/harper-core/src/linting/far_be_it.rs
@@ -35,7 +35,7 @@ impl ExprLinter for FarBeIt {
let content = span.get_content(src);
// We can only correct using `far be it for`, otherwise we recommend rephrasing the sentence.
- let (suggestions, message) = if span.get_content(src).eq_ignore_ascii_case_str("for") {
+ let (suggestions, message) = if span.get_content(src).eq_str("for") {
(
vec![Suggestion::replace_with_match_case(
vec!['f', 'r', 'o', 'm'],
diff --git a/harper-core/src/linting/feel_fell.rs b/harper-core/src/linting/feel_fell.rs
index 1d66bd3df..343de91cd 100644
--- a/harper-core/src/linting/feel_fell.rs
+++ b/harper-core/src/linting/feel_fell.rs
@@ -47,9 +47,7 @@ impl ExprLinter for FeelFell {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let fell_token = find_the_only_token_matching(toks, src, |tok, src| {
- tok.span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['f', 'e', 'l', 'l'])
+ tok.get_ch(src).eq_ch(&['f', 'e', 'l', 'l'])
})?;
Some(Lint {
@@ -57,7 +55,7 @@ impl ExprLinter for FeelFell {
lint_kind: LintKind::Typo,
suggestions: vec![Suggestion::replace_with_match_case_str(
"feel",
- fell_token.span.get_content(src),
+ fell_token.get_ch(src),
)],
message: "It looks like this is a typo, did you mean `feel`?".to_string(),
..Default::default()
diff --git a/harper-core/src/linting/few_units_of_time_ago.rs b/harper-core/src/linting/few_units_of_time_ago.rs
index 05d46018d..996afdfb5 100644
--- a/harper-core/src/linting/few_units_of_time_ago.rs
+++ b/harper-core/src/linting/few_units_of_time_ago.rs
@@ -39,7 +39,7 @@ impl ExprLinter for FewUnitsOfTimeAgo {
let mut span = None;
for tok in toks.iter().take(3) {
- if tok.span.get_content_string(src).eq_ignore_ascii_case("few") {
+ if tok.get_str(src).eq_ignore_ascii_case("few") {
span = Some(tok.span);
break;
}
diff --git a/harper-core/src/linting/find_fine.rs b/harper-core/src/linting/find_fine.rs
index 859cdfc25..1b3a4f47b 100644
--- a/harper-core/src/linting/find_fine.rs
+++ b/harper-core/src/linting/find_fine.rs
@@ -35,7 +35,7 @@ impl ExprLinter for FindFine {
lint_kind: LintKind::Typo,
suggestions: vec![Suggestion::replace_with_match_case_str(
"fine",
- offending_word.span.get_content(source),
+ offending_word.get_ch(source),
)],
message: "Did you mean `fine`?".to_owned(),
priority: 63,
diff --git a/harper-core/src/linting/flesh_out_vs_full_fledged.rs b/harper-core/src/linting/flesh_out_vs_full_fledged.rs
index 45c71619b..fd633af18 100644
--- a/harper-core/src/linting/flesh_out_vs_full_fledged.rs
+++ b/harper-core/src/linting/flesh_out_vs_full_fledged.rs
@@ -39,8 +39,7 @@ impl ExprLinter for FleshOutVsFullFledged {
let has_full_y = toks
.first()
.map(|t| {
- t.span
- .get_content(src)
+ t.get_ch(src)
.eq_any_ignore_ascii_case_str(&["full", "fully"])
})
.unwrap_or(false);
@@ -48,7 +47,7 @@ impl ExprLinter for FleshOutVsFullFledged {
// Is the last word is "out"?
let mut has_out = toks
.last()
- .map(|t| t.span.get_content(src).eq_ignore_ascii_case_str("out"))
+ .map(|t| t.get_ch(src).eq_str("out"))
.unwrap_or(false);
// Adjust tokens to exclude "out" when it's part of a hyphenated compound
@@ -73,7 +72,7 @@ impl ExprLinter for FleshOutVsFullFledged {
let vtok_idx = if has_full_y { 2 } else { 0 };
let vtok = &toks[vtok_idx];
- let vtok_chars = vtok.span.get_content(src);
+ let vtok_chars = vtok.get_ch(src);
let form = match vtok_chars.last() {
Some('d') => Form::Past,
diff --git a/harper-core/src/linting/free_predicate.rs b/harper-core/src/linting/free_predicate.rs
index 2d7d0359d..28bf11a43 100644
--- a/harper-core/src/linting/free_predicate.rs
+++ b/harper-core/src/linting/free_predicate.rs
@@ -53,7 +53,7 @@ impl ExprLinter for FreePredicate {
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
"free",
- offending.span.get_content(source),
+ offending.get_ch(source),
)],
message: "Use `free` here to show that something costs nothing.".to_owned(),
priority: 38,
@@ -71,7 +71,7 @@ fn matches_fee(token: &Token, source: &[char]) -> bool {
}
const FEE: [char; 3] = ['f', 'e', 'e'];
- let content = token.span.get_content(source);
+ let content = token.get_ch(source);
content.len() == FEE.len()
&& content
@@ -92,11 +92,9 @@ fn follows_fee(token: &Token, _source: &[char]) -> bool {
fn linking_like(token: &Token, source: &[char]) -> bool {
const BE_FORMS: [&str; 8] = ["be", "is", "am", "are", "was", "were", "being", "been"];
- let content = token.span.get_content(source);
+ let content = token.get_ch(source);
- BE_FORMS
- .iter()
- .any(|form| content.eq_ignore_ascii_case_str(form))
+ BE_FORMS.iter().any(|form| content.eq_str(form))
}
#[cfg(test)]
diff --git a/harper-core/src/linting/friend_of_me.rs b/harper-core/src/linting/friend_of_me.rs
index a9e58c253..329928fa3 100644
--- a/harper-core/src/linting/friend_of_me.rs
+++ b/harper-core/src/linting/friend_of_me.rs
@@ -30,7 +30,7 @@ impl ExprLinter for FriendOfMe {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let obj_pron_tok = toks.last()?;
- let obj_pron_str = obj_pron_tok.span.get_content_string(src);
+ let obj_pron_str = obj_pron_tok.get_str(src);
let poss_pron_str = match obj_pron_str.as_str() {
"me" => "mine",
@@ -49,7 +49,7 @@ impl ExprLinter for FriendOfMe {
lint_kind: LintKind::Grammar,
suggestions: vec![Suggestion::replace_with_match_case_str(
poss_pron_str,
- obj_pron_tok.span.get_content(src),
+ obj_pron_tok.get_ch(src),
)],
message: format!("Use `{poss_pron_str}` instead of `{obj_pron_str}`."),
priority: 31,
diff --git a/harper-core/src/linting/go_so_far_as_to.rs b/harper-core/src/linting/go_so_far_as_to.rs
index b9a29d726..b4b6e247f 100644
--- a/harper-core/src/linting/go_so_far_as_to.rs
+++ b/harper-core/src/linting/go_so_far_as_to.rs
@@ -52,7 +52,7 @@ impl ExprLinter for GoSoFarAsTo {
format!(
"{} as {}",
go_so_far_toks.span()?.get_content_string(src),
- to_tok.span.get_content_string(src)
+ to_tok.get_str(src)
)
.chars()
.collect(),
diff --git a/harper-core/src/linting/go_to_war.rs b/harper-core/src/linting/go_to_war.rs
index 1df200a92..f528baaac 100644
--- a/harper-core/src/linting/go_to_war.rs
+++ b/harper-core/src/linting/go_to_war.rs
@@ -37,7 +37,7 @@ impl ExprLinter for GoToWar {
let prep_span = prep_tok.span;
let prep_chars = prep_span.get_content(src);
- if prep_chars.eq_ignore_ascii_case_chars(&['t', 'o']) {
+ if prep_chars.eq_ch(&['t', 'o']) {
return None;
}
diff --git a/harper-core/src/linting/handful.rs b/harper-core/src/linting/handful.rs
index 78389b542..5eb3ade06 100644
--- a/harper-core/src/linting/handful.rs
+++ b/harper-core/src/linting/handful.rs
@@ -48,7 +48,7 @@ impl ExprLinter for Handful {
let replacement = &matched_tokens[..highlight_end];
let span = replacement.span()?;
- let template = matched_tokens.first()?.span.get_content(source);
+ let template = matched_tokens.first()?.get_ch(source);
Some(Lint {
span,
diff --git a/harper-core/src/linting/have_take_a_look.rs b/harper-core/src/linting/have_take_a_look.rs
index cf697fe16..e177af457 100644
--- a/harper-core/src/linting/have_take_a_look.rs
+++ b/harper-core/src/linting/have_take_a_look.rs
@@ -35,7 +35,7 @@ impl ExprLinter for HaveTakeALook {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let light_verb_tok = toks.first().unwrap();
- let light_verb_str = light_verb_tok.span.get_content_string(src);
+ let light_verb_str = light_verb_tok.get_str(src);
let light_verb = light_verb_str.to_ascii_lowercase();
let translated_light_verb: &[&str] = match light_verb.as_str() {
@@ -54,10 +54,7 @@ impl ExprLinter for HaveTakeALook {
let suggestions = translated_light_verb
.iter()
.map(|s| {
- Suggestion::replace_with_match_case(
- s.chars().collect(),
- light_verb_tok.span.get_content(src),
- )
+ Suggestion::replace_with_match_case(s.chars().collect(), light_verb_tok.get_ch(src))
})
.collect();
diff --git a/harper-core/src/linting/hop_hope/to_hop.rs b/harper-core/src/linting/hop_hope/to_hop.rs
index 9aede0d02..bd01ca998 100644
--- a/harper-core/src/linting/hop_hope/to_hop.rs
+++ b/harper-core/src/linting/hop_hope/to_hop.rs
@@ -46,7 +46,7 @@ impl ExprLinter for ToHop {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let offending_word = &matched_tokens[0];
- let word_chars = offending_word.span.get_content(source);
+ let word_chars = offending_word.get_ch(source);
let word = word_chars.to_string();
let correct = Self::to_correct(&word)?;
diff --git a/harper-core/src/linting/hop_hope/to_hope.rs b/harper-core/src/linting/hop_hope/to_hope.rs
index b4d2b8e25..44dfec7fe 100644
--- a/harper-core/src/linting/hop_hope/to_hope.rs
+++ b/harper-core/src/linting/hop_hope/to_hope.rs
@@ -33,7 +33,7 @@ impl ExprLinter for ToHope {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let offending_word = &matched_tokens[2];
- let word_chars = offending_word.span.get_content(source);
+ let word_chars = offending_word.get_ch(source);
Some(Lint {
span: offending_word.span,
diff --git a/harper-core/src/linting/if_wouldve.rs b/harper-core/src/linting/if_wouldve.rs
index a6b64b8e4..8cf5d7681 100644
--- a/harper-core/src/linting/if_wouldve.rs
+++ b/harper-core/src/linting/if_wouldve.rs
@@ -49,8 +49,8 @@ impl ExprLinter for IfWouldve {
.rev()
.step_by(2) // Check every other token since we're looking at pairs
.find_map(|i| {
- let prev = toks[i - 2].span.get_content(src);
- let curr = toks[i].span.get_content(src);
+ let prev = toks[i - 2].get_ch(src);
+ let curr = toks[i].get_ch(src);
let would_had = &["would", "had"];
diff --git a/harper-core/src/linting/inflected_verb_after_to.rs b/harper-core/src/linting/inflected_verb_after_to.rs
index 41ab1f1c5..a8dd44b8a 100644
--- a/harper-core/src/linting/inflected_verb_after_to.rs
+++ b/harper-core/src/linting/inflected_verb_after_to.rs
@@ -31,7 +31,7 @@ impl<T: Dictionary> Linter for InflectedVerbAfterTo<T> {
continue;
}
let prep_to = document.get_span_content(&prep.span);
- if !prep_to.eq_ignore_ascii_case_chars(&['t', 'o']) {
+ if !prep_to.eq_ch(&['t', 'o']) {
continue;
}
diff --git a/harper-core/src/linting/initialism_linter.rs b/harper-core/src/linting/initialism_linter.rs
index 2a10d31c4..7158d4f5a 100644
--- a/harper-core/src/linting/initialism_linter.rs
+++ b/harper-core/src/linting/initialism_linter.rs
@@ -47,7 +47,7 @@ impl ExprLinter for InitialismLinter {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let tok = matched_tokens.first()?;
- let source = tok.span.get_content(source);
+ let source = tok.get_ch(source);
let suggestions = self
.expansions_lower
diff --git a/harper-core/src/linting/interested_in.rs b/harper-core/src/linting/interested_in.rs
index 381467c50..b28e0fdeb 100644
--- a/harper-core/src/linting/interested_in.rs
+++ b/harper-core/src/linting/interested_in.rs
@@ -34,7 +34,7 @@ impl ExprLinter for InterestedIn {
let prep_span = tokens.last().unwrap().span;
let prep_chars = prep_span.get_content(source);
- if prep_chars.eq_ignore_ascii_case_chars(&['i', 'n']) {
+ if prep_chars.eq_ch(&['i', 'n']) {
return None;
}
diff --git a/harper-core/src/linting/its_contraction/general.rs b/harper-core/src/linting/its_contraction/general.rs
index 5003e3bf4..907784425 100644
--- a/harper-core/src/linting/its_contraction/general.rs
+++ b/harper-core/src/linting/its_contraction/general.rs
@@ -70,10 +70,10 @@ impl Linter for General {
impl General {
fn match_to_lint(&self, toks: &[Token], source: &[char]) -> Option<Lint> {
let offender = toks.first()?;
- let offender_chars = offender.span.get_content(source);
+ let offender_chars = offender.get_ch(source);
let modifier = toks.get(2)?;
- let modifier_text = modifier.span.get_content_string(source);
+ let modifier_text = modifier.get_str(source);
let modifier_lower = modifier_text.to_ascii_lowercase();
let next_kind = toks.get(4).map(|tok| tok.kind.clone());
@@ -190,7 +190,7 @@ impl General {
return false;
}
- let modifier_text = modifier.span.get_content_string(source);
+ let modifier_text = modifier.get_str(source);
!["had", "been", "got"]
.iter()
@@ -198,7 +198,7 @@ impl General {
}
fn is_likely_predicative_participle(tok: &Token, source: &[char]) -> bool {
- let text = tok.span.get_content_string(source);
+ let text = tok.get_str(source);
["called", "named", "known", "termed", "titled"]
.iter()
diff --git a/harper-core/src/linting/its_contraction/proper_noun.rs b/harper-core/src/linting/its_contraction/proper_noun.rs
index 297a5ad33..1289aa593 100644
--- a/harper-core/src/linting/its_contraction/proper_noun.rs
+++ b/harper-core/src/linting/its_contraction/proper_noun.rs
@@ -26,8 +26,7 @@ impl Default for ProperNoun {
let capitalized_word = |tok: &Token, src: &[char]| {
tok.kind.is_word()
&& tok
- .span
- .get_content(src)
+ .get_ch(src)
.first()
.map(|c| c.is_uppercase())
.unwrap_or(false)
@@ -81,8 +80,7 @@ impl ProperNoun {
&& let Some(next_word) = matched_tokens.get(6)
{
let is_lowercase = next_word
- .span
- .get_content(source)
+ .get_ch(source)
.first()
.map(|c| c.is_lowercase())
.unwrap_or(false);
@@ -96,7 +94,7 @@ impl ProperNoun {
let range = self.expr.lookup(0, matched_tokens, source)?.clone();
let offending = matched_tokens.get(range.start)?;
- let offender_text = offending.span.get_content(source);
+ let offender_text = offending.get_ch(source);
Some(Lint {
span: offending.span,
diff --git a/harper-core/src/linting/jealous_of.rs b/harper-core/src/linting/jealous_of.rs
index b9b8c6c82..679f79df0 100644
--- a/harper-core/src/linting/jealous_of.rs
+++ b/harper-core/src/linting/jealous_of.rs
@@ -44,7 +44,7 @@ impl ExprLinter for JealousOf {
lint_kind: LintKind::Usage,
suggestions: vec![Suggestion::replace_with_match_case_str(
"of",
- from_token.span.get_content(source),
+ from_token.get_ch(source),
)],
message: "Use `of` after `jealous`.".to_owned(),
..Default::default()
diff --git a/harper-core/src/linting/johns_hopkins.rs b/harper-core/src/linting/johns_hopkins.rs
index 555dd4fc6..50cc1efed 100644
--- a/harper-core/src/linting/johns_hopkins.rs
+++ b/harper-core/src/linting/johns_hopkins.rs
@@ -12,15 +12,11 @@ pub struct JohnsHopkins {
impl Default for JohnsHopkins {
fn default() -> Self {
let expr = SequenceExpr::with(|tok: &Token, src: &[char]| {
- tok.kind.is_proper_noun() && tok.span.get_content(src).eq_ignore_ascii_case_str("john")
+ tok.kind.is_proper_noun() && tok.get_ch(src).eq_str("john")
})
.t_ws()
.then(|tok: &Token, src: &[char]| {
- tok.kind.is_proper_noun()
- && tok
- .span
- .get_content(src)
- .eq_ignore_ascii_case_str("hopkins")
+ tok.kind.is_proper_noun() && tok.get_ch(src).eq_str("hopkins")
});
Self { expr }
diff --git a/harper-core/src/linting/less_worse.rs b/harper-core/src/linting/less_worse.rs
index dda943501..b62a2ab98 100644
--- a/harper-core/src/linting/less_worse.rs
+++ b/harper-core/src/linting/less_worse.rs
@@ -32,9 +32,9 @@ impl ExprLinter for LessWorse {
let span = toks.span()?;
- let how_little = toks[0].span.get_content(src).to_lower();
+ let how_little = toks[0].get_ch(src).to_lower();
let space_or_hyphen = &toks[1];
- let how_bad = toks[2].span.get_content(src).to_lower();
+ let how_bad = toks[2].get_ch(src).to_lower();
let (suggestions, message): (&[&[char]], &str) = match (
how_little.as_ref(),
diff --git a/harper-core/src/linting/lets_confusion/let_us_redundancy.rs b/harper-core/src/linting/lets_confusion/let_us_redundancy.rs
index 6a1a7c7bf..e4a8a42af 100644
--- a/harper-core/src/linting/lets_confusion/let_us_redundancy.rs
+++ b/harper-core/src/linting/lets_confusion/let_us_redundancy.rs
@@ -33,7 +33,7 @@ impl ExprLinter for LetUsRedundancy {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let template = matched_tokens.span()?.get_content(source);
- let pronoun = matched_tokens.last()?.span.get_content_string(source);
+ let pronoun = matched_tokens.last()?.get_str(source);
Some(Lint {
span: matched_tokens.span()?,
diff --git a/harper-core/src/linting/lets_confusion/no_contraction_with_verb.rs b/harper-core/src/linting/lets_confusion/no_contraction_with_verb.rs
index 426644462..ab23c9a50 100644
--- a/harper-core/src/linting/lets_confusion/no_contraction_with_verb.rs
+++ b/harper-core/src/linting/lets_confusion/no_contraction_with_verb.rs
@@ -64,8 +64,8 @@ impl ExprLinter for NoContractionWithVerb {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let (let_string, verb_string) = (
- matched_tokens[0].span.get_content_string(source),
- matched_tokens[2].span.get_content_string(source),
+ matched_tokens[0].get_str(source),
+ matched_tokens[2].get_str(source),
);
// "to let go" is a phrasal verb but "lets go" is quite a common mistake for "let's go"
diff --git a/harper-core/src/linting/lint.rs b/harper-core/src/linting/lint.rs
index 19e2da99b..bf2c91520 100644
--- a/harper-core/src/linting/lint.rs
+++ b/harper-core/src/linting/lint.rs
@@ -47,6 +47,16 @@ impl Lint {
pub fn message_html(&self) -> String {
render_markdown(&self.message)
}
+
+ /// Get the lint's span content as a slice of characters.
+ pub fn get_ch<'a>(&self, source: &'a [char]) -> &'a [char] {
+ self.span.get_content(source)
+ }
+
+ /// Get the lint's span content as a string.
+ pub fn get_str(&self, source: &[char]) -> String {
+ self.span.get_content_string(source)
+ }
}
impl Default for Lint {
diff --git a/harper-core/src/linting/looking_forward_to.rs b/harper-core/src/linting/looking_forward_to.rs
index 606a75c27..f640f55b0 100644
--- a/harper-core/src/linting/looking_forward_to.rs
+++ b/harper-core/src/linting/looking_forward_to.rs
@@ -33,7 +33,7 @@ impl ExprLinter for LookingForwardTo {
fn match_to_lint(&self, matched_tokens: &[Token], src: &[char]) -> Option<Lint> {
let span = matched_tokens.last()?.span;
- let verb = matched_tokens.last()?.span.get_content_string(src);
+ let verb = matched_tokens.last()?.get_str(src);
if verb.ends_with("ing") {
return None;
}
diff --git a/harper-core/src/linting/map_phrase_set_linter.rs b/harper-core/src/linting/map_phrase_set_linter.rs
index f8a3997cb..fe5d01bb3 100644
--- a/harper-core/src/linting/map_phrase_set_linter.rs
+++ b/harper-core/src/linting/map_phrase_set_linter.rs
@@ -82,7 +82,7 @@ impl<'a> ExprLinter for MapPhraseSetLinter<'a> {
let mut suggestions: Vec<_> = self
.wrong_forms_to_correct_forms
.iter()
- .filter(|(wrong_form, _)| matched_text.eq_ignore_ascii_case_str(wrong_form))
+ .filter(|(wrong_form, _)| matched_text.eq_str(wrong_form))
.map(|(_, correct_form)| {
Suggestion::replace_with_match_case(correct_form.chars().collect(), matched_text)
})
@@ -94,7 +94,7 @@ impl<'a> ExprLinter for MapPhraseSetLinter<'a> {
.flat_map(|(wrong_forms, correct_forms)| {
wrong_forms
.iter()
- .filter(move |&&wrong_form| matched_text.eq_ignore_ascii_case_str(wrong_form))
+ .filter(move |&&wrong_form| matched_text.eq_str(wrong_form))
.flat_map(move |_| {
correct_forms.iter().map(move |correct_form| {
Suggestion::replace_with_match_case(
diff --git a/harper-core/src/linting/mass_nouns/mass_plurals.rs b/harper-core/src/linting/mass_nouns/mass_plurals.rs
index 757016e66..23f3e7c7d 100644
--- a/harper-core/src/linting/mass_nouns/mass_plurals.rs
+++ b/harper-core/src/linting/mass_nouns/mass_plurals.rs
@@ -20,9 +20,7 @@ where
pub fn new(dict: D) -> Self {
let oov = SequenceExpr::default().then_oov();
let looks_plural = SequenceExpr::with(|tok: &Token, src: &[char]| {
- tok.span
- .get_content(src)
- .ends_with_ignore_ascii_case_chars(&['s'])
+ tok.get_ch(src).ends_with_ignore_ascii_case_chars(&['s'])
});
let oov_looks_plural = All::new(vec![Box::new(oov), Box::new(looks_plural)]);
@@ -76,7 +74,7 @@ where
} else {
let invalid_plural_tok = &invalid_plural_toks[0];
// Not a fixed phrase, so it's a single word that's not in the dictionary and ends with -s
- let mut remaining_chars = invalid_plural_tok.span.get_content(src);
+ let mut remaining_chars = invalid_plural_tok.get_ch(src);
// -s
if remaining_chars.ends_with(&['s']) {
diff --git a/harper-core/src/linting/mass_nouns/noun_countability.rs b/harper-core/src/linting/mass_nouns/noun_countability.rs
index 89a5572d4..512f49f81 100644
--- a/harper-core/src/linting/mass_nouns/noun_countability.rs
+++ b/harper-core/src/linting/mass_nouns/noun_countability.rs
@@ -84,10 +84,10 @@ impl ExprLinter for NounCountability {
}
// the determiner or quantifier
- let dq = toks[0].span.get_content_string(src).to_lowercase();
+ let dq = toks[0].get_str(src).to_lowercase();
// the mass noun
- let noun = toks[2].span.get_content_string(src).to_lowercase();
+ let noun = toks[2].get_str(src).to_lowercase();
let synonym_corrections: &'static [Correction] = match (noun.as_str(), dq.as_str()) {
("advice", "a" | "an" | "another" | "each" | "every" | "one") => &[
diff --git a/harper-core/src/linting/missing_to.rs b/harper-core/src/linting/missing_to.rs
index 1bedbdf6b..2e671778f 100644
--- a/harper-core/src/linting/missing_to.rs
+++ b/harper-core/src/linting/missing_to.rs
@@ -257,7 +257,7 @@ impl ExprLinter for MissingTo {
let controller = &matched_tokens[offending_idx];
let span = controller.span;
- let controller_text = controller.span.get_content_string(source).to_lowercase();
+ let controller_text = controller.get_str(source).to_lowercase();
let controller_text = controller_text.as_str();
let is_adjective_controller = matches!(controller_text, "eager" | "inclined" | "ready");
@@ -315,7 +315,7 @@ impl ExprLinter for MissingTo {
.skip(offending_idx + 1)
.find(|tok| !tok.kind.is_whitespace())?;
- let next_text = next_token.span.get_content_string(source).to_lowercase();
+ let next_text = next_token.get_str(source).to_lowercase();
if controller_text.starts_with("try") && next_text == "and" {
return None;
diff --git a/harper-core/src/linting/misspell.rs b/harper-core/src/linting/misspell.rs
index 75187b2d0..6dcc0bbef 100644
--- a/harper-core/src/linting/misspell.rs
+++ b/harper-core/src/linting/misspell.rs
@@ -34,7 +34,7 @@ impl ExprLinter for Misspell {
let span = matched_tokens.span()?;
let misspell_variant = matched_tokens.last()?;
- let variant_chars = misspell_variant.span.get_content(source);
+ let variant_chars = misspell_variant.get_ch(source);
let variant_lower = variant_chars
.iter()
.map(|c| c.to_ascii_lowercase())
diff --git a/harper-core/src/linting/mixed_bag.rs b/harper-core/src/linting/mixed_bag.rs
index 4f260a33e..d0677a73c 100644
--- a/harper-core/src/linting/mixed_bag.rs
+++ b/harper-core/src/linting/mixed_bag.rs
@@ -36,9 +36,7 @@ impl ExprLinter for MixedBag {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let bad_span = find_the_only_token_matching(toks, src, |tok, _src| {
- tok.span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['b', 'a', 'd'])
+ tok.get_ch(src).eq_ch(&['b', 'a', 'd'])
})?
.span;
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index a81eb94e1..410afea22 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -325,7 +325,7 @@ pub mod debug {
tokens
.iter()
.filter(|t| !t.kind.is_unlintable())
- .map(|t| t.span.get_content_string(src))
+ .map(|t| t.get_str(src))
.collect::<String>()
};
@@ -393,10 +393,7 @@ pub mod tests {
// Check if word matches any of the patterns in the map
for (errors, fixes) in self.map {
// if any of the errors match, add all of the corrections
- if errors
- .iter()
- .any(|&e| word_chars.eq_ignore_ascii_case_str(e))
- {
+ if errors.iter().any(|&e| word_chars.eq_str(e)) {
corr.push((wordspan, word_chars, fixes))
}
}
diff --git a/harper-core/src/linting/modal_be_adjective.rs b/harper-core/src/linting/modal_be_adjective.rs
index 29e4669ff..4f0db3c55 100644
--- a/harper-core/src/linting/modal_be_adjective.rs
+++ b/harper-core/src/linting/modal_be_adjective.rs
@@ -51,16 +51,9 @@ impl ExprLinter for ModalBeAdjective {
if followed_by_word(ctx, |nw| {
(nw.kind.is_noun()
&& !nw
- .span
- .get_content(src)
+ .get_ch(src)
.eq_any_ignore_ascii_case_str(&["at", "by", "if"]))
- || (toks
- .last()
- .unwrap()
- .span
- .get_content(src)
- .eq_ignore_ascii_case_str("kind")
- && nw.span.get_content(src).eq_ignore_ascii_case_str("of"))
+ || (toks.last().unwrap().get_ch(src).eq_str("kind") && nw.get_ch(src).eq_str("of"))
}) {
return None;
}
diff --git a/harper-core/src/linting/modal_seem.rs b/harper-core/src/linting/modal_seem.rs
index e1a98653a..53686dd46 100644
--- a/harper-core/src/linting/modal_seem.rs
+++ b/harper-core/src/linting/modal_seem.rs
@@ -72,11 +72,7 @@ impl ExprLinter for ModalSeem {
let seen_token = matched_tokens
.iter()
.skip(context.modal_index)
- .find(|tok| {
- tok.span
- .get_content(source)
- .eq_ignore_ascii_case_str("seen")
- })?;
+ .find(|tok| tok.get_ch(source).eq_str("seen"))?;
let span = seen_token.span;
let original = span.get_content(source);
diff --git a/harper-core/src/linting/months.rs b/harper-core/src/linting/months.rs
index e01cd5de4..881e92c12 100644
--- a/harper-core/src/linting/months.rs
+++ b/harper-core/src/linting/months.rs
@@ -93,12 +93,12 @@ impl ExprLinter for Months {
fn match_to_lint(&self, tokens: &[Token], src: &[char]) -> Option<Lint> {
// `find` which token is the month by seeing which tok's content (lowercased) is in ALL_MONTHS
let month_tok = tokens.iter().find(|token| {
- let token_str = token.span.get_content_string(src);
+ let token_str = token.get_str(src);
ALL_MONTHS.iter().any(|&m| m == token_str.to_lowercase())
})?; // Return None if no month token found
// let month_tok = tokens.last().unwrap();
- let month_ch = month_tok.span.get_content(src);
+ let month_ch = month_tok.get_ch(src);
if month_ch[0].is_uppercase() {
return None;
diff --git a/harper-core/src/linting/more_adjective.rs b/harper-core/src/linting/more_adjective.rs
index 7c610a7be..0a40e7ffd 100644
--- a/harper-core/src/linting/more_adjective.rs
+++ b/harper-core/src/linting/more_adjective.rs
@@ -70,11 +70,11 @@ where
}
let degree_tok = &toks[0];
- let degree_chars = degree_tok.span.get_content(src);
+ let degree_chars = degree_tok.get_ch(src);
- let degree = if degree_chars.eq_ignore_ascii_case_str("more") {
+ let degree = if degree_chars.eq_str("more") {
Degree::Comparative
- } else if degree_chars.eq_ignore_ascii_case_str("most") {
+ } else if degree_chars.eq_str("most") {
Degree::Superlative
} else {
return None;
diff --git a/harper-core/src/linting/more_better.rs b/harper-core/src/linting/more_better.rs
index ef2d4e2b9..d10e8cc40 100644
--- a/harper-core/src/linting/more_better.rs
+++ b/harper-core/src/linting/more_better.rs
@@ -39,7 +39,7 @@ impl ExprLinter for MoreBetter {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let phrase_span = toks.span()?;
- let degree_str = toks.first()?.span.get_content_string(src);
+ let degree_str = toks.first()?.get_str(src);
let adj_span = toks.last()?.span;
let suggestion = Suggestion::replace_with_match_case(
diff --git a/harper-core/src/linting/most_number.rs b/harper-core/src/linting/most_number.rs
index 36ac302d1..9db9f8660 100644
--- a/harper-core/src/linting/most_number.rs
+++ b/harper-core/src/linting/most_number.rs
@@ -43,7 +43,7 @@ impl ExprLinter for MostNumber {
fn match_to_lint(&self, toks: &[Token], source: &[char]) -> Option<Lint> {
let most_amt_num_span = toks[0..3].span()?;
- let noun_string = toks[2].span.get_content_string(source);
+ let noun_string = toks[2].get_str(source);
let superlatives = if noun_string == "amount" {
vec!["largest", "greatest", "maximum"]
} else {
@@ -64,7 +64,7 @@ impl ExprLinter for MostNumber {
suggestions,
message: format!(
"`Most` is not standard before `{}`.",
- toks[2].span.get_content_string(source)
+ toks[2].get_str(source)
),
priority: 31,
})
diff --git a/harper-core/src/linting/multiple_frequency_adverbs.rs b/harper-core/src/linting/multiple_frequency_adverbs.rs
index 20431c2f5..a12f4622e 100644
--- a/harper-core/src/linting/multiple_frequency_adverbs.rs
+++ b/harper-core/src/linting/multiple_frequency_adverbs.rs
@@ -11,11 +11,7 @@ pub struct MultipleFrequencyAdverbs {
impl Default for MultipleFrequencyAdverbs {
fn default() -> Self {
let adverb_of_frequency = |t: &Token, s: &[char]| {
- t.kind.is_frequency_adverb()
- && !t
- .span
- .get_content(s)
- .eq_ignore_ascii_case_chars(&['o', 'n', 'l', 'y'])
+ t.kind.is_frequency_adverb() && !t.get_ch(s).eq_ch(&['o', 'n', 'l', 'y'])
};
Self {
@@ -45,7 +41,7 @@ impl ExprLinter for MultipleFrequencyAdverbs {
let (adv1span, adv2span) = (adv1tok.span, adv2tok.span);
let (adv1ch, adv2ch) = (adv1span.get_content(src), adv2span.get_content(src));
- if !adv1ch.eq_ignore_ascii_case_chars(adv2ch) {
+ if !adv1ch.eq_ch(adv2ch) {
Some(Lint {
span: toks.span()?,
lint_kind: LintKind::Usage,
diff --git a/harper-core/src/linting/multiple_sequential_pronouns.rs b/harper-core/src/linting/multiple_sequential_pronouns.rs
index 6189cdf45..6ddae146c 100644
--- a/harper-core/src/linting/multiple_sequential_pronouns.rs
+++ b/harper-core/src/linting/multiple_sequential_pronouns.rs
@@ -40,8 +40,8 @@ impl ExprLinter for MultipleSequentialPronouns {
let first_word_tok = &matched_tokens[0];
let second_word_tok = &matched_tokens[2];
- let first_word_raw = first_word_tok.span.get_content(source);
- let second_word_raw = second_word_tok.span.get_content(source);
+ let first_word_raw = first_word_tok.get_ch(source);
+ let second_word_raw = second_word_tok.get_ch(source);
// Bug 578: "I can lend you my car" - if 1st is object and second is possessive adjective, don't lint
if first_word_tok.kind.is_object_pronoun()
&& second_word_tok.kind.is_possessive_determiner()
@@ -68,10 +68,10 @@ impl ExprLinter for MultipleSequentialPronouns {
}
suggestions.push(Suggestion::ReplaceWith(
- matched_tokens[0].span.get_content(source).to_vec(),
+ matched_tokens[0].get_ch(source).to_vec(),
));
suggestions.push(Suggestion::ReplaceWith(
- matched_tokens[2].span.get_content(source).to_vec(),
+ matched_tokens[2].get_ch(source).to_vec(),
));
}
diff --git a/harper-core/src/linting/need_to_noun.rs b/harper-core/src/linting/need_to_noun.rs
index efb638002..b4eda1f9b 100644
--- a/harper-core/src/linting/need_to_noun.rs
+++ b/harper-core/src/linting/need_to_noun.rs
@@ -67,7 +67,7 @@ impl ExprLinter for NeedToNoun {
let noun_idx = 4;
let noun_token = &matched_tokens[noun_idx];
- let noun_text = noun_token.span.get_content_string(source);
+ let noun_text = noun_token.get_str(source);
let span = to_token.span;
Some(Lint {
diff --git a/harper-core/src/linting/no_longer.rs b/harper-core/src/linting/no_longer.rs
index a12f0cd44..8e6eb5a65 100644
--- a/harper-core/src/linting/no_longer.rs
+++ b/harper-core/src/linting/no_longer.rs
@@ -51,7 +51,7 @@ impl ExprLinter for NoLonger {
lint_kind: LintKind::Usage,
suggestions: vec![Suggestion::replace_with_match_case_str(
"no",
- toks[0].span.get_content(src),
+ toks[0].get_ch(src),
)],
message: "The correct expression is `no longer`.".to_string(),
..Default::default()
diff --git a/harper-core/src/linting/no_match_for.rs b/harper-core/src/linting/no_match_for.rs
index 58cac3d6a..947b2b835 100644
--- a/harper-core/src/linting/no_match_for.rs
+++ b/harper-core/src/linting/no_match_for.rs
@@ -41,8 +41,8 @@ impl ExprLinter for NoMatchFor {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let prep_tok = toks.last()?;
- let prep_chars = prep_tok.span.get_content(src);
- if prep_chars.eq_ignore_ascii_case_chars(&['f', 'o', 'r']) {
+ let prep_chars = prep_tok.get_ch(src);
+ if prep_chars.eq_ch(&['f', 'o', 'r']) {
return None;
}
diff --git a/harper-core/src/linting/nominal_wants.rs b/harper-core/src/linting/nominal_wants.rs
index 136c3b6af..edae43439 100644
--- a/harper-core/src/linting/nominal_wants.rs
+++ b/harper-core/src/linting/nominal_wants.rs
@@ -19,7 +19,7 @@ impl Default for NominalWants {
fn default() -> Self {
fn is_applicable_pronoun(tok: &Token, src: &[char]) -> bool {
if tok.kind.is_pronoun() && tok.kind.is_upos(UPOS::PRON) {
- let pron = tok.span.get_content(src);
+ let pron = tok.get_ch(src);
!pron.eq_any_ignore_ascii_case_chars(&[
// "That" can act as two kinds of pronoun: demonstrative and relative.
// As a demonstrative pronoun, it's third person singular.
@@ -88,7 +88,7 @@ impl ExprLinter for NominalWants {
let offender_span = offender.span;
let offender_chars = offender_span.get_content(source);
- if offender_chars.eq_ignore_ascii_case_chars(&replacement_chars) {
+ if offender_chars.eq_ch(&replacement_chars) {
return None;
}
diff --git a/harper-core/src/linting/noun_verb_confusion/effect_affect/affect_to_effect.rs b/harper-core/src/linting/noun_verb_confusion/effect_affect/affect_to_effect.rs
index d2851f3d9..e3dce9cea 100644
--- a/harper-core/src/linting/noun_verb_confusion/effect_affect/affect_to_effect.rs
+++ b/harper-core/src/linting/noun_verb_confusion/effect_affect/affect_to_effect.rs
@@ -96,7 +96,7 @@ impl ExprLinter for AffectToEffect {
return None;
}
- let token_text = target.span.get_content_string(source);
+ let token_text = target.get_str(source);
let lower = token_text.to_lowercase();
let replacement = match lower.as_str() {
"affect" => "effect",
@@ -109,7 +109,7 @@ impl ExprLinter for AffectToEffect {
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
replacement,
- target.span.get_content(source),
+ target.get_ch(source),
)],
message: "`affect` is usually a verb; use `effect` here for the result or outcome."
.into(),
@@ -130,16 +130,16 @@ fn is_affect_word(token: &Token, source: &[char]) -> bool {
return false;
}
- let text = token.span.get_content(source);
- text.eq_ignore_ascii_case_chars(AFFECT) || text.eq_ignore_ascii_case_chars(AFFECTS)
+ let text = token.get_ch(source);
+ text.eq_ch(AFFECT) || text.eq_ch(AFFECTS)
}
fn is_take_form(chars: &[char]) -> bool {
- chars.eq_ignore_ascii_case_str("take")
- || chars.eq_ignore_ascii_case_str("takes")
- || chars.eq_ignore_ascii_case_str("taking")
- || chars.eq_ignore_ascii_case_str("took")
- || chars.eq_ignore_ascii_case_str("taken")
+ chars.eq_str("take")
+ || chars.eq_str("takes")
+ || chars.eq_str("taking")
+ || chars.eq_str("took")
+ || chars.eq_str("taken")
}
fn is_modal_like(token: &Token, source: &[char], prev: &[char]) -> bool {
@@ -150,15 +150,15 @@ fn is_modal_like(token: &Token, source: &[char], prev: &[char]) -> bool {
return true;
}
- prev.eq_ignore_ascii_case_str("do")
- || prev.eq_ignore_ascii_case_str("does")
- || prev.eq_ignore_ascii_case_str("did")
- || prev.eq_ignore_ascii_case_str("don't")
- || prev.eq_ignore_ascii_case_str("dont")
- || prev.eq_ignore_ascii_case_str("doesn't")
- || prev.eq_ignore_ascii_case_str("doesnt")
- || prev.eq_ignore_ascii_case_str("didn't")
- || prev.eq_ignore_ascii_case_str("didnt")
+ prev.eq_str("do")
+ || prev.eq_str("does")
+ || prev.eq_str("did")
+ || prev.eq_str("don't")
+ || prev.eq_str("dont")
+ || prev.eq_str("doesn't")
+ || prev.eq_str("doesnt")
+ || prev.eq_str("didn't")
+ || prev.eq_str("didnt")
}
fn matches_preceding_context(token: &Token, source: &[char]) -> bool {
@@ -187,7 +187,7 @@ fn matches_preceding_context_impl(
return false;
}
- let content = token.span.get_content(source);
+ let content = token.get_ch(source);
let is_take_form_word = is_take_form(content);
if behaves_like_verb(token, source, content) && !is_take_form_word {
diff --git a/harper-core/src/linting/noun_verb_confusion/effect_affect/effect_to_affect.rs b/harper-core/src/linting/noun_verb_confusion/effect_affect/effect_to_affect.rs
index 8891d3b61..9c2b11bfc 100644
--- a/harper-core/src/linting/noun_verb_confusion/effect_affect/effect_to_affect.rs
+++ b/harper-core/src/linting/noun_verb_confusion/effect_affect/effect_to_affect.rs
@@ -54,7 +54,7 @@ impl ExprLinter for EffectToAffect {
let second_following = following.next();
if let Some(prev) = preceding {
- let lower_prev = prev.span.get_content_string(source).to_lowercase();
+ let lower_prev = prev.get_str(source).to_lowercase();
if matches!(
lower_prev.as_str(),
@@ -68,10 +68,7 @@ impl ExprLinter for EffectToAffect {
return None;
}
- let first_following_lower = first_following
- .span
- .get_content_string(source)
- .to_lowercase();
+ let first_following_lower = first_following.get_str(source).to_lowercase();
if matches!(
first_following_lower.as_str(),
@@ -116,7 +113,7 @@ impl ExprLinter for EffectToAffect {
return None;
}
- let token_text = target.span.get_content_string(source);
+ let token_text = target.get_str(source);
let lower = token_text.to_lowercase();
if lower.as_str() == "effects" && preceding.is_some_and(|tok| tok.kind.is_upos(UPOS::VERB))
@@ -136,7 +133,7 @@ impl ExprLinter for EffectToAffect {
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
replacement,
- target.span.get_content(source),
+ target.get_ch(source),
)],
message:
"Use `affect` for the verb meaning to influence; `effect` usually names the result."
@@ -158,15 +155,12 @@ fn is_effect_word(token: &Token, source: &[char]) -> bool {
const EFFECT: &[char] = &['e', 'f', 'f', 'e', 'c', 't'];
const EFFECTS: &[char] = &['e', 'f', 'f', 'e', 'c', 't', 's'];
- let text = token.span.get_content(source);
- text.eq_ignore_ascii_case_chars(EFFECT) || text.eq_ignore_ascii_case_chars(EFFECTS)
+ let text = token.get_ch(source);
+ text.eq_ch(EFFECT) || text.eq_ch(EFFECTS)
}
fn is_token_to(token: &Token, source: &[char]) -> bool {
- token
- .span
- .get_content(source)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
+ token.get_ch(source).eq_ch(&['t', 'o'])
}
fn is_change_like(token: &Token, source: &[char]) -> bool {
@@ -175,11 +169,7 @@ fn is_change_like(token: &Token, source: &[char]) -> bool {
}
matches!(
- token
- .span
- .get_content_string(source)
- .to_lowercase()
- .as_str(),
+ token.get_str(source).to_lowercase().as_str(),
"change" | "changes" | "substitution" | "substitutions"
)
}
diff --git a/harper-core/src/linting/noun_verb_confusion/noun_instead_of_verb/general.rs b/harper-core/src/linting/noun_verb_confusion/noun_instead_of_verb/general.rs
index d88fa84a1..c28ec0e74 100644
--- a/harper-core/src/linting/noun_verb_confusion/noun_instead_of_verb/general.rs
+++ b/harper-core/src/linting/noun_verb_confusion/noun_instead_of_verb/general.rs
@@ -20,11 +20,7 @@ impl Default for GeneralNounInsteadOfVerb {
// Adverbs that can come before verbs but not nouns
// Note: "Sometimes" can come before a noun.
let adverb_of_frequency = |tok: &Token, src: &[char]| {
- tok.kind.is_frequency_adverb()
- && !tok
- .span
- .get_content(src)
- .eq_ignore_ascii_case_str("sometimes")
+ tok.kind.is_frequency_adverb() && !tok.get_ch(src).eq_str("sometimes")
};
let pre_context = FirstMatchOf::new(vec![
@@ -84,8 +80,7 @@ impl ExprLinter for GeneralNounInsteadOfVerb {
{
// But first rule out marginal "nouns"
if !following_tok
- .span
- .get_content(src)
+ .get_ch(src)
.eq_any_ignore_ascii_case_str(&["it", "me", "on", "that"])
{
return None;
@@ -93,30 +88,20 @@ impl ExprLinter for GeneralNounInsteadOfVerb {
}
// If the previous word is "to", use the following word to disambiguate
- if prev_tok
- .span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
- && !following_tok.kind.is_determiner()
- {
+ if prev_tok.get_ch(src).eq_ch(&['t', 'o']) && !following_tok.kind.is_determiner() {
return None;
}
}
// If we don't have the next word token, don't continue if the previous token is "to"
// since "to" is a preposition and an infinitive marker and there's not enough context to disambiguate.
- if toks.len() <= 4
- && prev_tok
- .span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
- {
+ if toks.len() <= 4 && prev_tok.get_ch(src).eq_ch(&['t', 'o']) {
return None;
}
let noun_tok = &toks[2];
- let noun_chars = noun_tok.span.get_content(src);
- let noun_text = noun_tok.span.get_content_string(src);
+ let noun_chars = noun_tok.get_ch(src);
+ let noun_text = noun_tok.get_str(src);
let noun_lower = noun_text.to_lowercase();
let verb = NOUN_VERB_PAIRS
diff --git a/harper-core/src/linting/noun_verb_confusion/verb_instead_of_noun.rs b/harper-core/src/linting/noun_verb_confusion/verb_instead_of_noun.rs
index 733e9e0f1..35aaa6c68 100644
--- a/harper-core/src/linting/noun_verb_confusion/verb_instead_of_noun.rs
+++ b/harper-core/src/linting/noun_verb_confusion/verb_instead_of_noun.rs
@@ -42,8 +42,8 @@ impl ExprLinter for VerbInsteadOfNoun {
let adj_tok = &toks.first()?;
let verb_tok = &toks.last()?;
- let adj_text = adj_tok.span.get_content_string(src);
- let verb_text = verb_tok.span.get_content_string(src);
+ let adj_text = adj_tok.get_str(src);
+ let verb_text = verb_tok.get_str(src);
let verb_lower = verb_text.to_lowercase();
if adj_tok.kind.is_auxiliary_verb() || adj_tok.kind.is_upos(UPOS::AUX) {
@@ -71,7 +71,7 @@ impl ExprLinter for VerbInsteadOfNoun {
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case(
noun.chars().collect(),
- verb_tok.span.get_content(src),
+ verb_tok.get_ch(src),
)],
message: format!("`{verb_text}` is a verb, the noun should be `{noun}`."),
priority: 63,
diff --git a/harper-core/src/linting/obsess_preposition.rs b/harper-core/src/linting/obsess_preposition.rs
index 4c5867a5e..7090ca65e 100644
--- a/harper-core/src/linting/obsess_preposition.rs
+++ b/harper-core/src/linting/obsess_preposition.rs
@@ -64,11 +64,11 @@ impl ExprLinter for ObsessPreposition {
// 👎
// obsessed of
- if prep_chars.eq_ignore_ascii_case_str("over") {
+ if prep_chars.eq_str("over") {
return None;
}
- if conj == Conj::Ed && prep_chars.eq_ignore_ascii_case_str("with") {
+ if conj == Conj::Ed && prep_chars.eq_str("with") {
return None;
}
diff --git a/harper-core/src/linting/oldest_in_the_book.rs b/harper-core/src/linting/oldest_in_the_book.rs
index 8fafd034e..b6cb715f0 100644
--- a/harper-core/src/linting/oldest_in_the_book.rs
+++ b/harper-core/src/linting/oldest_in_the_book.rs
@@ -14,10 +14,7 @@ impl Default for OldestInTheBook {
let k = &t.kind;
(k.is_np_member() || k.is_adjective())
&& !k.is_noun()
- && !t
- .span
- .get_content(s)
- .eq_ignore_ascii_case_chars(&['i', 'n'])
+ && !t.get_ch(s).eq_ch(&['i', 'n'])
};
// Zero or more adjectives
@@ -25,11 +22,7 @@ impl Default for OldestInTheBook {
let noun = |t: &Token, s: &[char]| {
let k = &t.kind;
- (k.is_np_member() || k.is_noun() || k.is_oov())
- && !t
- .span
- .get_content(s)
- .eq_ignore_ascii_case_chars(&['i', 'n'])
+ (k.is_np_member() || k.is_noun() || k.is_oov()) && !t.get_ch(s).eq_ch(&['i', 'n'])
};
// One or more nouns
@@ -63,8 +56,7 @@ impl ExprLinter for OldestInTheBook {
) -> Option<Lint> {
let np = &toks[2..toks.len() - 4];
let tricky = np.iter().any(|n| {
- n.span
- .get_content(src)
+ n.get_ch(src)
.eq_any_ignore_ascii_case_str(&["trick", "tricks"])
});
@@ -80,7 +72,7 @@ impl ExprLinter for OldestInTheBook {
lint_kind: LintKind::Usage,
suggestions: vec![Suggestion::replace_with_match_case_str(
"book",
- toks.last()?.span.get_content(src),
+ toks.last()?.get_ch(src),
)],
message,
..Default::default()
diff --git a/harper-core/src/linting/once_or_twice.rs b/harper-core/src/linting/once_or_twice.rs
index 9be0a624d..64f04a9b6 100644
--- a/harper-core/src/linting/once_or_twice.rs
+++ b/harper-core/src/linting/once_or_twice.rs
@@ -29,9 +29,9 @@ impl ExprLinter for OnceOrTwice {
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let article = matched_tokens.iter().find(|token| {
- token.kind.is_word() && token.span.get_content(source).eq_ignore_ascii_case_str("a")
- })?;
+ let article = matched_tokens
+ .iter()
+ .find(|token| token.kind.is_word() && token.get_ch(source).eq_str("a"))?;
let span = article.span;
let original = span.get_content(source);
diff --git a/harper-core/src/linting/one_and_the_same.rs b/harper-core/src/linting/one_and_the_same.rs
index e3342c9e4..7454c8378 100644
--- a/harper-core/src/linting/one_and_the_same.rs
+++ b/harper-core/src/linting/one_and_the_same.rs
@@ -44,7 +44,7 @@ impl ExprLinter for OneAndTheSame {
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let phrase = if matched_tokens.last()?.span.get_content(source) == ['a', 's'] {
+ let phrase = if matched_tokens.last()?.get_ch(source) == ['a', 's'] {
matched_tokens[0..matched_tokens.len() - 2].span()?
} else {
matched_tokens[2..].span()?
diff --git a/harper-core/src/linting/one_of_the_singular.rs b/harper-core/src/linting/one_of_the_singular.rs
index 57a954eba..ba36892da 100644
--- a/harper-core/src/linting/one_of_the_singular.rs
+++ b/harper-core/src/linting/one_of_the_singular.rs
@@ -24,9 +24,7 @@ impl SeqExprExt for SequenceExpr {
(t.kind.is_non_possessive_noun() || t.kind.is_adjective())
&& !t.kind.is_preposition() // "in" etc.
&& !t.kind.is_pronoun() // "who" etc.
- && !t
- .span
- .get_content(s)
+ && !t.get_ch(s)
.eq_any_ignore_ascii_case_str(&["ah", "few", "first", "said", "uh"])
})
}
diff --git a/harper-core/src/linting/open_compounds.rs b/harper-core/src/linting/open_compounds.rs
index 2d2929575..ee445dd41 100644
--- a/harper-core/src/linting/open_compounds.rs
+++ b/harper-core/src/linting/open_compounds.rs
@@ -137,8 +137,7 @@ fn get_compound_idx(toks: &[Token], src: &[char], compound: &str) -> Option<usiz
} else {
Some(
!tok0
- .span
- .get_content(src)
+ .get_ch(src)
.iter()
.collect::<String>()
.eq_ignore_ascii_case(compound) as usize,
diff --git a/harper-core/src/linting/open_the_light.rs b/harper-core/src/linting/open_the_light.rs
index c3bcd5168..01b598774 100644
--- a/harper-core/src/linting/open_the_light.rs
+++ b/harper-core/src/linting/open_the_light.rs
@@ -77,7 +77,7 @@ impl ExprLinter for OpenTheLight {
const ES: &[char] = &['e', 's'];
const LEMMA: &[char] = &[];
- let verb: &[char] = toks.first()?.span.get_content(src);
+ let verb: &[char] = toks.first()?.get_ch(src);
let (e, n, d) = (
verb[verb.len() - 3],
diff --git a/harper-core/src/linting/orthographic_consistency.rs b/harper-core/src/linting/orthographic_consistency.rs
index 76d45b48d..fc2567a3d 100644
--- a/harper-core/src/linting/orthographic_consistency.rs
+++ b/harper-core/src/linting/orthographic_consistency.rs
@@ -64,7 +64,7 @@ impl ExprLinter for OrthographicConsistency {
return None;
};
- let chars = word.span.get_content(source);
+ let chars = word.get_ch(source);
let cur_flags = OrthFlags::from_letters(chars);
diff --git a/harper-core/src/linting/phrasal_verb_as_compound_noun.rs b/harper-core/src/linting/phrasal_verb_as_compound_noun.rs
index 452ca4ce1..c0d3cbbe4 100644
--- a/harper-core/src/linting/phrasal_verb_as_compound_noun.rs
+++ b/harper-core/src/linting/phrasal_verb_as_compound_noun.rs
@@ -167,10 +167,7 @@ impl PhrasalVerbAsCompoundNoun {
// "dictionary lookup" is not a mistake but "couples breakup" is.
// But "settings plugin" is not.
if prev_tok.kind.is_noun() && !prev_tok.kind.is_plural_noun()
- || prev_tok
- .span
- .get_content(document.get_source())
- .eq_ignore_ascii_case_str("settings")
+ || prev_tok.get_ch(document.get_source()).eq_str("settings")
{
return Err(Why::ItsPrecededByANonPluralNoun);
}
@@ -181,10 +178,7 @@ impl PhrasalVerbAsCompoundNoun {
// If the previous word is (only) a preposition, this word is surely a noun
if prev_tok.kind.is_preposition()
- && !prev_tok
- .span
- .get_content(document.get_source())
- .eq_ignore_ascii_case_str("to")
+ && !prev_tok.get_ch(document.get_source()).eq_str("to")
{
return Err(Why::ItsPrecededByAPreposition);
}
@@ -208,8 +202,7 @@ impl PhrasalVerbAsCompoundNoun {
// "That" or "which" can follow a noun as relative pronouns.
if next_tok.kind.is_pronoun()
&& next_tok
- .span
- .get_content(document.get_source())
+ .get_ch(document.get_source())
.eq_any_ignore_ascii_case_chars(&[
&['t', 'h', 'a', 't'][..],
&['w', 'h', 'i', 'c', 'h'][..],
@@ -260,8 +253,7 @@ impl PhrasalVerbAsCompoundNoun {
}
.contains(
&next_tok
- .span
- .get_content_string(document.get_source())
+ .get_str(document.get_source())
.to_lowercase()
.as_ref(),
)
diff --git a/harper-core/src/linting/pique_interest.rs b/harper-core/src/linting/pique_interest.rs
index fbd9bc3d0..516d60505 100644
--- a/harper-core/src/linting/pique_interest.rs
+++ b/harper-core/src/linting/pique_interest.rs
@@ -57,7 +57,7 @@ impl ExprLinter for PiqueInterest {
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case(
correct.to_vec(),
- matched_tokens[0].span.get_content(source),
+ matched_tokens[0].get_ch(source),
)],
message: format!(
"Did you mean `{}` instead of `{}`?",
diff --git a/harper-core/src/linting/plural_decades/four_digits.rs b/harper-core/src/linting/plural_decades/four_digits.rs
index 779d2ad5a..df8f08974 100644
--- a/harper-core/src/linting/plural_decades/four_digits.rs
+++ b/harper-core/src/linting/plural_decades/four_digits.rs
@@ -29,7 +29,7 @@ pub fn match_to_lint_four_digits(
{
Some(Context {
sep_is_hyphen: psep.kind.is_hyphen(),
- word: pw.span.get_content(src),
+ word: pw.get_ch(src),
})
} else {
None
@@ -42,7 +42,7 @@ pub fn match_to_lint_four_digits(
{
Some(Context {
sep_is_hyphen: nsep.kind.is_hyphen(),
- word: nw.span.get_content(src),
+ word: nw.get_ch(src),
})
} else {
None
@@ -60,12 +60,8 @@ pub fn match_to_lint_four_digits(
// Hyphen before suggests username, not a mistake
(Some(before), _) if before.sep_is_hyphen => UsageJudgment::NotMistake,
// "style" after the decade suggests the apostrophe is a mistake
- (_, Some(after)) if after.word.eq_ignore_ascii_case_str("style") => {
- UsageJudgment::IsMistake
- }
- (Some(before), _)
- if !before.sep_is_hyphen && before.word.eq_ignore_ascii_case_str("the") =>
- {
+ (_, Some(after)) if after.word.eq_str("style") => UsageJudgment::IsMistake,
+ (Some(before), _) if !before.sep_is_hyphen && before.word.eq_str("the") => {
// Go back one more word and look for "in the" before the decade
if let [.., ppw, ppsep, _, _] = pre.unwrap()
&& ppsep.kind.is_whitespace()
diff --git a/harper-core/src/linting/plural_decades/mod.rs b/harper-core/src/linting/plural_decades/mod.rs
index ffa3b73b9..b20d0c8ad 100644
--- a/harper-core/src/linting/plural_decades/mod.rs
+++ b/harper-core/src/linting/plural_decades/mod.rs
@@ -47,8 +47,7 @@ impl ExprLinter for PluralDecades {
return None;
}
- let (decade_chars, _s_chars) =
- (toks[0].span.get_content(src), toks[2].span.get_content(src));
+ let (decade_chars, _s_chars) = (toks[0].get_ch(src), toks[2].get_ch(src));
// TODO does not yet support two-digit decades like 80's
// if decade_chars.len() != 4 || !decade_chars.ends_with(&['0']) {
@@ -56,8 +55,7 @@ impl ExprLinter for PluralDecades {
return None;
}
- let (decade_chars, s_chars) =
- (toks[0].span.get_content(src), toks[2].span.get_content(src));
+ let (decade_chars, s_chars) = (toks[0].get_ch(src), toks[2].get_ch(src));
let (before_context, after_context): (Option<&[Token]>, Option<&[Token]>) = match ctx {
Some((pw, nw)) => {
diff --git a/harper-core/src/linting/plural_decades/two_digits.rs b/harper-core/src/linting/plural_decades/two_digits.rs
index 29ea37fdf..130f8e215 100644
--- a/harper-core/src/linting/plural_decades/two_digits.rs
+++ b/harper-core/src/linting/plural_decades/two_digits.rs
@@ -38,7 +38,7 @@ pub fn match_to_lint_two_digits(
} else if tok.kind.is_plus() {
return Some(Tok::Plus);
} else if tok.kind.is_word() {
- return Some(Tok::Word(tok.span.get_content(src)));
+ return Some(Tok::Word(tok.get_ch(src)));
}
}
None
@@ -63,7 +63,7 @@ pub fn match_to_lint_two_digits(
} else if tok.kind.is_plus() {
Tok::Plus
} else if tok.kind.is_word() {
- Tok::Word(tok.span.get_content(src))
+ Tok::Word(tok.get_ch(src))
} else {
return None;
},
@@ -79,7 +79,7 @@ pub fn match_to_lint_two_digits(
&& let Some((tok2, kind2)) = get_tok_with_kind(before, -2)
{
// in the 80's
- if matches!(tok2, Tok::Word(w) if w.eq_ignore_ascii_case_str("the"))
+ if matches!(tok2, Tok::Word(w) if w.eq_str("the"))
&& get_kind(before, -3).is_some_and(|k| k.is_whitespace())
&& get_kind(before, -4).is_some_and(|k| k.is_preposition())
{
@@ -90,7 +90,7 @@ pub fn match_to_lint_two_digits(
return UsageJudgment::IsMistakeForAgeRange;
}
// Windows 10's / Xcode 10's
- if decade.eq_ignore_ascii_case_str("10")
+ if decade.eq_str("10")
&& matches!(tok2, Tok::Word(w) if w.eq_any_ignore_ascii_case_str(&["windows", "xcode", "android"]))
{
return UsageJudgment::NotMistake;
@@ -107,10 +107,9 @@ pub fn match_to_lint_two_digits(
}
// +10's
if matches!(tok1, Tok::Plus)
- && decade.eq_ignore_ascii_case_str("20")
+ && decade.eq_str("20")
&& get_tok(before, -2).is_some_and(|t| matches!(t, Tok::Plus))
- && get_tok(before, -3)
- .is_some_and(|t| matches!(t, Tok::Word(w) if w.eq_ignore_ascii_case_str("c")))
+ && get_tok(before, -3).is_some_and(|t| matches!(t, Tok::Word(w) if w.eq_str("c")))
{
// C++10's
return UsageJudgment::NotMistake;
@@ -118,8 +117,7 @@ pub fn match_to_lint_two_digits(
}
// 70's_style / 80's-style
if get_tok(after, 0).is_some_and(|t| matches!(t, Tok::Whitespace | Tok::Hyphen))
- && get_tok(after, 1)
- .is_some_and(|t| matches!(t, Tok::Word(w) if w.eq_ignore_ascii_case_str("style")))
+ && get_tok(after, 1).is_some_and(|t| matches!(t, Tok::Word(w) if w.eq_str("style")))
{
return UsageJudgment::IsMistakeForDecade;
}
diff --git a/harper-core/src/linting/plural_wrong_word_of_phrase.rs b/harper-core/src/linting/plural_wrong_word_of_phrase.rs
index 232276f9b..6da1a5c5d 100644
--- a/harper-core/src/linting/plural_wrong_word_of_phrase.rs
+++ b/harper-core/src/linting/plural_wrong_word_of_phrase.rs
@@ -23,13 +23,13 @@ impl Default for PluralWrongWordOfPhrase {
fn default() -> Self {
let word_str = |w| {
SequenceExpr::with(move |t: &Token, s: &[char]| {
- t.kind.is_word() && t.span.get_content(s).eq_ignore_ascii_case_str(w)
+ t.kind.is_word() && t.get_ch(s).eq_str(w)
})
};
let word_string = |w: String| {
SequenceExpr::with(move |t: &Token, s: &[char]| {
- t.kind.is_word() && t.span.get_content(s).eq_ignore_ascii_case_str(&w)
+ t.kind.is_word() && t.get_ch(s).eq_str(&w)
})
};
diff --git a/harper-core/src/linting/progressive_needs_be.rs b/harper-core/src/linting/progressive_needs_be.rs
index d0e3676af..de7ad720b 100644
--- a/harper-core/src/linting/progressive_needs_be.rs
+++ b/harper-core/src/linting/progressive_needs_be.rs
@@ -47,7 +47,7 @@ impl ExprLinter for ProgressiveNeedsBe {
// If this is the non-contracted pattern, extend the replacement span to include "have"
let have_tok_opt = word_toks
.iter()
- .find(|t| t.span.get_content(src).eq_ignore_ascii_case_str("have"))
+ .find(|t| t.get_ch(src).eq_str("have"))
.copied();
let span = if let Some(have_tok) = have_tok_opt {
@@ -57,7 +57,7 @@ impl ExprLinter for ProgressiveNeedsBe {
};
// Choose the correct "be" contraction based on the pronoun
- let pronoun = first_word.span.get_content(src);
+ let pronoun = first_word.get_ch(src);
let progressive_replacement = if pronoun.starts_with_ignore_ascii_case_str("i") {
"I'm"
} else if pronoun.starts_with_ignore_ascii_case_str("we") {
diff --git a/harper-core/src/linting/pronoun_are.rs b/harper-core/src/linting/pronoun_are.rs
index 362af6f43..13f9a4178 100644
--- a/harper-core/src/linting/pronoun_are.rs
+++ b/harper-core/src/linting/pronoun_are.rs
@@ -40,9 +40,9 @@ impl ExprLinter for PronounAre {
let gap = tokens.get(1)?;
let letter = tokens.get(2)?;
- let pronoun_chars = pronoun.span.get_content(source);
- let gap_chars = gap.span.get_content(source);
- let letter_chars = letter.span.get_content(source);
+ let pronoun_chars = pronoun.get_ch(source);
+ let gap_chars = gap.get_ch(source);
+ let letter_chars = letter.get_ch(source);
let all_pronoun_letters_uppercase = pronoun_chars
.iter()
diff --git a/harper-core/src/linting/pronoun_contraction/avoid_contraction.rs b/harper-core/src/linting/pronoun_contraction/avoid_contraction.rs
index 928a65092..13b1b87bd 100644
--- a/harper-core/src/linting/pronoun_contraction/avoid_contraction.rs
+++ b/harper-core/src/linting/pronoun_contraction/avoid_contraction.rs
@@ -28,7 +28,7 @@ impl ExprLinter for AvoidContraction {
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let word = matched_tokens[0].span.get_content(source);
+ let word = matched_tokens[0].get_ch(source);
Some(Lint {
span: matched_tokens[0].span,
diff --git a/harper-core/src/linting/pronoun_knew.rs b/harper-core/src/linting/pronoun_knew.rs
index 55d53af45..6ddc67cfb 100644
--- a/harper-core/src/linting/pronoun_knew.rs
+++ b/harper-core/src/linting/pronoun_knew.rs
@@ -31,7 +31,7 @@ impl Default for PronounKnew {
return false;
}
- let pronorm = tok.span.get_content_string(source).to_lowercase();
+ let pronorm = tok.get_str(source).to_lowercase();
let excluded = ["every", "something", "nothing"];
!excluded.contains(&&*pronorm)
};
diff --git a/harper-core/src/linting/pronoun_verb_agreement.rs b/harper-core/src/linting/pronoun_verb_agreement.rs
index d3ef6cea0..2940742c8 100644
--- a/harper-core/src/linting/pronoun_verb_agreement.rs
+++ b/harper-core/src/linting/pronoun_verb_agreement.rs
@@ -77,7 +77,7 @@ where
&& !t.kind.is_conjunction() // "and"
&& (!t.kind.is_auxiliary_verb() // "I go"≠"he goes" but "I can"="he can"
// We don't want modals because they don't inflect, but we want the other auxiliaries.
- || t.span.get_content(src).eq_any_ignore_ascii_case_str(NON_MODAL_AUX))
+ || t.get_ch(src).eq_any_ignore_ascii_case_str(NON_MODAL_AUX))
};
Self {
@@ -118,10 +118,7 @@ where
}
}
- if let Some((lemma, _)) = IRREGULAR
- .iter()
- .find(|(_, f)| form.eq_ignore_ascii_case_str(f))
- {
+ if let Some((lemma, _)) = IRREGULAR.iter().find(|(_, f)| form.eq_str(f)) {
words.push(lemma.chars().collect::<Vec<char>>());
}
@@ -194,14 +191,14 @@ where
&& let [.., prev_word_tok, ws_tok] = before
&& ws_tok.kind.is_whitespace()
{
- let prev_word = prev_word_tok.span.get_content(src);
+ let prev_word = prev_word_tok.get_ch(src);
let is_exempt = if is_3psg {
prev_word_tok.kind.is_auxiliary_verb()
|| prev_word.eq_any_ignore_ascii_case_str(SUBJUNCTIVE)
} else if pron_tok.kind.is_subject_pronoun() {
// Clause structure: (... in you) is ... ≠ you is
// Look for "true" prepositions, not ones that are more like adverbial particles
- prev_word_tok.kind.is_preposition() && !prev_word.eq_ignore_ascii_case_str("up")
+ prev_word_tok.kind.is_preposition() && !prev_word.eq_str("up")
// When the verb is ditransitive, the pronoun is object case, the verb position is actually a noun
|| (prev_word.eq_any_ignore_ascii_case_str(DITRANSITIVE) && verb_tok.kind.is_noun())
} else {
@@ -214,8 +211,8 @@ where
}
let verb_span = verb_tok.span;
- let verb_chars = verb_tok.span.get_content(src);
- let verb_str = verb_tok.span.get_content_string(src);
+ let verb_chars = verb_tok.get_ch(src);
+ let verb_str = verb_tok.get_str(src);
let suggs = if is_3psg {
self.lemma_to_third_person_singular_present(&verb_str)
diff --git a/harper-core/src/linting/proper_noun_capitalization_linters.rs b/harper-core/src/linting/proper_noun_capitalization_linters.rs
index 4ef6f9a83..6249de7af 100644
--- a/harper-core/src/linting/proper_noun_capitalization_linters.rs
+++ b/harper-core/src/linting/proper_noun_capitalization_linters.rs
@@ -61,7 +61,7 @@ impl<D: Dictionary + 'static> ExprLinter for ProperNounCapitalizationLinter<D> {
let mut broken = false;
for (err_token, correct_token) in matched_tokens.iter().zip(canonical_case.fat_tokens()) {
- let err_chars = err_token.span.get_content(source);
+ let err_chars = err_token.get_ch(source);
if err_chars != correct_token.content {
broken = true;
break;
diff --git a/harper-core/src/linting/quantifier_numeral_conflict.rs b/harper-core/src/linting/quantifier_numeral_conflict.rs
index 3d6ddae51..5da3c8d3c 100644
--- a/harper-core/src/linting/quantifier_numeral_conflict.rs
+++ b/harper-core/src/linting/quantifier_numeral_conflict.rs
@@ -56,7 +56,7 @@ impl ExprLinter for QuantifierNumeralConflict {
}
let qtok = toks.first().unwrap();
- let quant = qtok.span.get_content_string(src);
+ let quant = qtok.get_str(src);
// Handle special cases for "least", "most", "each", and "both"
match quant.to_ascii_lowercase().as_str() {
@@ -65,10 +65,7 @@ impl ExprLinter for QuantifierNumeralConflict {
&& let [.., prev_word, prev_space] = previous
&& prev_space.kind.is_whitespace()
&& prev_word.kind.is_word()
- && prev_word
- .span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['a', 't'])
+ && prev_word.get_ch(src).eq_ch(&['a', 't'])
{
return None;
}
@@ -80,7 +77,7 @@ impl ExprLinter for QuantifierNumeralConflict {
lint_kind: LintKind::Usage,
suggestions: vec![Suggestion::replace_with_match_case(
"every".chars().collect(),
- qtok.span.get_content(src),
+ qtok.get_ch(src),
)],
message: "Use 'every' instead of 'each' before a number.".to_owned(),
..Default::default()
@@ -93,10 +90,7 @@ impl ExprLinter for QuantifierNumeralConflict {
&& let [ws, conj, ..] = following.get(noun_phrase_span.end..).unwrap_or(&[])
&& ws.kind.is_whitespace()
&& conj.kind.is_conjunction()
- && conj
- .span
- .get_content_string(src)
- .eq_ignore_ascii_case("and")
+ && conj.get_str(src).eq_ignore_ascii_case("and")
{
return None;
}
diff --git a/harper-core/src/linting/quite_quiet.rs b/harper-core/src/linting/quite_quiet.rs
index 944a6731a..2a64bf64c 100644
--- a/harper-core/src/linting/quite_quiet.rs
+++ b/harper-core/src/linting/quite_quiet.rs
@@ -26,8 +26,7 @@ impl Default for QuiteQuiet {
if !tok.kind.is_verb() || !tok.kind.is_apostrophized() {
return false;
}
- tok.span
- .get_content(src)
+ tok.get_ch(src)
.ends_with_any_ignore_ascii_case_chars(&[&['n', '\'', 't'], &['n', '’', 't']])
})
.t_ws()
diff --git a/harper-core/src/linting/reason_for_doing.rs b/harper-core/src/linting/reason_for_doing.rs
index a271999b5..32ae331e0 100644
--- a/harper-core/src/linting/reason_for_doing.rs
+++ b/harper-core/src/linting/reason_for_doing.rs
@@ -47,18 +47,14 @@ impl ExprLinter for ReasonForDoing {
const OF: usize = 2;
// let reasontok = &toks[REASON];
// let reasonspan = reasontok.span;
- let reasonchars = toks[REASON].span.get_content(src);
+ let reasonchars = toks[REASON].get_ch(src);
// let oftok = &toks[OF];
let ofspan = toks[OF].span;
// let ofchars = ofspan.get_content(src);
// "for reasons of doing" is a legit construction. TODO: Usually, but not always!
if reasonchars.last()? == &'s'
- && preceded_by_word(ctx, |t| {
- t.span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['f', 'o', 'r'])
- })
+ && preceded_by_word(ctx, |t| t.get_ch(src).eq_ch(&['f', 'o', 'r']))
{
return None;
}
diff --git a/harper-core/src/linting/redundant_acronyms.rs b/harper-core/src/linting/redundant_acronyms.rs
index 9a2b3fa7e..b7719011f 100644
--- a/harper-core/src/linting/redundant_acronyms.rs
+++ b/harper-core/src/linting/redundant_acronyms.rs
@@ -31,9 +31,7 @@ impl Default for RedundantAcronyms {
Box::new(SequenceExpr::aco(acronym).t_ws().then_any_of(vec![
Box::new(Word::new(last_str)),
Box::new(move |t: &Token, src: &[char]| {
- t.span
- .get_content(src)
- .eq_ignore_ascii_case_str(&format!("{last_string}s"))
+ t.get_ch(src).eq_str(&format!("{last_string}s"))
}),
])) as Box<dyn Expr>
})
@@ -55,7 +53,7 @@ impl ExprLinter for RedundantAcronyms {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let last_word_span = toks.last()?.span;
let last_word_chars = last_word_span.get_content(src);
- let acronym_str = toks.first()?.span.get_content_string(src);
+ let acronym_str = toks.first()?.get_str(src);
// "pin number" (lowercase) is used to refer to the pins on microchips, etc.
if acronym_str.eq_ignore_ascii_case("PIN") && acronym_str != "PIN" {
diff --git a/harper-core/src/linting/redundant_additive_adverbs.rs b/harper-core/src/linting/redundant_additive_adverbs.rs
index 778affb76..9a66572b9 100644
--- a/harper-core/src/linting/redundant_additive_adverbs.rs
+++ b/harper-core/src/linting/redundant_additive_adverbs.rs
@@ -60,7 +60,7 @@ impl ExprLinter for RedundantAdditiveAdverbs {
for word in toks
.iter()
.filter(|tok| tok.kind.is_word())
- .map(|tok| tok.span.get_content(src))
+ .map(|tok| tok.get_ch(src))
.collect::<Vec<_>>()
{
let term: &[char] = match word {
diff --git a/harper-core/src/linting/redundant_progressive_comparative.rs b/harper-core/src/linting/redundant_progressive_comparative.rs
index f00d47a3a..cacd58d74 100644
--- a/harper-core/src/linting/redundant_progressive_comparative.rs
+++ b/harper-core/src/linting/redundant_progressive_comparative.rs
@@ -33,20 +33,12 @@ impl ExprLinter for RedundantProgressiveComparative {
let first = matched_tokens.first()?;
let second = matched_tokens.get(2)?;
- let (replacement, message) = if second
- .span
- .get_content(src)
- .eq_ignore_ascii_case_str("more")
- {
+ let (replacement, message) = if second.get_ch(src).eq_str("more") {
(
"more and more",
"This phrasing is redundant; use a direct comparative like `more and more`.",
)
- } else if second
- .span
- .get_content(src)
- .eq_ignore_ascii_case_str("less")
- {
+ } else if second.get_ch(src).eq_str("less") {
(
"less and less",
"This phrasing is redundant; use a direct comparative like `less and less`.",
diff --git a/harper-core/src/linting/respond.rs b/harper-core/src/linting/respond.rs
index 7f40c43b2..93cc51e32 100644
--- a/harper-core/src/linting/respond.rs
+++ b/harper-core/src/linting/respond.rs
@@ -20,7 +20,7 @@ impl Default for Respond {
return false;
}
- let lower = tok.span.get_content_string(src).to_lowercase();
+ let lower = tok.get_str(src).to_lowercase();
matches!(
lower.as_str(),
"do" | "did" | "does" | "won't" | "don't" | "didn't" | "doesn't"
@@ -69,7 +69,7 @@ impl ExprLinter for Respond {
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
"respond",
- response_token.span.get_content(source),
+ response_token.get_ch(source),
)],
message: "Use the verb `respond` here.".to_owned(),
priority: 40,
diff --git a/harper-core/src/linting/right_click.rs b/harper-core/src/linting/right_click.rs
index 2df17fe1f..2c0a35b04 100644
--- a/harper-core/src/linting/right_click.rs
+++ b/harper-core/src/linting/right_click.rs
@@ -38,8 +38,8 @@ impl ExprLinter for RightClick {
let span = matched_tokens.get(start_idx..=click_idx)?.span()?;
let template = span.get_content(source);
- let direction = matched_tokens.get(start_idx)?.span.get_content(source);
- let click = matched_tokens.get(click_idx)?.span.get_content(source);
+ let direction = matched_tokens.get(start_idx)?.get_ch(source);
+ let click = matched_tokens.get(click_idx)?.get_ch(source);
let replacement: Vec<char> = direction
.iter()
diff --git a/harper-core/src/linting/safe_to_save.rs b/harper-core/src/linting/safe_to_save.rs
index 089224236..a5cda74a3 100644
--- a/harper-core/src/linting/safe_to_save.rs
+++ b/harper-core/src/linting/safe_to_save.rs
@@ -47,7 +47,7 @@ impl ExprLinter for SafeToSave {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let safe_idx = toks
.iter()
- .position(|t| t.span.get_content_string(src).to_lowercase() == "safe")?;
+ .position(|t| t.get_str(src).to_lowercase() == "safe")?;
let safe_tok = &toks[safe_idx];
diff --git a/harper-core/src/linting/save_to_safe.rs b/harper-core/src/linting/save_to_safe.rs
index 7b7d1c641..25319b88a 100644
--- a/harper-core/src/linting/save_to_safe.rs
+++ b/harper-core/src/linting/save_to_safe.rs
@@ -35,7 +35,7 @@ impl ExprLinter for SaveToSafe {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let save_tok = &toks.get(2)?;
let verb_tok = &toks.get(4)?;
- let verb = verb_tok.span.get_content_string(src).to_lowercase();
+ let verb = verb_tok.get_str(src).to_lowercase();
Some(Lint {
span: save_tok.span,
lint_kind: LintKind::WordChoice,
diff --git a/harper-core/src/linting/shoot_oneself_in_the_foot.rs b/harper-core/src/linting/shoot_oneself_in_the_foot.rs
index 72059563a..909258889 100644
--- a/harper-core/src/linting/shoot_oneself_in_the_foot.rs
+++ b/harper-core/src/linting/shoot_oneself_in_the_foot.rs
@@ -39,17 +39,17 @@ impl ExprLinter for ShootOneselfInTheFoot {
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
- let pron = &toks.get(2)?.span.get_content(src);
- let prep = &toks.get(4)?.span.get_content(src);
- let det = &toks.get(6)?.span.get_content(src);
- let body_part = &toks.get(8)?.span.get_content(src);
+ let pron = &toks.get(2)?.get_ch(src);
+ let prep = &toks.get(4)?.get_ch(src);
+ let det = &toks.get(6)?.get_ch(src);
+ let body_part = &toks.get(8)?.get_ch(src);
let plural_pron = pron.ends_with_ignore_ascii_case_str("elves");
let plural_foot = toks.get(8)?.kind.is_plural_noun();
- let is_in = prep.eq_ignore_ascii_case_str("in");
- let is_the = det.eq_ignore_ascii_case_str("the");
- let is_foot = body_part.eq_ignore_ascii_case_str("foot");
+ let is_in = prep.eq_str("in");
+ let is_the = det.eq_str("the");
+ let is_foot = body_part.eq_str("foot");
let foot_ok = is_foot || (plural_pron && plural_foot);
diff --git a/harper-core/src/linting/simple_past_to_past_participle.rs b/harper-core/src/linting/simple_past_to_past_participle.rs
index 5ee0831db..c68b6a2be 100644
--- a/harper-core/src/linting/simple_past_to_past_participle.rs
+++ b/harper-core/src/linting/simple_past_to_past_participle.rs
@@ -69,7 +69,7 @@ impl ExprLinter for SimplePastToPastParticiple {
let verb_tok = &toks[2];
- let simple_past = verb_tok.span.get_content_string(src);
+ let simple_past = verb_tok.get_str(src);
if let Some(past_participle) = IrregularVerbs::curated()
.get_past_participle_for_preterite(&simple_past)
@@ -77,7 +77,7 @@ impl ExprLinter for SimplePastToPastParticiple {
{
let suggestions = vec![Suggestion::replace_with_match_case(
past_participle.chars().collect(),
- verb_tok.span.get_content(src),
+ verb_tok.get_ch(src),
)];
let message = format!(
diff --git a/harper-core/src/linting/since_duration.rs b/harper-core/src/linting/since_duration.rs
index ea7434fe5..e92b9f370 100644
--- a/harper-core/src/linting/since_duration.rs
+++ b/harper-core/src/linting/since_duration.rs
@@ -48,8 +48,7 @@ impl ExprLinter for SinceDuration {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let last = toks.last()?;
if last
- .span
- .get_content(src)
+ .get_ch(src)
.eq_any_ignore_ascii_case_chars(&[&['a', 'g', 'o'], &['o', 'l', 'd']])
{
return None;
@@ -59,7 +58,7 @@ impl ExprLinter for SinceDuration {
let mut since_point_in_time = since_duration_span.get_content(src).to_vec();
since_point_in_time.push(' ');
- let unit_template = toks.last()?.span.get_content(src);
+ let unit_template = toks.last()?.get_ch(src);
since_point_in_time.extend(
match_case_string(unit_template, AGO_VARIANTS)
.iter()
@@ -68,7 +67,7 @@ impl ExprLinter for SinceDuration {
let ago_suggestion = Suggestion::ReplaceWith(since_point_in_time);
let duration = toks[1..].span()?.get_content(src);
- let since_template = toks.first()?.span.get_content(src);
+ let since_template = toks.first()?.get_ch(src);
let mut for_duration = match_case_string(since_template, FOR_VARIANTS).to_vec();
for_duration.extend(duration);
let for_suggestion = Suggestion::ReplaceWith(for_duration);
diff --git a/harper-core/src/linting/single_be.rs b/harper-core/src/linting/single_be.rs
index fa454a7c8..21982147b 100644
--- a/harper-core/src/linting/single_be.rs
+++ b/harper-core/src/linting/single_be.rs
@@ -30,7 +30,7 @@ fn looks_like_be_contraction(token: &Token, source: &[char]) -> bool {
return false;
}
- let content = token.span.get_content(source);
+ let content = token.get_ch(source);
let Some(apostrophe_idx) = content.iter().rposition(|c| matches!(*c, '\'' | '’')) else {
return false;
};
@@ -94,8 +94,7 @@ impl ExprLinter for SingleBe {
}
if first.kind.is_possessive_nominal()
&& first
- .span
- .get_content(source)
+ .get_ch(source)
.first()
.is_some_and(|c| c.is_uppercase())
{
@@ -121,7 +120,7 @@ impl ExprLinter for SingleBe {
.map(is_past_flag)
.unwrap_or_else(|| second.kind.is_verb_past_form());
- let first_chars = first.span.get_content(source);
+ let first_chars = first.get_ch(source);
let base_before_apostrophe = first_chars
.iter()
.rposition(|c| matches!(*c, '\'' | '’'))
diff --git a/harper-core/src/linting/some_without_article.rs b/harper-core/src/linting/some_without_article.rs
index 22d177054..02df8a1df 100644
--- a/harper-core/src/linting/some_without_article.rs
+++ b/harper-core/src/linting/some_without_article.rs
@@ -29,7 +29,7 @@ impl ExprLinter for SomeWithoutArticle {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let span = matched_tokens.span()?;
let template = span.get_content(source);
- let some_chars = matched_tokens.last()?.span.get_content(source);
+ let some_chars = matched_tokens.last()?.get_ch(source);
let suggestions = vec![
Suggestion::ReplaceWith(some_chars.to_vec()),
diff --git a/harper-core/src/linting/something_is.rs b/harper-core/src/linting/something_is.rs
index e3c13935e..887f6f82e 100644
--- a/harper-core/src/linting/something_is.rs
+++ b/harper-core/src/linting/something_is.rs
@@ -31,7 +31,7 @@ impl ExprLinter for SomethingIs {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let offender = matched_tokens.first()?;
- let original = offender.span.get_content(source);
+ let original = offender.get_ch(source);
let stem_len = original.len().checked_sub(1)?;
let stem = original[..stem_len].to_vec();
diff --git a/harper-core/src/linting/split_words.rs b/harper-core/src/linting/split_words.rs
index ca458079f..df69afa49 100644
--- a/harper-core/src/linting/split_words.rs
+++ b/harper-core/src/linting/split_words.rs
@@ -46,7 +46,7 @@ impl ExprLinter for SplitWords {
return None;
}
- let chars = &word.span.get_content(source);
+ let chars = &word.get_ch(source);
// Get all possible prefix candidates from trie and extract valid split positions
let candidates = self.dict.find_words_with_common_prefix(chars);
diff --git a/harper-core/src/linting/subject_pronoun.rs b/harper-core/src/linting/subject_pronoun.rs
index 937cfa208..632ecce60 100644
--- a/harper-core/src/linting/subject_pronoun.rs
+++ b/harper-core/src/linting/subject_pronoun.rs
@@ -32,7 +32,7 @@ impl ExprLinter for SubjectPronoun {
let span = matched_tokens.span()?;
let mut suggestion_chars = Vec::new();
- suggestion_chars.extend_from_slice(matched_tokens.last()?.span.get_content(source));
+ suggestion_chars.extend_from_slice(matched_tokens.last()?.get_ch(source));
suggestion_chars.extend(" and I".chars());
Some(Lint {
@@ -50,7 +50,7 @@ impl ExprLinter for SubjectPronoun {
}
fn append_token_chars(chars: &mut Vec<char>, token: &Token, source: &[char]) {
- chars.extend(token.span.get_content(source).iter().copied());
+ chars.extend(token.get_ch(source).iter().copied());
}
fn append_tokens_chars(chars: &mut Vec<char>, tokens: &[Token], source: &[char]) {
diff --git a/harper-core/src/linting/take_a_look_to.rs b/harper-core/src/linting/take_a_look_to.rs
index 0c86851ac..60561f845 100644
--- a/harper-core/src/linting/take_a_look_to.rs
+++ b/harper-core/src/linting/take_a_look_to.rs
@@ -52,11 +52,10 @@ impl ExprLinter for TakeALookTo {
if followed_by_word(ctx, |nw| {
nw.kind.is_verb_lemma()
// Exception 1. Have/take a look to see if everything is ok
- || (nw.span.get_content(src).eq_ignore_ascii_case_str("it")
+ || (nw.get_ch(src).eq_str("it")
// Exception 2. It has a look to it that I don't like
&& toks.first().is_some_and(|tok| {
- tok.span
- .get_content(src)
+ tok.get_ch(src)
.eq_any_ignore_ascii_case_str(HAVE_FORMS)
}))
}) {
diff --git a/harper-core/src/linting/take_medicine.rs b/harper-core/src/linting/take_medicine.rs
index b1552f2ac..92df11111 100644
--- a/harper-core/src/linting/take_medicine.rs
+++ b/harper-core/src/linting/take_medicine.rs
@@ -66,10 +66,7 @@ fn replacement_for(
base
};
- Suggestion::replace_with_match_case(
- replacement.chars().collect(),
- verb.span.get_content(source),
- )
+ Suggestion::replace_with_match_case(replacement.chars().collect(), verb.get_ch(source))
}
impl ExprLinter for TakeMedicine {
diff --git a/harper-core/src/linting/that_than.rs b/harper-core/src/linting/that_than.rs
index 521d209de..b79c44bb2 100644
--- a/harper-core/src/linting/that_than.rs
+++ b/harper-core/src/linting/that_than.rs
@@ -46,7 +46,7 @@ impl ExprLinter for ThatThan {
lint_kind: LintKind::Typo,
suggestions: vec![Suggestion::replace_with_match_case_str(
"than",
- that_tok.span.get_content(src),
+ that_tok.get_ch(src),
)],
message: "This looks like a comparison that should use `than` rather than `that`."
.to_string(),
diff --git a/harper-core/src/linting/the_how_why.rs b/harper-core/src/linting/the_how_why.rs
index a402cfcbf..d53b7aeb7 100644
--- a/harper-core/src/linting/the_how_why.rs
+++ b/harper-core/src/linting/the_how_why.rs
@@ -69,7 +69,7 @@ impl ExprLinter for TheHowWhy {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let the_token_span = matched_tokens[0..2].span()?;
let question_word_token = matched_tokens.get(2)?;
- let question_word = question_word_token.span.get_content(source);
+ let question_word = question_word_token.get_ch(source);
Some(Lint {
span: the_token_span,
diff --git a/harper-core/src/linting/the_my.rs b/harper-core/src/linting/the_my.rs
index 1e58466cf..30689d05c 100644
--- a/harper-core/src/linting/the_my.rs
+++ b/harper-core/src/linting/the_my.rs
@@ -42,8 +42,8 @@ impl ExprLinter for TheMy {
let span = matched_tokens.span().unwrap();
let span_content = span.get_content(source);
- let first_word = matched_tokens[0].span.get_content(source);
- let second_word = matched_tokens[2].span.get_content(source);
+ let first_word = matched_tokens[0].get_ch(source);
+ let second_word = matched_tokens[2].get_ch(source);
let first_word_string: String = first_word.to_string();
diff --git a/harper-core/src/linting/the_point_for.rs b/harper-core/src/linting/the_point_for.rs
index b306b66ac..8c8e9fc00 100644
--- a/harper-core/src/linting/the_point_for.rs
+++ b/harper-core/src/linting/the_point_for.rs
@@ -47,10 +47,7 @@ impl ExprLinter for ThePointFor {
if let Some((_, after)) = ctx
&& after.len() >= 2
&& after[0].kind.is_whitespace()
- && after[1]
- .span
- .get_content(src)
- .eq_ignore_ascii_case_str("which")
+ && after[1].get_ch(src).eq_str("which")
{
return None;
}
diff --git a/harper-core/src/linting/the_proper_noun_possessive.rs b/harper-core/src/linting/the_proper_noun_possessive.rs
index 4d2b118ae..a87b978b9 100644
--- a/harper-core/src/linting/the_proper_noun_possessive.rs
+++ b/harper-core/src/linting/the_proper_noun_possessive.rs
@@ -20,8 +20,7 @@ impl Default for TheProperNounPossessive {
&& t.kind.is_titlecase()
&& !t.kind.is_lowercase()
&& !t
- .span
- .get_content(s)
+ .get_ch(s)
.eq_any_ignore_ascii_case_str(&["internet's", "internet’s"])
}),
}
diff --git a/harper-core/src/linting/then_than.rs b/harper-core/src/linting/then_than.rs
index ee2516c88..42741a239 100644
--- a/harper-core/src/linting/then_than.rs
+++ b/harper-core/src/linting/then_than.rs
@@ -56,8 +56,7 @@ impl ThenThan {
fn is_comparative(tok: &Token, source: &[char]) -> bool {
tok.kind.is_comparative_adjective()
|| tok
- .span
- .get_content(source)
+ .get_ch(source)
.eq_any_ignore_ascii_case_chars(&[&['l', 'e', 's', 's'], &['m', 'o', 'r', 'e']])
}
@@ -76,8 +75,7 @@ impl ExprLinter for ThenThan {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let mut thans_and_thens = matched_tokens.iter().filter(|tok| {
- tok.span
- .get_content(source)
+ tok.get_ch(source)
.eq_any_ignore_ascii_case_chars(&[&['t', 'h', 'a', 'n'], &['t', 'h', 'e', 'n']])
});
@@ -89,7 +87,7 @@ impl ExprLinter for ThenThan {
let offending_text = span.get_content(source);
- let new_text = if offending_text.eq_ignore_ascii_case_chars(&['t', 'h', 'e', 'n']) {
+ let new_text = if offending_text.eq_ch(&['t', 'h', 'e', 'n']) {
"than"
} else {
"then"
diff --git a/harper-core/src/linting/theses_these.rs b/harper-core/src/linting/theses_these.rs
index 6a49d664a..50b7ec20d 100644
--- a/harper-core/src/linting/theses_these.rs
+++ b/harper-core/src/linting/theses_these.rs
@@ -30,7 +30,7 @@ impl ExprLinter for ThesesThese {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let theses_token = matched_tokens.first()?;
- let content = theses_token.span.get_content(source);
+ let content = theses_token.get_ch(source);
let suggestions = vec![Suggestion::replace_with_match_case_str("these", content)];
diff --git a/harper-core/src/linting/theyre_confusions/mod.rs b/harper-core/src/linting/theyre_confusions/mod.rs
index 2a7317189..02ce70f9b 100644
--- a/harper-core/src/linting/theyre_confusions/mod.rs
+++ b/harper-core/src/linting/theyre_confusions/mod.rs
@@ -14,11 +14,7 @@ fn token_is_theyre(token: &Token, source: &[char]) -> bool {
return false;
}
- token
- .span
- .get_content(source)
- .normalized()
- .eq_ignore_ascii_case_str("they're")
+ token.get_ch(source).normalized().eq_str("they're")
}
fn token_is_typographic_theyre(token: &Token, source: &[char]) -> bool {
@@ -26,9 +22,8 @@ fn token_is_typographic_theyre(token: &Token, source: &[char]) -> bool {
return false;
}
- let content = token.span.get_content(source);
- content.iter().any(|c| c.normalized() != *c)
- && content.normalized().eq_ignore_ascii_case_str("they're")
+ let content = token.get_ch(source);
+ content.iter().any(|c| c.normalized() != *c) && content.normalized().eq_str("they're")
}
fn token_is_likely_their_possession(token: &Token, source: &[char]) -> bool {
@@ -36,7 +31,7 @@ fn token_is_likely_their_possession(token: &Token, source: &[char]) -> bool {
return false;
}
- let normalized = token.span.get_content(source).normalized();
+ let normalized = token.get_ch(source).normalized();
matches!(
normalized.as_ref(),
['b', 'a', 'c', 'k', 'p', 'a', 'c', 'k', 's']
diff --git a/harper-core/src/linting/theyre_confusions/over_theyre_to_there.rs b/harper-core/src/linting/theyre_confusions/over_theyre_to_there.rs
index 99e8103ff..218028f21 100644
--- a/harper-core/src/linting/theyre_confusions/over_theyre_to_there.rs
+++ b/harper-core/src/linting/theyre_confusions/over_theyre_to_there.rs
@@ -31,7 +31,7 @@ impl ExprLinter for OverTheyreToThere {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let offender = matched_tokens.last()?;
- let template = offender.span.get_content(source);
+ let template = offender.get_ch(source);
Some(Lint {
span: offender.span,
diff --git a/harper-core/src/linting/theyre_confusions/typographic_theyre_to_their.rs b/harper-core/src/linting/theyre_confusions/typographic_theyre_to_their.rs
index d2ce7a71b..e092d2ffc 100644
--- a/harper-core/src/linting/theyre_confusions/typographic_theyre_to_their.rs
+++ b/harper-core/src/linting/theyre_confusions/typographic_theyre_to_their.rs
@@ -31,7 +31,7 @@ impl ExprLinter for TypographicTheyreToTheir {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let offender = matched_tokens.first()?;
- let template = offender.span.get_content(source);
+ let template = offender.get_ch(source);
Some(Lint {
span: offender.span,
diff --git a/harper-core/src/linting/this_type_of_thing.rs b/harper-core/src/linting/this_type_of_thing.rs
index 9249000ce..62a4df21c 100644
--- a/harper-core/src/linting/this_type_of_thing.rs
+++ b/harper-core/src/linting/this_type_of_thing.rs
@@ -140,7 +140,7 @@ impl ExprLinter for ThisTypeOfThing {
}
.chars()
.collect(),
- bad_tok.span.get_content(src),
+ bad_tok.get_ch(src),
)],
message: "The grammatical number of the determiner and the two nouns must agree."
.to_string(),
diff --git a/harper-core/src/linting/though_thought.rs b/harper-core/src/linting/though_thought.rs
index 85775bcb7..42f1a0548 100644
--- a/harper-core/src/linting/though_thought.rs
+++ b/harper-core/src/linting/though_thought.rs
@@ -36,9 +36,7 @@ impl ExprLinter for ThoughThought {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let tok = find_the_only_token_matching(toks, src, |tok, src| {
- tok.span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['t', 'h', 'o', 'u', 'g', 'h'])
+ tok.get_ch(src).eq_ch(&['t', 'h', 'o', 'u', 'g', 'h'])
})?;
Some(Lint {
@@ -46,7 +44,7 @@ impl ExprLinter for ThoughThought {
lint_kind: LintKind::Typo,
suggestions: vec![Suggestion::replace_with_match_case_str(
"thought",
- tok.span.get_content(src),
+ tok.get_ch(src),
)],
message: "Is this a typo for `thought`?".to_string(),
..Default::default()
diff --git a/harper-core/src/linting/throw_away.rs b/harper-core/src/linting/throw_away.rs
index d0dd3d545..0792ce9b0 100644
--- a/harper-core/src/linting/throw_away.rs
+++ b/harper-core/src/linting/throw_away.rs
@@ -29,7 +29,7 @@ impl ExprLinter for ThrowAway {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let typo = matched_tokens.first()?;
- let original = typo.span.get_content(source);
+ let original = typo.get_ch(source);
Some(Lint {
span: typo.span,
diff --git a/harper-core/src/linting/to_two_too/to_too_adjective_end.rs b/harper-core/src/linting/to_two_too/to_too_adjective_end.rs
index 94104b226..846850f0d 100644
--- a/harper-core/src/linting/to_two_too/to_too_adjective_end.rs
+++ b/harper-core/src/linting/to_two_too/to_too_adjective_end.rs
@@ -42,11 +42,9 @@ impl ExprLinter for ToTooAdjectiveEnd {
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
// Find the `to` token
- let to_index = tokens.iter().position(|t| {
- t.span
- .get_content(source)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
- })?;
+ let to_index = tokens
+ .iter()
+ .position(|t| t.get_ch(source).eq_ch(&['t', 'o']))?;
// First non-whitespace after `to` should be the adjective
let mut idx = to_index + 1;
@@ -79,7 +77,7 @@ impl ExprLinter for ToTooAdjectiveEnd {
let should_lint = if j >= tokens.len() {
true
} else if tokens[j].kind.is_punctuation() {
- let punct: String = tokens[j].span.get_content(source).iter().collect();
+ let punct: String = tokens[j].get_ch(source).iter().collect();
!matches!(
punct.as_str(),
"`" | "\"" | "'" | "“" | "”" | "‘" | "’" | "-" | "–" | "—"
@@ -99,7 +97,7 @@ impl ExprLinter for ToTooAdjectiveEnd {
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
"too",
- to_tok.span.get_content(source),
+ to_tok.get_ch(source),
)],
message: "Use `too` here to mean ‘also’ or an excessive degree.".to_string(),
..Default::default()
diff --git a/harper-core/src/linting/to_two_too/to_too_adjective_punct.rs b/harper-core/src/linting/to_two_too/to_too_adjective_punct.rs
index 4267dc954..1df3f0e17 100644
--- a/harper-core/src/linting/to_two_too/to_too_adjective_punct.rs
+++ b/harper-core/src/linting/to_two_too/to_too_adjective_punct.rs
@@ -39,11 +39,9 @@ impl ExprLinter for ToTooAdjectivePunct {
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
- let to_index = tokens.iter().position(|t| {
- t.span
- .get_content(source)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
- })?;
+ let to_index = tokens
+ .iter()
+ .position(|t| t.get_ch(source).eq_ch(&['t', 'o']))?;
let mut idx = to_index + 1;
while idx < tokens.len() && tokens[idx].kind.is_whitespace() {
@@ -74,7 +72,7 @@ impl ExprLinter for ToTooAdjectivePunct {
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
"too",
- to_tok.span.get_content(source),
+ to_tok.get_ch(source),
)],
message: "Use `too` here to mean ‘also’ or an excessive degree.".to_string(),
..Default::default()
diff --git a/harper-core/src/linting/to_two_too/to_too_adjverb_ed_punct.rs b/harper-core/src/linting/to_two_too/to_too_adjverb_ed_punct.rs
index d313f9b59..55ebc8d3e 100644
--- a/harper-core/src/linting/to_two_too/to_too_adjverb_ed_punct.rs
+++ b/harper-core/src/linting/to_two_too/to_too_adjverb_ed_punct.rs
@@ -21,8 +21,7 @@ impl Default for ToTooAdjVerbEdPunct {
&& tok.kind.is_verb()
&& !tok.kind.is_noun()
&& tok
- .span
- .get_content(src)
+ .get_ch(src)
.ends_with_ignore_ascii_case_chars(&['e', 'd'])
})
.then_sentence_terminator();
@@ -41,18 +40,16 @@ impl ExprLinter for ToTooAdjVerbEdPunct {
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
- let to_tok = tokens.iter().find(|t| {
- t.span
- .get_content(source)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
- })?;
+ let to_tok = tokens
+ .iter()
+ .find(|t| t.get_ch(source).eq_ch(&['t', 'o']))?;
Some(Lint {
span: to_tok.span,
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
"too",
- to_tok.span.get_content(source),
+ to_tok.get_ch(source),
)],
message: "Use `too` here to mean ‘also’ or an excessive degree.".to_string(),
..Default::default()
diff --git a/harper-core/src/linting/to_two_too/to_too_adverb.rs b/harper-core/src/linting/to_two_too/to_too_adverb.rs
index 8398d127f..d87282356 100644
--- a/harper-core/src/linting/to_two_too/to_too_adverb.rs
+++ b/harper-core/src/linting/to_two_too/to_too_adverb.rs
@@ -42,18 +42,16 @@ impl ExprLinter for ToTooAdverb {
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
- let to_tok = tokens.iter().find(|t| {
- t.span
- .get_content(source)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
- })?;
+ let to_tok = tokens
+ .iter()
+ .find(|t| t.get_ch(source).eq_ch(&['t', 'o']))?;
Some(Lint {
span: to_tok.span,
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
"too",
- to_tok.span.get_content(source),
+ to_tok.get_ch(source),
)],
message: "Use `too` here to mean ‘also’ or an excessive degree.".to_string(),
..Default::default()
diff --git a/harper-core/src/linting/to_two_too/to_too_chunk_start_comma.rs b/harper-core/src/linting/to_two_too/to_too_chunk_start_comma.rs
index 5ab2aed70..9bd6f1a3f 100644
--- a/harper-core/src/linting/to_two_too/to_too_chunk_start_comma.rs
+++ b/harper-core/src/linting/to_two_too/to_too_chunk_start_comma.rs
@@ -33,18 +33,16 @@ impl ExprLinter for ToTooChunkStartComma {
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
- let to_tok = tokens.iter().find(|t| {
- t.span
- .get_content(source)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
- })?;
+ let to_tok = tokens
+ .iter()
+ .find(|t| t.get_ch(source).eq_ch(&['t', 'o']))?;
Some(Lint {
span: to_tok.span,
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
"too",
- to_tok.span.get_content(source),
+ to_tok.get_ch(source),
)],
message: "Use `too` here to mean ‘also’ or an excessive degree.".to_string(),
..Default::default()
diff --git a/harper-core/src/linting/to_two_too/to_too_degree_words.rs b/harper-core/src/linting/to_two_too/to_too_degree_words.rs
index 4ef98c677..d5bec98d5 100644
--- a/harper-core/src/linting/to_two_too/to_too_degree_words.rs
+++ b/harper-core/src/linting/to_two_too/to_too_degree_words.rs
@@ -42,18 +42,16 @@ impl ExprLinter for ToTooDegreeWords {
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
- let to_tok = tokens.iter().find(|t| {
- t.span
- .get_content(source)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
- })?;
+ let to_tok = tokens
+ .iter()
+ .find(|t| t.get_ch(source).eq_ch(&['t', 'o']))?;
Some(Lint {
span: to_tok.span,
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
"too",
- to_tok.span.get_content(source),
+ to_tok.get_ch(source),
)],
message: "Use `too` here to mean ‘also’ or an excessive degree.".to_string(),
..Default::default()
diff --git a/harper-core/src/linting/to_two_too/to_too_eos.rs b/harper-core/src/linting/to_two_too/to_too_eos.rs
index f26e61dcd..826a9c108 100644
--- a/harper-core/src/linting/to_two_too/to_too_eos.rs
+++ b/harper-core/src/linting/to_two_too/to_too_eos.rs
@@ -41,7 +41,7 @@ impl Linter for ToTooEos {
lint_kind: LintKind::Typo,
suggestions: vec![Suggestion::replace_with_match_case_str(
"too",
- tok.span.get_content(document.get_source()),
+ tok.get_ch(document.get_source()),
)],
message: "Use `too` when expressing similarity.".to_owned(),
priority: 63,
diff --git a/harper-core/src/linting/to_two_too/to_too_pronoun_end.rs b/harper-core/src/linting/to_two_too/to_too_pronoun_end.rs
index 1285a4f21..45a23e4e2 100644
--- a/harper-core/src/linting/to_two_too/to_too_pronoun_end.rs
+++ b/harper-core/src/linting/to_two_too/to_too_pronoun_end.rs
@@ -54,18 +54,16 @@ impl ExprLinter for ToTooPronounEnd {
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
- let to_tok = tokens.iter().find(|t| {
- t.span
- .get_content(source)
- .eq_ignore_ascii_case_chars(&['t', 'o'])
- })?;
+ let to_tok = tokens
+ .iter()
+ .find(|t| t.get_ch(source).eq_ch(&['t', 'o']))?;
Some(Lint {
span: to_tok.span,
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case_str(
"too",
- to_tok.span.get_content(source),
+ to_tok.get_ch(source),
)],
message: "Use `too` here to mean ‘also’ or an excessive degree.".to_string(),
..Default::default()
diff --git a/harper-core/src/linting/touristic.rs b/harper-core/src/linting/touristic.rs
index b60876116..6b99e70dd 100644
--- a/harper-core/src/linting/touristic.rs
+++ b/harper-core/src/linting/touristic.rs
@@ -108,7 +108,7 @@ impl ExprLinter for Touristic {
0
}
(3, true, false) => {
- let next_word = toks[2].span.get_content_string(src);
+ let next_word = toks[2].get_str(src);
let next_kind = &toks[2].kind;
if next_kind.is_noun() {
@@ -131,9 +131,9 @@ impl ExprLinter for Touristic {
2
}
(5, _, _) => {
- let _prev_word = toks[0].span.get_content_string(src).to_lowercase();
+ let _prev_word = toks[0].get_str(src).to_lowercase();
let prev_kind = &toks[0].kind;
- let next_word = toks[4].span.get_content_string(src).to_lowercase();
+ let next_word = toks[4].get_str(src).to_lowercase();
let next_kind = &toks[4].kind;
if prev_kind.is_adverb() {
diff --git a/harper-core/src/linting/transposed_space.rs b/harper-core/src/linting/transposed_space.rs
index 01a0ec9b3..cdc052c1e 100644
--- a/harper-core/src/linting/transposed_space.rs
+++ b/harper-core/src/linting/transposed_space.rs
@@ -54,8 +54,8 @@ impl<D: Dictionary + 'static> ExprLinter for TransposedSpace<D> {
let toks_span = toks.span()?;
// "thec" "at" / "th ecat"
- let word1 = toks.first()?.span.get_content(src);
- let word2 = toks.last()?.span.get_content(src);
+ let word1 = toks.first()?.get_ch(src);
+ let word2 = toks.last()?.get_ch(src);
// "thec" -> "the c"
let w1_start = &word1[..word1.len() - 1];
diff --git a/harper-core/src/linting/verb_to_adjective.rs b/harper-core/src/linting/verb_to_adjective.rs
index 558e41bb5..91b0af268 100644
--- a/harper-core/src/linting/verb_to_adjective.rs
+++ b/harper-core/src/linting/verb_to_adjective.rs
@@ -46,8 +46,8 @@ impl ExprLinter for VerbToAdjective {
suggestions: vec![],
message: format!(
"`{}` is an adverb. Before the noun `{}`, this phrase more likely needs an adjective.",
- adverb.span.get_content_string(source),
- noun.span.get_content_string(source),
+ adverb.get_str(source),
+ noun.get_str(source),
),
priority: 31,
})
diff --git a/harper-core/src/linting/very_unique.rs b/harper-core/src/linting/very_unique.rs
index adc2b2672..874f053db 100644
--- a/harper-core/src/linting/very_unique.rs
+++ b/harper-core/src/linting/very_unique.rs
@@ -32,7 +32,7 @@ impl ExprLinter for VeryUnique {
let very_unique_span = toks.span()?;
let very_unique_chars = very_unique_span.get_content(src);
let qualifier_tok = &toks.first()?;
- let qualifier_str = qualifier_tok.span.get_content_string(src);
+ let qualifier_str = qualifier_tok.get_str(src);
let adjectives = ["special", "rare", "unusual"];
diff --git a/harper-core/src/linting/vicious_loop/mod.rs b/harper-core/src/linting/vicious_loop/mod.rs
index fa7e09320..8b9dddc7a 100644
--- a/harper-core/src/linting/vicious_loop/mod.rs
+++ b/harper-core/src/linting/vicious_loop/mod.rs
@@ -56,23 +56,20 @@ fn to_lint(toks: &[Token], src: &[char], pref: Prefer) -> Option<Lint> {
let (adjtok, nountok) = (toks.first()?, toks.last()?);
let badadj = adjtok
- .span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['v', 'i', 's', 'c', 'o', 'u', 's']);
+ .get_ch(src)
+ .eq_ch(&['v', 'i', 's', 'c', 'o', 'u', 's']);
let badnoun = match pref {
Prefer::Circle => nountok
- .span
- .get_content(src)
+ .get_ch(src)
.starts_with_ignore_ascii_case_str("cycle"),
Prefer::Cycle => nountok
- .span
- .get_content(src)
+ .get_ch(src)
.starts_with_ignore_ascii_case_str("circle"),
Prefer::DontCare => false,
};
- let is_plural = matches!(nountok.span.get_content(src).last(), Some('s' | 'S'));
+ let is_plural = matches!(nountok.get_ch(src).last(), Some('s' | 'S'));
// The noun doesn't match the user's preferred word.
if badnoun && !badadj {
@@ -87,7 +84,7 @@ fn to_lint(toks: &[Token], src: &[char], pref: Prefer) -> Option<Lint> {
(Prefer::Cycle, true) => "cycles",
_ => unreachable!(),
},
- nountok.span.get_content(src),
+ nountok.get_ch(src),
)],
message: if pref == Prefer::Circle {
"This idiom originally used `circle`, not `cycle`".to_string()
@@ -138,7 +135,7 @@ fn to_lint(toks: &[Token], src: &[char], pref: Prefer) -> Option<Lint> {
lint_kind: LintKind::Usage,
suggestions: vec![Suggestion::replace_with_match_case_str(
"vicious",
- adjtok.span.get_content(src),
+ adjtok.get_ch(src),
)],
message:
"The idiom uses the word `vicious`, not `viscous`, which describes thick liquids."
diff --git a/harper-core/src/linting/was_aloud.rs b/harper-core/src/linting/was_aloud.rs
index 960aafbbd..51d97ee8c 100644
--- a/harper-core/src/linting/was_aloud.rs
+++ b/harper-core/src/linting/was_aloud.rs
@@ -28,14 +28,14 @@ impl ExprLinter for WasAloud {
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let verb = matched_tokens[0].span.get_content_string(source);
+ let verb = matched_tokens[0].get_str(source);
Some(Lint {
span: matched_tokens.span()?,
lint_kind: LintKind::WordChoice,
suggestions: vec![Suggestion::replace_with_match_case(
format!("{verb} allowed").chars().collect(),
- matched_tokens[0].span.get_content(source),
+ matched_tokens[0].get_ch(source),
)],
message: format!("Did you mean `{verb} allowed`?"),
priority: 31,
diff --git a/harper-core/src/linting/were_where.rs b/harper-core/src/linting/were_where.rs
index 922c3bf42..00faca5e4 100644
--- a/harper-core/src/linting/were_where.rs
+++ b/harper-core/src/linting/were_where.rs
@@ -72,14 +72,12 @@ impl ExprLinter for WereWhere {
// Check if "where" appears in the match (where → were case)
let where_tok = toks.iter().find(|tok| {
- matches!(tok.kind, TokenKind::Word(_))
- && tok.span.get_content(src).eq_ignore_ascii_case_chars(WHERE)
+ matches!(tok.kind, TokenKind::Word(_)) && tok.span.get_content(src).eq_ch(WHERE)
});
// Check if "were" appears in the match (were → where case)
let were_tok = toks.iter().find(|tok| {
- matches!(tok.kind, TokenKind::Word(_))
- && tok.span.get_content(src).eq_ignore_ascii_case_chars(WERE)
+ matches!(tok.kind, TokenKind::Word(_)) && tok.span.get_content(src).eq_ch(WERE)
});
if let Some(tok) = where_tok {
diff --git a/harper-core/src/linting/whom_subject_of_verb.rs b/harper-core/src/linting/whom_subject_of_verb.rs
index f52dd9c4e..fc2bfc15f 100644
--- a/harper-core/src/linting/whom_subject_of_verb.rs
+++ b/harper-core/src/linting/whom_subject_of_verb.rs
@@ -45,12 +45,9 @@ impl ExprLinter for WhomSubjectOfVerb {
if let Some((before, _)) = ctx
&& let [.., word, ws1, prep, ws2] = before
&& ws2.kind.is_whitespace()
- && prep
- .span
- .get_content(src)
- .eq_ignore_ascii_case_chars(&['o', 'f'])
+ && prep.get_ch(src).eq_ch(&['o', 'f'])
&& ws1.kind.is_whitespace()
- && word.span.get_content(src).eq_ignore_ascii_case_str("many")
+ && word.get_ch(src).eq_str("many")
{
return None;
}
diff --git a/harper-core/src/linting/widely_accepted.rs b/harper-core/src/linting/widely_accepted.rs
index cf43a7bbd..ca6829782 100644
--- a/harper-core/src/linting/widely_accepted.rs
+++ b/harper-core/src/linting/widely_accepted.rs
@@ -31,7 +31,7 @@ impl ExprLinter for WidelyAccepted {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
// We only need to replace the `wide` token with `widely`.
let wide_token = matched_tokens.first()?;
- let wide_chars = wide_token.span.get_content(source);
+ let wide_chars = wide_token.get_ch(source);
Some(Lint {
span: wide_token.span,
diff --git a/harper-core/src/linting/win_prize.rs b/harper-core/src/linting/win_prize.rs
index 07558ab31..3851d5b09 100644
--- a/harper-core/src/linting/win_prize.rs
+++ b/harper-core/src/linting/win_prize.rs
@@ -36,7 +36,7 @@ impl ExprLinter for WinPrize {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let candidate = toks.last()?;
- let raw = candidate.span.get_content_string(src).to_lowercase();
+ let raw = candidate.get_str(src).to_lowercase();
let repl = match raw.as_str() {
"price" | "prise" => "prize",
"prices" | "prises" => "prizes",
diff --git a/harper-core/src/linting/would_never_have.rs b/harper-core/src/linting/would_never_have.rs
index e254e9f9a..2b88d3d52 100644
--- a/harper-core/src/linting/would_never_have.rs
+++ b/harper-core/src/linting/would_never_have.rs
@@ -44,8 +44,8 @@ impl ExprLinter for WouldNeverHave {
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
let modal_have_toks = toks.first()?;
- let modal_have_chars = modal_have_toks.span.get_content(src);
- let modal_have_str = modal_have_toks.span.get_content_string(src).to_lowercase();
+ let modal_have_chars = modal_have_toks.get_ch(src);
+ let modal_have_str = modal_have_toks.get_str(src).to_lowercase();
let modal = if modal_have_str.starts_with("could") {
"could"
diff --git a/harper-core/src/linting/wrong_apostrophe.rs b/harper-core/src/linting/wrong_apostrophe.rs
index 4a5ba455c..a1170f469 100644
--- a/harper-core/src/linting/wrong_apostrophe.rs
+++ b/harper-core/src/linting/wrong_apostrophe.rs
@@ -43,12 +43,11 @@ impl ExprLinter for WrongApostrophe {
let replacement_str = format!(
"{}'{}",
- base.span.get_content_string(src).to_lowercase(),
- ending.span.get_content_string(src).to_lowercase()
+ base.get_str(src).to_lowercase(),
+ ending.get_str(src).to_lowercase()
);
- let lettercase_template =
- [base.span.get_content(src), ending.span.get_content(src)].concat();
+ let lettercase_template = [base.get_ch(src), ending.get_ch(src)].concat();
Some(Lint {
span: whole_span,
diff --git a/harper-core/src/patterns/derived_from.rs b/harper-core/src/patterns/derived_from.rs
index f1d818665..bb1d0ac93 100644
--- a/harper-core/src/patterns/derived_from.rs
+++ b/harper-core/src/patterns/derived_from.rs
@@ -33,7 +33,7 @@ impl Pattern for DerivedFrom {
return Some(1);
}
- let chars = tok.span.get_content(source);
+ let chars = tok.get_ch(source);
let word_id = WordId::from_word_chars(chars);
if word_id == self.word_id {
diff --git a/harper-core/src/patterns/implies_quantity.rs b/harper-core/src/patterns/implies_quantity.rs
index ccb232eb6..81485af29 100644
--- a/harper-core/src/patterns/implies_quantity.rs
+++ b/harper-core/src/patterns/implies_quantity.rs
@@ -18,7 +18,7 @@ impl ImpliesQuantity {
return Some(false);
}
- let source = token.span.get_content(source);
+ let source = token.get_ch(source);
match source {
['a'] => Some(false),
diff --git a/harper-core/src/patterns/within_edit_distance.rs b/harper-core/src/patterns/within_edit_distance.rs
index 967af45fa..7bd4ff178 100644
--- a/harper-core/src/patterns/within_edit_distance.rs
+++ b/harper-core/src/patterns/within_edit_distance.rs
@@ -37,7 +37,7 @@ impl SingleTokenPattern for WithinEditDistance {
return false;
}
- let content = token.span.get_content(source);
+ let content = token.get_ch(source);
BUFFERS.with_borrow_mut(|(buffer_a, buffer_b)| {
let distance = edit_distance_min_alloc(
diff --git a/harper-core/src/patterns/word.rs b/harper-core/src/patterns/word.rs
index 7dd242606..b20caf7e3 100644
--- a/harper-core/src/patterns/word.rs
+++ b/harper-core/src/patterns/word.rs
@@ -54,7 +54,7 @@ impl SingleTokenPattern for Word {
return false;
}
- let chars = token.span.get_content(source);
+ let chars = token.get_ch(source);
if self.case_sensitive {
chars == self.word.as_slice()
} else {
diff --git a/harper-core/src/patterns/word_set.rs b/harper-core/src/patterns/word_set.rs
index bf61ca0f4..e4c341046 100644
--- a/harper-core/src/patterns/word_set.rs
+++ b/harper-core/src/patterns/word_set.rs
@@ -49,7 +49,7 @@ impl SingleTokenPattern for WordSet {
return false;
}
- let tok_chars = token.span.get_content(source);
+ let tok_chars = token.get_ch(source);
for word in &self.words {
if tok_chars.len() != word.len() {
diff --git a/harper-core/src/title_case.rs b/harper-core/src/title_case.rs
index bd6be67b4..925800803 100644
--- a/harper-core/src/title_case.rs
+++ b/harper-core/src/title_case.rs
@@ -61,17 +61,13 @@ pub fn try_make_title_case(
while let Some(word_idx) = word_likes.next() {
let word = &toks[word_idx];
- let is_alphabetic_word = word
- .span
- .get_content(source)
- .iter()
- .any(|c| c.is_alphabetic());
+ let is_alphabetic_word = word.get_ch(source).iter().any(|c| c.is_alphabetic());
if let Some(Some(metadata)) = word.kind.as_word()
&& metadata.is_proper_noun()
{
// Replace it with the dictionary entry verbatim.
- let orig_text = word.span.get_content(source);
+ let orig_text = word.get_ch(source);
if let Some(correct_caps) = dict.get_correct_capitalization_of(orig_text) {
// It should match the dictionary verbatim
@@ -149,7 +145,7 @@ fn should_capitalize_token(tok: &Token, source: &[char]) -> bool {
.collect()
});
- let chars = tok.span.get_content(source);
+ let chars = tok.get_ch(source);
let chars_lower = chars.to_lower();
let metadata = Cow::Borrowed(metadata);
diff --git a/harper-core/src/token.rs b/harper-core/src/token.rs
index 8b30d2440..7883760d4 100644
--- a/harper-core/src/token.rs
+++ b/harper-core/src/token.rs
@@ -16,9 +16,19 @@ impl Token {
Self { span, kind }
}
+ /// Get the token's content as a slice of characters.
+ pub fn get_ch<'a>(&self, source: &'a [char]) -> &'a [char] {
+ self.span.get_content(source)
+ }
+
+ /// Get the token's content as a string.
+ pub fn get_str(&self, source: &[char]) -> String {
+ self.span.get_content_string(source)
+ }
+
/// Convert to an allocated [`FatToken`].
pub fn to_fat(&self, source: &[char]) -> FatToken {
- let content = self.span.get_content(source).to_vec();
+ let content = self.get_ch(source).to_vec();
FatToken {
content,
diff --git a/harper-core/src/token_string_ext.rs b/harper-core/src/token_string_ext.rs
index c42cf523e..2076da811 100644
--- a/harper-core/src/token_string_ext.rs
+++ b/harper-core/src/token_string_ext.rs
@@ -98,10 +98,10 @@ pub trait TokenStringExt: private::Sealed {
/// # fn main() {
/// let source = "The cat sat on the mat.".chars().collect::<Vec<_>>();
/// let tokens = PlainEnglish.parse(&source);
- /// assert_eq!(tokens.get_rel(0).unwrap().span.get_content_string(&source), "The");
+ /// assert_eq!(tokens.get_rel(0).unwrap().get_str(&source), "The");
/// assert_eq!(tokens.get_rel(1).unwrap().kind.is_whitespace(), true);
/// assert_eq!(tokens.get_rel(-1).unwrap().kind.is_punctuation(), true);
- /// assert_eq!(tokens.get_rel(-2).unwrap().span.get_content_string(&source), "mat");
+ /// assert_eq!(tokens.get_rel(-2).unwrap().get_str(&source), "mat");
/// # }
/// ```
///
diff --git a/harper-core/src/weir/parsing/expr.rs b/harper-core/src/weir/parsing/expr.rs
index 642d83863..6023ae4f2 100644
--- a/harper-core/src/weir/parsing/expr.rs
+++ b/harper-core/src/weir/parsing/expr.rs
@@ -50,21 +50,21 @@ fn parse_single_expr(tokens: &[Token], source: &[char]) -> Result<FoundNode<AstE
// The expr ref notation
TokenKind::Punctuation(Punctuation::At) => {
let name_tok = tokens.get(1).ok_or(Error::EndOfInput)?;
- let name = name_tok.span.get_content(source);
+ let name = name_tok.get_ch(source);
Ok(FoundNode::new(AstExprNode::ExprRef(name.into()), 2))
}
// The derivation notation.
TokenKind::Punctuation(Punctuation::Currency(Currency::Dollar)) => {
let word_tok = tokens.get(1).ok_or(Error::EndOfInput)?;
- let word = word_tok.span.get_content(source);
+ let word = word_tok.get_ch(source);
Ok(FoundNode::new(AstExprNode::DerivativeOf(word.into()), 2))
}
TokenKind::Punctuation(Punctuation::Star) => {
Ok(FoundNode::new(AstExprNode::Anything, 1))
}
TokenKind::Word(_) => {
- let text = tok.span.get_content_string(source);
+ let text = tok.get_str(source);
if let Ok(upos) = UPOS::from_str(&text){
Ok(FoundNode::new(
@@ -126,7 +126,7 @@ fn parse_single_expr(tokens: &[Token], source: &[char]) -> Result<FoundNode<AstE
}
TokenKind::Punctuation(p) => Ok(FoundNode::new(AstExprNode::Punctuation(p), 1)),
- _ => Err(Error::UnsupportedToken(tok.span.get_content_string(source))),
+ _ => Err(Error::UnsupportedToken(tok.get_str(source))),
}
}
diff --git a/harper-core/src/weir/parsing/mod.rs b/harper-core/src/weir/parsing/mod.rs
index 2be8b9bd7..9bac19621 100644
--- a/harper-core/src/weir/parsing/mod.rs
+++ b/harper-core/src/weir/parsing/mod.rs
@@ -131,9 +131,7 @@ fn expected_space(cursor: usize, tokens: &[Token], source: &[char]) -> Result<()
let expected_space = &tokens[cursor];
if !expected_space.kind.is_space() {
- return Err(Error::UnexpectedToken(
- expected_space.span.get_content_string(source),
- ));
+ return Err(Error::UnexpectedToken(expected_space.get_str(source)));
}
Ok(())
diff --git a/harper-core/src/weir/parsing/stmt.rs b/harper-core/src/weir/parsing/stmt.rs
index 96648997c..db300205a 100644
--- a/harper-core/src/weir/parsing/stmt.rs
+++ b/harper-core/src/weir/parsing/stmt.rs
@@ -100,12 +100,12 @@ fn parse_stmt(tokens: &[Token], source: &[char]) -> Result<FoundNode<Option<AstS
Ok(FoundNode::new(Some(AstStmtNode::Comment(comment)), end + 1))
}
TokenKind::Word(_) => {
- let word_literal = key_token.span.get_content(source);
+ let word_literal = key_token.get_ch(source);
match word_literal {
['l', 'e', 't'] => {
expected_space(cursor + 1, tokens, source)?;
- let name = tokens[cursor + 2].span.get_content_string(source);
+ let name = tokens[cursor + 2].get_str(source);
expected_space(cursor + 3, tokens, source)?;
let str_res = parse_quoted_string(&tokens[cursor + 4..end], source);
@@ -132,9 +132,7 @@ fn parse_stmt(tokens: &[Token], source: &[char]) -> Result<FoundNode<Option<AstS
} else {
let open_brac_tok = &tokens[cursor + 4];
if !open_brac_tok.kind.is_open_square() {
- return Err(Error::UnexpectedToken(
- open_brac_tok.span.get_content_string(source),
- ));
+ return Err(Error::UnexpectedToken(open_brac_tok.get_str(source)));
}
let matching = locate_matching_brace(
@@ -168,7 +166,7 @@ fn parse_stmt(tokens: &[Token], source: &[char]) -> Result<FoundNode<Option<AstS
Ok(FoundNode::new(
Some(AstStmtNode::create_set_expr(
- tokens[cursor + 2].span.get_content_string(source),
+ tokens[cursor + 2].get_str(source),
AstExprNode::Seq(parse_seq(
&tokens[(cursor + 4).min(end)..end],
source,
@@ -182,9 +180,7 @@ fn parse_stmt(tokens: &[Token], source: &[char]) -> Result<FoundNode<Option<AstS
cursor += 1 + case.next_idx;
if cursor != end {
- return Err(Error::UnexpectedToken(
- tokens[cursor].span.get_content_string(source),
- ));
+ return Err(Error::UnexpectedToken(tokens[cursor].get_str(source)));
}
Ok(FoundNode::new(
@@ -202,9 +198,7 @@ fn parse_stmt(tokens: &[Token], source: &[char]) -> Result<FoundNode<Option<AstS
cursor += 1 + sol.next_idx;
if cursor != end {
- return Err(Error::UnexpectedToken(
- tokens[cursor].span.get_content_string(source),
- ));
+ return Err(Error::UnexpectedToken(tokens[cursor].get_str(source)));
}
Ok(FoundNode::new(
@@ -215,9 +209,7 @@ fn parse_stmt(tokens: &[Token], source: &[char]) -> Result<FoundNode<Option<AstS
_ => Err(Error::UnexpectedToken(word_literal.to_string())),
}
}
- _ => Err(Error::UnsupportedToken(
- key_token.span.get_content_string(source),
- )),
+ _ => Err(Error::UnsupportedToken(key_token.get_str(source))),
}
}
@@ -241,9 +233,7 @@ fn parse_quoted_string(tokens: &[Token], source: &[char]) -> Result<FoundNode<St
let quote_tok = tokens.get(cursor).ok_or(Error::EndOfInput)?;
if !quote_tok.kind.is_quote() {
- return Err(Error::UnexpectedToken(
- quote_tok.span.get_content_string(source),
- ));
+ return Err(Error::UnexpectedToken(quote_tok.get_str(source)));
}
let mut end = None;
diff --git a/harper-ls/src/diagnostics.rs b/harper-ls/src/diagnostics.rs
index a71f776de..2fa78287f 100644
--- a/harper-ls/src/diagnostics.rs
+++ b/harper-ls/src/diagnostics.rs
@@ -45,11 +45,9 @@ pub fn lint_to_code_actions<'a>(
let replace_string = match suggestion {
Suggestion::ReplaceWith(with) => with.iter().collect(),
Suggestion::Remove => "".to_string(),
- Suggestion::InsertAfter(with) => format!(
- "{}{}",
- lint.span.get_content_string(source),
- with.to_string()
- ),
+ Suggestion::InsertAfter(with) => {
+ format!("{}{}", lint.get_str(source), with.to_string())
+ }
};
Some(CodeAction {
@@ -92,7 +90,7 @@ pub fn lint_to_code_actions<'a>(
}));
if lint.lint_kind.is_spelling() {
- let orig = lint.span.get_content_string(source);
+ let orig = lint.get_str(source);
results.push(CodeActionOrCommand::Command(Command::new(
format!("Add \"{orig}\" to the user dictionary."),
diff --git a/harper-tex/src/masker.rs b/harper-tex/src/masker.rs
index e0697f60e..70f58c1cc 100644
--- a/harper-tex/src/masker.rs
+++ b/harper-tex/src/masker.rs
@@ -127,9 +127,7 @@ fn equation_at_cursor(cursor: usize, source: &[char]) -> Option<usize> {
curly_content,
} = deconstruct_command(&source[cursor..])?;
- if name.eq_ignore_ascii_case_str("begin")
- && curly_content.is_some_and(|cc| cc.eq_ignore_ascii_case_str("equation"))
- {
+ if name.eq_str("begin") && curly_content.is_some_and(|cc| cc.eq_str("equation")) {
let mut diff = 1
+ name.len()
+ curly_content.unwrap().len()
@@ -141,8 +139,8 @@ fn equation_at_cursor(cursor: usize, source: &[char]) -> Option<usize> {
curly_content,
..
}) = deconstruct_command(&source[cursor + diff..])
- && name.eq_ignore_ascii_case_str("end")
- && curly_content.is_some_and(|cc| cc.eq_ignore_ascii_case_str("equation"))
+ && name.eq_str("end")
+ && curly_content.is_some_and(|cc| cc.eq_str("equation"))
{
break;
}
diff --git a/harper-typst/tests/tests.rs b/harper-typst/tests/tests.rs
index 781c86eaf..fd24cd1e0 100644
--- a/harper-typst/tests/tests.rs
+++ b/harper-typst/tests/tests.rs
@@ -84,7 +84,7 @@ fn dict_parsing() {
let charslice = source.chars().collect_vec();
let tokens = document.tokens().collect_vec();
- assert_eq!(tokens[2].span.get_content_string(&charslice), "Typst");
+ assert_eq!(tokens[2].get_str(&charslice), "Typst");
assert!(matches!(
token_kinds.as_slice(),
@@ -157,8 +157,8 @@ fn header_parsing() {
let charslice = source.chars().collect_vec();
let tokens = document.tokens().collect_vec();
- assert_eq!(tokens[0].span.get_content_string(&charslice), "Header");
- assert_eq!(tokens[2].span.get_content_string(&charslice), "Paragraph");
+ assert_eq!(tokens[0].get_str(&charslice), "Header");
+ assert_eq!(tokens[2].get_str(&charslice), "Paragraph");
assert!(matches!(
&token_kinds.as_slice(),
@@ -257,7 +257,7 @@ fn smart_apostrophe_newline() {
let charslice = source.chars().collect_vec();
let tokens = document.tokens().collect_vec();
- assert_eq!(tokens[2].span.get_content_string(&charslice), "writing");
+ assert_eq!(tokens[2].get_str(&charslice), "writing");
assert!(matches!(
token_kinds.as_slice(),
diff --git a/harper-wasm/src/lib.rs b/harper-wasm/src/lib.rs
index 589dbabf5..fb4b3bb6a 100644
--- a/harper-wasm/src/lib.rs
+++ b/harper-wasm/src/lib.rs
@@ -324,7 +324,7 @@ impl Linter {
lints: ls
.into_iter()
.map(|l| {
- let problem_text = l.span.get_content_string(&source);
+ let problem_text = l.get_str(&source);
let span = Into::<Span>::into(l.span).to_js_indices(source.as_slice());
Lint::new(l, span, problem_text, language)
@@ -377,7 +377,7 @@ impl Linter {
lints
.into_iter()
.map(|l| {
- let problem_text = l.span.get_content_string(&source);
+ let problem_text = l.get_str(&source);
let span = Into::<Span>::into(l.span).to_js_indices(source.as_slice());
Lint::new(l, span, problem_text, language)
})