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);