]> granicus.if.org Git - flex/commitdiff
filter: new internal function is_blank_line()
authorExplorer09 <explorer09@gmail.com>
Sat, 8 Jul 2017 10:54:30 +0000 (18:54 +0800)
committerWill Estes <westes575@gmail.com>
Thu, 13 Jul 2017 19:15:29 +0000 (15:15 -0400)
It's simply to return (regexec(&regex_blank_line, str, 0, NULL, 0) == 0);
The reason for encapsulation is to allow replacing this with a
non-regex method if necessary.

src/filter.c

index 35b80a96fd910c766f2d7370775c857d966a33e7..fd1bb40ab5dcfbba3dafcabcd578688358216af2 100644 (file)
@@ -324,6 +324,11 @@ int filter_tee_header (struct filter *chain)
        return 0;
 }
 
+static bool is_blank_line (const char *str)
+{
+       return (regexec (&regex_blank_line, str, 0, NULL, 0) == 0);
+}
+
 /** Adjust the line numbers in the #line directives of the generated scanner.
  * After the m4 expansion, the line numbers are incorrect since the m4 macros
  * can add or remove lines.  This only adjusts line numbers for generated code,
@@ -395,9 +400,7 @@ int filter_fix_linedirs (struct filter *chain)
                }
 
                /* squeeze blank lines from generated code */
-               else if (in_gen
-                        && regexec (&regex_blank_line, buf, 0, NULL,
-                                    0) == 0) {
+               else if (in_gen && is_blank_line(buf)) {
                        if (last_was_blank)
                                continue;
                        else