Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

implement improved camel case #630

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b1c604e
implement improved camel case
feckertson Dec 18, 2022
91fc096
correct build failure
Dec 19, 2022
ccb33db
set CheckInfo in check_camel
feckertson Dec 24, 2022
18c2459
attempt to fix build_jessie failure
feckertson Dec 24, 2022
f2692a6
try two
feckertson Dec 24, 2022
04fa8f8
undo last experimental change
feckertson Dec 25, 2022
35837d5
let check_runtogether handle single words
feckertson Dec 27, 2022
a7e017e
revert to original check_runtoether logic if check_camel does not ret…
feckertson Dec 27, 2022
359833d
add unit test for improved camel case
feckertson Dec 29, 2022
98ca011
address review comment
feckertson Dec 30, 2022
c3e2c81
address review comment
feckertson Dec 30, 2022
6a22344
address review comment
feckertson Dec 30, 2022
3aa7e4d
address review comment
feckertson Dec 30, 2022
63a7cd9
address review comment
feckertson Dec 30, 2022
0c919d6
address review comment
feckertson Dec 31, 2022
eaa1733
address review comment
feckertson Dec 31, 2022
aec924a
address review comment
feckertson Dec 31, 2022
a2fba21
address review comment
feckertson Dec 31, 2022
1044d2f
address review comment
feckertson Dec 31, 2022
66f3e34
address review comment
feckertson Dec 31, 2022
58051cd
address review comment
feckertson Dec 31, 2022
cae6a1f
address review comment
feckertson Dec 31, 2022
4f4d55f
attempt to get a successful build
feckertson Jun 14, 2023
7cbc00b
that didn't work. trying something else
feckertson Jun 14, 2023
9f5121e
try three
feckertson Jun 14, 2023
6123afb
let's try something else
feckertson Jun 14, 2023
0beda3c
back to the way it was
feckertson Jun 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 46 additions & 35 deletions modules/speller/default/speller_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,64 @@ namespace aspeller {
return NULL;
}


/**
Returns false if camel case checking is not enabled.
Otherwise returns true when the provided string is acceptable camel case and false when not.
*/
bool SpellerImpl::check_camel(const char * str, size_t len, CheckInfo & ci) {
if(!camel_case_) {
return false;
}

CompoundWord cw = lang_->split_word(str, len, true);
WordEntry we;
bool notSingle = false;
do {
size_t sz = cw.word_len();
char word[sz+1];
memcpy(word, cw.word, sz);
word[sz] = '\0';
if (!check_simple(word, we)) {
return false;
}
cw = lang_->split_word(cw.rest, cw.rest_len(), true);
if (cw.word_len()) {
notSingle = true;
}
} while (!cw.empty());
if (notSingle) {
ci.word = str;
ci.compound = true;
return true;
}
return false;
}


PosibErr<bool> SpellerImpl::check(char * word, char * word_end,
/* it WILL modify word */
bool try_uppercase,
unsigned run_together_limit,
CheckInfo * ci, CheckInfo * ci_end,
GuessInfo * gi, CompoundInfo * cpi)
{
clear_check_info(*ci);
if (check_camel(word, word_end - word, *ci)) {
return true;
}

clear_check_info(*ci);
bool res = check_runtogether(word, word_end, try_uppercase, run_together_limit, ci, ci_end, gi);
if (res) return true;

CompoundWord cw = lang_->split_word(word, word_end - word, camel_case_);
if (cw.single()) return false;
bool ok = true;
CheckInfo * ci_prev = NULL;
do {
unsigned len = cw.word_len();

char save = word[len];
word[len] = '\0';
CheckInfo * ci_last = check_runtogether(word, word + len, try_uppercase, run_together_limit, ci, ci_end, gi);
Expand All @@ -255,7 +295,7 @@ namespace aspeller {

if (cpi)
cpi->count++;

if (ci_prev) {
ci_prev->compound = true;
ci_prev->next = ci;
Expand All @@ -267,42 +307,13 @@ namespace aspeller {
if (cpi) cpi->count = 0;
return false;
}

word = word + cw.rest_offset();
cw = lang_->split_word(cw.rest, cw.rest_len(), camel_case_);

} while (!cw.empty());

return ok;

// for (;;) {
// cw = lang_->split_word(cw.rest, cw.rest_len(), camel_case_);
// if (cw.empty()) break;
// if (ci + 1 >= ci_end) {
// if (cpi) cpi->count = 0;
// return false;
// }
// if (cpi) cpi->count++;
// len = cw.word_len();
// save = word[len];
// word[len] = '\0';
// ci_last = check_runtogether(word, word + len, try_uppercase, run_together_limit, ci + 1, ci_end, gi);
// word[len] = save;
// ci->compound = true;
// ci->next = ci + 1;
// if (ci_last) {
// ci = ci_last;
// } else if (cpi) {
// ok = false;
// ci->word.str = word;
// ci->word.len = len;
// ci->incorrect = true;
// cpi->incorrect_count++;
// } else {
// return false;
// }
// word = word + cw.rest_offset();
// }
}

//////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions modules/speller/default/speller_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ namespace aspeller {
return check(MutableString(&w.front(), sz));
}

bool check_camel(const char * str, size_t len, CheckInfo & ci);

CheckInfo * check_runtogether(char * word, char * word_end, /* it WILL modify word */
bool try_uppercase,
unsigned run_together_limit,
Expand Down
17 changes: 17 additions & 0 deletions test/sanity
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,20 @@ else
exit 1
fi

echo 'itIsOKForACamelCaseWordToContainNumerousCOMPONENTS' | aspell --camel-case -d en_US -a > tmp/res
if cat tmp/res | fgrep '-'; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity is meant for a few quick tests to make sure Aspell functions at all. Specific unit tests should be in a separate file. Please move these into the file test/camel_case and add a target for it in the Makefile.

echo "pass"
else
echo "fail:"
cat tmp/res
exit 1
fi

echo 'EvenIfTheFirstCOMPONENTBeginsWithACapitalLetter' | aspell --camel-case -d en_US -a > tmp/res
if cat tmp/res | fgrep '-'; then
echo "pass"
else
echo "fail:"
cat tmp/res
exit 1
fi