From 1a5a74cde96fd8072e24456b46e2478a950b79a8 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 14 Jun 2017 10:46:27 -0400
Subject: [PATCH 28/44] FIXME: rework word-breaking

---
 gcc/spellcheck-enchant.c | 98 ++++++++++++++++++++++++------------------------
 1 file changed, 49 insertions(+), 49 deletions(-)

diff --git a/gcc/spellcheck-enchant.c b/gcc/spellcheck-enchant.c
index 3687e41..fe85b3d 100644
--- a/gcc/spellcheck-enchant.c
+++ b/gcc/spellcheck-enchant.c
@@ -383,59 +383,45 @@ spellcheck_enchant_check_comment (const cpp_token *token, location_t loc)
   for (idx = 2; idx < len; idx++)
     {
       unsigned char ch = content[idx];
-      if (ISALPHA (ch) || ch == '_')
-	{
-	  if (word_start_idx == -1)
-	    {
-	      /* We have the start of a word.  */
-	      word_start_idx = idx;
-	      word_start_column = column;
-	      word_start_line = line;
-	    }
-	}
-      else
+
+      /* If we see a '.' or '/' followed by non-whitespace, treat it as
+	 a filename, and ignore it.  */
+      if (ch == '.' || ch == '/')
+	if (idx + 1 < len)
+	  if (!ISSPACE (content[idx + 1]))
+	    ignore_until_next_whitespace = true;
+
+      /* If we see a '@' followed by non-whitespace, treat it as
+	 an email address, and ignore it.  */
+      if (ch == '@')
+	if (idx + 1 < len)
+	  if (!ISSPACE (content[idx + 1]))
+	    ignore_until_next_whitespace = true;
+
+      /* If we see a '-' after whitespace, treat it as a command-line
+	 option, and ignore it.  */
+      if (ch == '-')
+	if (idx > 0)
+	  if (ISSPACE (content[idx - 1]))
+	    ignore_until_next_whitespace = true;
+
+      /* If we have ', `, ", or < after whitespace, treat it as the
+	 start of a quoted word, and suppress spellchecking until further
+	 whitespace.  */
+      if (ch == '\'' || ch == '`' || ch == '"' || ch == '<' )
+	if (idx > 0)
+	  if (ISSPACE (content[idx - 1]))
+	    ignore_until_next_whitespace = true;
+
+      /* Detect word breaks.  */
+      if (word_start_idx != -1)
 	{
-	  /* If we see a '.' or '/' followed by non-whitespace, treat it as
-	     a filename, and ignore it.  */
-	  if (ch == '.' || ch == '/')
-	    if (idx + 1 < len)
-	      if (!ISSPACE (content[idx + 1]))
-		ignore_until_next_whitespace = true;
-
-	  /* If we see a '@' followed by non-whitespace, treat it as
-	     an email address, and ignore it.  */
-	  if (ch == '@')
-	    if (idx + 1 < len)
-	      if (!ISSPACE (content[idx + 1]))
-		ignore_until_next_whitespace = true;
-
-	  /* If we see a '-' after whitespace, treat it as a command-line
-	     option, and ignore it.  */
-	  if (ch == '-')
-	    if (idx > 0)
-	      if (ISSPACE (content[idx - 1]))
-		ignore_until_next_whitespace = true;
-
-	  /* If we have ', `, ", or < after whitespace, treat it as the
-	     start of a quoted word, and suppress spellchecking until further
-	     whitespace.  */
-	  if (ch == '\'' || ch == '`' || ch == '"' || ch == '<' )
-	    if (idx > 0)
-	      if (ISSPACE (content[idx - 1]))
-		ignore_until_next_whitespace = true;
-
-	  /* If we have ' followed by alphabetic, treat it as an apostrophe
-	     (and thus not a word ending), rather than a quote.  */
-	  bool is_apostrophe = false;
-	  if (ch == '\'')
-	    if (idx + 1 < len)
-	      if (ISALPHA (content[idx + 1]))
-		is_apostrophe = true;
-
-	  if (word_start_idx != -1 && !is_apostrophe)
+	  /* Within a word; look for word endings.  */
+	  if (!(ISALPHA (ch) || ch =='_' || ch == '\''))
 	    {
 	      /* We have a word ending.  */
 	      size_t word_len = idx - word_start_idx;
+
 	      /* Don't check any comments that appear to contain DejaGnu
 		 directives.  */
 	      if (word_len >= 2)
@@ -461,11 +447,25 @@ spellcheck_enchant_check_comment (const cpp_token *token, location_t loc)
 	      if (!ignore_until_next_whitespace)
 		spellcheck_word (content + word_start_idx, word_len, ord_map,
 				 word_start_line, word_start_column);
+
 	      word_start_idx = -1;
 	    }
 	}
+      else
+	{
+	  /* Outside a word; detect start of a word.  */
+	  if (ISALPHA (ch))
+	    {
+	      /* We have the start of a word.  */
+	      word_start_idx = idx;
+	      word_start_column = column;
+	      word_start_line = line;
+	    }
+	}
+
       if (ISSPACE (ch))
 	ignore_until_next_whitespace = false;
+
       if (ch == '\n')
 	{
 	  column = 1;
-- 
1.8.5.3

