Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ ifdef SLOPPY
EXTRA_CONFIG_FLAGS += --enable-sloppy-null-term-strings
endif

.PHONY: all prep sanity filter-test suggest wide cxx_warnings
all: prep sanity filter-test suggest wide cxx_warnings
.PHONY: all prep sanity camel-case filter-test suggest wide cxx_warnings
all: prep sanity camel-case filter-test suggest wide cxx_warnings
cat test-res

# warning-settings.mk defines EXTRA_CXXFLAGS
Expand All @@ -28,6 +28,10 @@ sanity: prep
./sanity
echo "all ok (sanity)" >> test-res

camel-case: prep
sh ./camel-case
echo "all ok (camel-case)" >> test-res

filter-test: prep
./filter-test "${ASPELL_WRAP} ${ASPELL}" < markdown.dat
echo "all ok (markdown filter-test)" >> test-res
Expand Down
22 changes: 22 additions & 0 deletions test/camel-case
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

set -e
set -x

echo 'itIsOKForACamelCaseWordToContainNumerousCOMPONENTS' | ${ASPELL} --camel-case -d en_US -a > tmp/camel-case-res
if cat tmp/camel-case-res | fgrep -x '-'; then
echo "pass"
else
echo "fail:"
cat tmp/camel-case-res
exit 1
fi

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