Skip to content

Commit

Permalink
checker: Remove assumptions about Stem type alias
Browse files Browse the repository at this point in the history
This is a style refactor that should make it easier to change the
underlying type of `Stem` should we want to optimize it in the future.
  • Loading branch information
the-mikedavis committed Nov 1, 2024
1 parent 5093ad6 commit 9fc1500
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/aff/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ pub(crate) fn parse<'aff, 'dic, S: BuildHasher + Clone>(
.map_err(|err| lines.error(ParseDictionaryErrorKind::MalformedFlag(err)))?;
// Normalize out Pascal and Camel cases (and uppercase when there are no flags) by
// converting them to titlecase and setting the hidden homonym flag.
let casing = crate::classify_casing(&word);
let casing = crate::classify_casing(word.as_ref());
if (matches!(casing, Casing::Pascal | Casing::Camel)
&& !cx
.options
.forbidden_word_flag
.is_some_and(|flag| flagset.contains(&flag)))
|| (matches!(casing, Casing::All) && !flagset.is_empty())
{
let word = cx.options.case_handling.titlecase(&word).into();
let word = cx.options.case_handling.titlecase(word.as_ref()).into();
words.insert(word, flagset.with_flag(HIDDEN_HOMONYM_FLAG));
}
words.insert(word, flagset);
Expand Down Expand Up @@ -1262,7 +1262,7 @@ pub(crate) fn parse_dic_line(
s.chars()
.filter(|ch| !ignore.contains(ch))
.collect::<String>()
.into_boxed_str()
.into()
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
AffData, Affix, AffixKind, CompoundPattern, Pfx, Prefix, Sfx, Suffix, HIDDEN_HOMONYM_FLAG,
},
alloc::{string::String, vec::Vec},
classify_casing, erase_chars, AffixingMode, Casing, Dictionary, Flag, FlagSet, WordList,
classify_casing, erase_chars, AffixingMode, Casing, Dictionary, Flag, FlagSet, Stem, WordList,
AT_COMPOUND_BEGIN, AT_COMPOUND_END, AT_COMPOUND_MIDDLE, FULL_WORD, MAX_WORD_LEN,
};

Expand Down Expand Up @@ -1542,7 +1542,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
part1_entry,
);
}
let part2_word = part2_entry.stem;
let part2_word = part2_entry.stem.as_ref();
// TODO: do we need a bounds check? Use starts_with on the subslice of `&word[i..]`
// instead?
if &word[i..i + part2_word.len()] == part2_word
Expand Down Expand Up @@ -1703,7 +1703,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
return None;
}

let part2_word = part2_entry.stem;
let part2_word = part2_entry.stem.as_ref();
// TODO: do we need a bounds check? Use starts_with on the subslice of `&word[i..]`
// instead?
if &word[i..i + part2_word.len()] == part2_word
Expand Down Expand Up @@ -2252,7 +2252,7 @@ impl HiddenHomonym {
// Similar to Nuspell's AffixingResult
#[derive(Debug)]
pub(crate) struct AffixForm<'aff> {
stem: &'aff str,
stem: &'aff Stem,
flags: &'aff FlagSet,
// Up to 2 prefixes and/or 2 suffixes allowed.
prefixes: [Option<&'aff Prefix>; 2],
Expand All @@ -2262,15 +2262,15 @@ pub(crate) struct AffixForm<'aff> {
// TODO: docs.
#[derive(Debug, PartialEq, Eq)]
pub(crate) struct CompoundingResult<'aff> {
stem: &'aff str,
stem: &'aff Stem,
flags: &'aff FlagSet,
num_words_modifier: u16,
num_syllable_modifier: i16,
affixed_and_modified: bool,
}

impl<'aff> CompoundingResult<'aff> {
pub fn new(stem: &'aff str, flags: &'aff FlagSet) -> Self {
pub fn new(stem: &'aff Stem, flags: &'aff FlagSet) -> Self {
Self {
stem,
flags,
Expand Down

0 comments on commit 9fc1500

Please sign in to comment.