1 | // Copyright 2009-2021 Intel Corporation |
---|---|
2 | // SPDX-License-Identifier: Apache-2.0 |
3 | |
4 | #pragma once |
5 | |
6 | #include "stream.h" |
7 | |
8 | namespace embree |
9 | { |
10 | /* removes all line comments from a stream */ |
11 | class LineCommentFilter : public Stream<int> |
12 | { |
13 | public: |
14 | LineCommentFilter (const FileName& fileName, const std::string& lineComment) |
15 | : cin(new FileStream(fileName)), lineComment(lineComment) {} |
16 | LineCommentFilter (Ref<Stream<int> > cin, const std::string& lineComment) |
17 | : cin(cin), lineComment(lineComment) {} |
18 | |
19 | ParseLocation location() { return cin->loc(); } |
20 | |
21 | int next() |
22 | { |
23 | /* look if the line comment starts here */ |
24 | for (size_t j=0; j<lineComment.size(); j++) { |
25 | if (cin->peek() != lineComment[j]) { cin->unget(j); goto not_found; } |
26 | cin->get(); |
27 | } |
28 | /* eat all characters until the end of the line (or file) */ |
29 | while (cin->peek() != '\n' && cin->peek() != EOF) cin->get(); |
30 | |
31 | not_found: |
32 | return cin->get(); |
33 | } |
34 | |
35 | private: |
36 | Ref<Stream<int> > cin; |
37 | std::string lineComment; |
38 | }; |
39 | } |
40 |