stringstream.h 1.0 KB

1234567891011121314151617181920212223242526272829
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "stream.h"
  5. namespace embree
  6. {
  7. /*! simple tokenizer that produces a string stream */
  8. class StringStream : public Stream<std::string>
  9. {
  10. public:
  11. StringStream(const Ref<Stream<int> >& cin, const std::string& seps = "\n\t\r ",
  12. const std::string& endl = "", bool multiLine = false);
  13. public:
  14. ParseLocation location() { return cin->loc(); }
  15. std::string next();
  16. private:
  17. __forceinline bool isSeparator(unsigned int c) const { return c<256 && isSepMap[c]; }
  18. __forceinline bool isValidChar(unsigned int c) const { return c<256 && isValidCharMap[c]; }
  19. private:
  20. Ref<Stream<int> > cin; /*! source character stream */
  21. bool isSepMap[256]; /*! map for fast classification of separators */
  22. bool isValidCharMap[256]; /*! map for valid characters */
  23. std::string endl; /*! the token of the end of line */
  24. bool multiLine; /*! whether to parse lines wrapped with \ */
  25. };
  26. }