# HG changeset patch # User ali # Date 1381960289 -3600 # Node ID 70cc629ec1e0b3a9010092a438aff6babb23bbcd # Parent d22d8cd4f6285d16494b49a825d6c951e0d132c0 Fix bug #28: Don't report ., as double punctuation after "etc" or "&c" diff -r d22d8cd4f628 -r 70cc629ec1e0 bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Sun Oct 27 17:01:47 2013 +0000 +++ b/bookloupe/bookloupe.c Wed Oct 16 22:51:29 2013 +0100 @@ -2568,6 +2568,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)) { @@ -2593,36 +2617,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 d22d8cd4f628 -r 70cc629ec1e0 test/bookloupe/Makefile.am --- a/test/bookloupe/Makefile.am Sun Oct 27 17:01:47 2013 +0000 +++ b/test/bookloupe/Makefile.am Wed Oct 16 22:51:29 2013 +0100 @@ -3,6 +3,6 @@ runfox-quotes.tst curved-genitives.tst multi-line-illustration.tst \ emdash.tst config-internal.tst config-default.tst config-user.tst \ config-override.tst charset-cp1252.tst charset-latin1.tst \ - footnote-marker.tst unix-lineends.tst os9-lineends.tst + footnote-marker.tst unix-lineends.tst os9-lineends.tst dot-comma.tst dist_pkgdata_DATA=$(TESTS) diff -r d22d8cd4f628 -r 70cc629ec1e0 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 ****************