]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Refactor ada-lex.l:processId
authorTom Tromey <tromey@adacore.com>
Tue, 22 Feb 2022 19:53:14 +0000 (12:53 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 4 Apr 2022 18:46:09 +0000 (12:46 -0600)
processId in ada-lex.l is a bit funny -- it uses an "if" and a
"switch", and a nested loop.  This patch cleans it up a bit, changing
it to use a boolean flag and a simpler "if".

gdb/ada-lex.l

index 6c32a9bd002e651215d8ff4adfdb1acf0aeb3ab9..40e450bf6790ff377cfcf52e5bd82886fa3d8012 100644 (file)
@@ -541,33 +541,28 @@ processId (const char *name0, int len)
       return result;
     }
 
+  bool in_quotes = false;
   i = i0 = 0;
   while (i0 < len)
     {
-      if (isalnum (name0[i0]))
+      if (in_quotes)
+       name[i++] = name0[i0++];
+      else if (isalnum (name0[i0]))
        {
          name[i] = tolower (name0[i0]);
          i += 1; i0 += 1;
        }
-      else switch (name0[i0])
+      else if (isspace (name0[i0]))
+       i0 += 1;
+      else if (name0[i0] == '\'')
        {
-       default:
-         name[i] = name0[i0];
-         i += 1; i0 += 1;
-         break;
-       case ' ': case '\t':
-         i0 += 1;
-         break;
-       case '\'':
-         do
-           {
-             name[i] = name0[i0];
-             i += 1; i0 += 1;
-           }
-         while (i0 < len && name0[i0] != '\'');
-         i0 += 1;
-         break;
+         /* Copy the starting quote, but not the ending quote.  */
+         if (!in_quotes)
+           name[i++] = name0[i0++];
+         in_quotes = !in_quotes;
        }
+      else
+       name[i++] = name0[i0++];
     }
   name[i] = '\000';