From: Tom Tromey Date: Tue, 22 Feb 2022 19:53:14 +0000 (-0700) Subject: Refactor ada-lex.l:processId X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=67700be2867e6f03d7e0891a47429aab2b879551;p=binutils-gdb.git Refactor ada-lex.l:processId 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". --- diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index 6c32a9bd002..40e450bf679 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -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';