| 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 | /*! simple tokenizer that produces a string stream */ |
| 11 | class StringStream : public Stream<std::string> |
| 12 | { |
| 13 | public: |
| 14 | StringStream(const Ref<Stream<int> >& cin, const std::string& seps = "\n\t\r " , |
| 15 | const std::string& endl = "" , bool multiLine = false); |
| 16 | public: |
| 17 | ParseLocation location() { return cin->loc(); } |
| 18 | std::string next(); |
| 19 | private: |
| 20 | __forceinline bool isSeparator(unsigned int c) const { return c<256 && isSepMap[c]; } |
| 21 | __forceinline bool isValidChar(unsigned int c) const { return c<256 && isValidCharMap[c]; } |
| 22 | private: |
| 23 | Ref<Stream<int> > cin; /*! source character stream */ |
| 24 | bool isSepMap[256]; /*! map for fast classification of separators */ |
| 25 | bool isValidCharMap[256]; /*! map for valid characters */ |
| 26 | std::string endl; /*! the token of the end of line */ |
| 27 | bool multiLine; /*! whether to parse lines wrapped with \ */ |
| 28 | }; |
| 29 | } |
| 30 | |