ReadStream.cc
Go to the documentation of this file.
1 #include <utl/ReadStream.h>
2 #include <utl/ErrorLogger.h>
3 
4 using namespace std;
5 
6 
7 namespace utl {
8 
9  string
10  ReadStream::FilterComments(const string& line)
11  {
12  string ret;
13  ret.reserve(line.size());
14  bool white = false;
15  for (size_t i = 0, n = line.size(); i < n; ) {
16  const char c = line[i++];
17  switch (c) {
18  case '#':
19  return ret;
20  case ' ':
21  case '\t':
22  case '\r':
23  if (!ret.empty())
24  white = true;
25  continue;
26  case '/':
27  {
28  const char c2 = line[i++];
29  switch (c2) {
30  case '/':
31  return ret;
32  case '*':
33  i = line.find("*/", i);
34  if (i == string::npos) {
35  const string err = "Only single line comments supported!";
36  ERROR(err);
37  throw DoesNotComputeException(err);
38  }
39  i += 2;
40  continue;
41  default:
42  if (white) {
43  ret.push_back(' ');
44  white = false;
45  }
46  ret.push_back(c);
47  ret.push_back(c2);
48  continue;
49  }
50  }
51  default:
52  if (white) {
53  ret.push_back(' ');
54  white = false;
55  }
56  ret.push_back(c);
57  continue;
58  }
59  }
60  if (!ret.empty() && ret[ret.length()-1] == ' ')
61  ret.erase(ret.length()-1);
62  return ret;
63  }
64 
65 }
Base class for inconsistency/illogicality exceptions.
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.