diff --git a/modules/speller/default/speller_impl.cpp b/modules/speller/default/speller_impl.cpp index 12e226a3..e67fce09 100644 --- a/modules/speller/default/speller_impl.cpp +++ b/modules/speller/default/speller_impl.cpp @@ -214,6 +214,41 @@ 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 SpellerImpl::check(char * word, char * word_end, /* it WILL modify word */ bool try_uppercase, @@ -221,17 +256,22 @@ namespace aspeller { 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); @@ -255,7 +295,7 @@ namespace aspeller { if (cpi) cpi->count++; - + if (ci_prev) { ci_prev->compound = true; ci_prev->next = ci; @@ -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(); - // } } ////////////////////////////////////////////////////////////////////// diff --git a/modules/speller/default/speller_impl.hpp b/modules/speller/default/speller_impl.hpp index 17a60d13..2cc9f5d8 100644 --- a/modules/speller/default/speller_impl.hpp +++ b/modules/speller/default/speller_impl.hpp @@ -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, diff --git a/test/Makefile b/test/Makefile index 9f709ddb..f821de90 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 @@ -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 diff --git a/test/camel-case b/test/camel-case new file mode 100644 index 00000000..b260aee8 --- /dev/null +++ b/test/camel-case @@ -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