Skip to content

Commit 17d9897

Browse files
author
Daniel Kroening
committed
switch to C++ version of find_pattern
1 parent 80ee0b1 commit 17d9897

File tree

1 file changed

+8
-37
lines changed

1 file changed

+8
-37
lines changed

src/ansi-c/builtin_factory.cpp

+8-37
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,26 @@ Author: Daniel Kroening, [email protected]
1313
#include "ansi_c_typecheck.h"
1414

1515
#include <util/config.h>
16+
#include <util/string_utils.h>
1617

17-
#include <cstring>
1818
#include <ostream>
1919
#include <sstream>
2020

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
3521
static bool find_pattern(
3622
const std::string &pattern,
3723
const char *header_file,
3824
std::ostream &out)
3925
{
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))
4429
{
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)
5232
continue;
5333

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;
6536
}
6637

6738
return false;

0 commit comments

Comments
 (0)