# HG changeset patch # User ali # Date 1381960289 -3600 # Node ID 719d0682a16a4590e61baf1c1468b206a76e0e4c # Parent 37da646396b98688519d402293acf70d6a6aa300 Fix bug #28: Don't report ., as double punctuation after "etc" or "&c" diff -r 37da646396b9 -r 719d0682a16a bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Tue Oct 15 07:57:45 2013 +0100 +++ b/bookloupe/bookloupe.c Wed Oct 16 22:51:29 2013 +0100 @@ -2130,6 +2130,27 @@ } /* + * str_follows_word: + * + * Given a position p within a string str, determine whether it follows the + * given word. This is roughly equivalent to the regular expression (?<=\bword) + * but has different boundary conditions. + */ +static gboolean str_follows_word(const char *str,const char *p,const char *word) +{ + int len=strlen(word); + if (p-lendotcomma is used * to suppress detailed reporting if it occurs often. + * Indeed, ".," is so common after "etc" or "&c" that + * we don't warn on these cases at all. */ void check_for_double_punctuation(const char *aline,struct warnings *warnings) { const char *s; gunichar c,nc; + gboolean is_query; nc=g_utf8_get_char(aline); for (s=aline;*s;s=g_utf8_next_char(s)) { @@ -2155,36 +2179,30 @@ g_utf8_strchr(".?!,;:",-1,nc)) { /* followed by punctuation, it's a query, unless . . . */ - if (c==nc && (c=='.' || c=='?' || c=='!') || - !warnings->dotcomma && c=='.' && nc==',' || - warnings->isFrench && g_str_has_prefix(s,",...") || - warnings->isFrench && g_str_has_prefix(s,"...,") || - warnings->isFrench && g_str_has_prefix(s,";...") || - warnings->isFrench && g_str_has_prefix(s,"...;") || - warnings->isFrench && g_str_has_prefix(s,":...") || - warnings->isFrench && g_str_has_prefix(s,"...:") || - warnings->isFrench && g_str_has_prefix(s,"!...") || - warnings->isFrench && g_str_has_prefix(s,"...!") || - warnings->isFrench && g_str_has_prefix(s,"?...") || - warnings->isFrench && g_str_has_prefix(s,"...?")) + is_query=TRUE; + if (warnings->isFrench && + (g_str_has_prefix(s,",...") || g_str_has_prefix(s,"...,") || + g_str_has_prefix(s,";...") || g_str_has_prefix(s,"...;") || + g_str_has_prefix(s,":...") || g_str_has_prefix(s,"...:") || + g_str_has_prefix(s,"!...") || g_str_has_prefix(s,"...!") || + g_str_has_prefix(s,"?...") || g_str_has_prefix(s,"...?"))) { - if (warnings->isFrench && g_str_has_prefix(s,",...") || - warnings->isFrench && g_str_has_prefix(s,"...,") || - warnings->isFrench && g_str_has_prefix(s,";...") || - warnings->isFrench && g_str_has_prefix(s,"...;") || - warnings->isFrench && g_str_has_prefix(s,":...") || - warnings->isFrench && g_str_has_prefix(s,"...:") || - warnings->isFrench && g_str_has_prefix(s,"!...") || - warnings->isFrench && g_str_has_prefix(s,"...!") || - warnings->isFrench && g_str_has_prefix(s,"?...") || - warnings->isFrench && g_str_has_prefix(s,"...?")) - { - s+=4; - nc=g_utf8_get_char(g_utf8_next_char(s)); - } - ; /* do nothing for .. !! and ?? which can be legit */ + s+=4; + nc=g_utf8_get_char(g_utf8_next_char(s)); + is_query=FALSE; } - else + else if (c==nc && (c=='.' || c=='?' || c=='!')) + { + /* do nothing for .. !! and ?? which can be legit */ + is_query=FALSE; + } + else if (c=='.' && nc==',') + { + if (!warnings->dotcomma || str_follows_word(aline,s,"etc") || + str_follows_word(aline,s,"&c")) + is_query=FALSE; + } + if (is_query) { if (pswit[ECHO_SWITCH]) g_print("\n%s\n",aline); diff -r 37da646396b9 -r 719d0682a16a test/bookloupe/Makefile.am --- a/test/bookloupe/Makefile.am Tue Oct 15 07:57:45 2013 +0100 +++ b/test/bookloupe/Makefile.am Wed Oct 16 22:51:29 2013 +0100 @@ -1,6 +1,6 @@ TESTS_ENVIRONMENT=BOOKLOUPE=../../bookloupe/bookloupe ../harness/loupe-test TESTS=non-ascii.tst long-line.tst curved-single-quotes.tst curved-quotes.tst \ runfox-quotes.tst curved-genitives.tst multi-line-illustration.tst \ - emdash.tst + emdash.tst dot-comma.tst dist_pkgdata_DATA=$(TESTS) diff -r 37da646396b9 -r 719d0682a16a test/bookloupe/dot-comma.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bookloupe/dot-comma.tst Wed Oct 16 22:51:29 2013 +0100 @@ -0,0 +1,6 @@ +**************** INPUT **************** +All men should read the Gospels, &c., in their vulgar tongue. + +I would have redeemed them from the grip of Sheol, etc., if they had been +wise, but being foolish I will bring on them the plagues of death. +**************** EXPECTED ****************