5757#ifndef SIMPLECPP_TOKENLIST_ALLOW_PTR
5858// still provide the legacy API in case we lack the performant wrappers
5959# if !defined(__cpp_lib_string_view) && !defined(__cpp_lib_span)
60- # define SIMPLECPP_TOKENLIST_ALLOW_PTR
60+ // # define SIMPLECPP_TOKENLIST_ALLOW_PTR
6161# endif
6262#endif
6363
@@ -69,6 +69,40 @@ namespace simplecpp {
6969 enum cppstd_t : std::int8_t { CPPUnknown=-1 , CPP03, CPP11, CPP14, CPP17, CPP20, CPP23, CPP26 };
7070
7171 using TokenString = std::string;
72+
73+ #if defined(__cpp_lib_string_view)
74+ using View = std::string_view;
75+ #else
76+ struct View
77+ {
78+ View (const char * data)
79+ : data_(data)
80+ , size_(strlen(data))
81+ {}
82+
83+ View (const char * data, std::size_t size)
84+ : data_(data)
85+ , size_(size)
86+ {}
87+
88+ View (const std::string& str)
89+ : data_(str.data())
90+ , size_(str.size())
91+ {}
92+
93+ const char * data () const {
94+ return data_;
95+ }
96+
97+ std::size_t size () const {
98+ return size_;
99+ }
100+
101+ const char * data_;
102+ std::size_t size_;
103+ };
104+ #endif
105+
72106 class Macro ;
73107
74108 /* *
@@ -238,9 +272,9 @@ namespace simplecpp {
238272 : TokenList(reinterpret_cast <const unsigned char *>(data), size, filenames, filename, outputList, 0)
239273 {}
240274#endif
241- #if defined(__cpp_lib_string_view) && !defined(__cpp_lib_span)
275+ #if !defined(__cpp_lib_span)
242276 /* * generates a token list from the given buffer */
243- TokenList (std::string_view data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
277+ TokenList (View data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr)
244278 : TokenList(reinterpret_cast <const unsigned char *>(data.data()), data.size(), filenames, filename, outputList, 0)
245279 {}
246280#endif
0 commit comments