@@ -13,55 +13,26 @@ Author: Daniel Kroening, kroening@kroening.com
13
13
#include " ansi_c_typecheck.h"
14
14
15
15
#include < util/config.h>
16
+ #include < util/string_utils.h>
16
17
17
- #include < cstring>
18
18
#include < ostream>
19
19
#include < sstream>
20
20
21
- // ! Advance to the next line
22
- static const char *next_line (const char *line)
23
- {
24
- const char *end=strchr (line, ' \n ' );
25
-
26
- if (end==NULL )
27
- return strchr (line, 0 );
28
- else
29
- return end+1 ;
30
- }
31
-
32
- // ! Look for given pattern in given string.
33
- // ! Add line with pattern to 'out' if found.
34
- // ! \return 'true' if found
35
21
static bool find_pattern (
36
22
const std::string &pattern,
37
23
const char *header_file,
38
24
std::ostream &out)
39
25
{
40
- // read line-by-line
41
- const char *line, *line_end;
42
-
43
- for (line=header_file; *line!=0 ; line=line_end)
26
+ std::istringstream hdr (header_file);
27
+ std::string line;
28
+ while (std::getline (hdr, line))
44
29
{
45
- line_end=next_line (line);
46
-
47
- // skip spaces
48
- while (*line==' ' )
49
- line++;
50
-
51
- if (line[0 ]==' /' && line[1 ]==' /' ) // comment
30
+ line = strip_string (line);
31
+ if (has_prefix (line, " //" ) || line.find (pattern) == std::string::npos)
52
32
continue ;
53
33
54
- for (const char *p=line; p<line_end; p++)
55
- {
56
- if (strncmp (p, pattern.c_str (), pattern.size ())==0 )
57
- {
58
- // copy the entire line to out
59
- for (const char *s=line; s!=line_end; s++)
60
- out << *s;
61
-
62
- return true ; // done, found
63
- }
64
- }
34
+ out << line;
35
+ return true ;
65
36
}
66
37
67
38
return false ;
0 commit comments