Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
Tokenizer.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <string>
5#include <utility>
6
7namespace ph
8{
9
10// TODO: make this possible for use as constexpr (most use cases are constexpr)
11// TODO: parse string_view
12class Tokenizer final
13{
14public:
15 explicit Tokenizer(const std::vector<char>& separators);
16 explicit Tokenizer(const std::vector<std::pair<char, char>>& enclosures);
17 Tokenizer(const std::vector<char>& separators, const std::vector<std::pair<char, char>>& enclosures);
18
19 // Tokenize the input string using specified rules (separators & enclosures).
20 // The resulting tokens will not include any separator and enclosure characters
21 // or any empty strings.
22 // Also notice that source string's starting and ending locations are treated
23 // as implicit separators; for example, the source string will be returned as a
24 // token if no separator is provided and no enclosures are found.
25 void tokenize(const std::string& source, std::vector<std::string>& out_results) const;
26
27private:
28 std::vector<char> m_separators;
29 std::vector<std::pair<char, char>> m_enclosures;
30
31 std::size_t extractSeparatorSeparatedToken(const std::string& source, const std::size_t startIndex,
32 std::vector<std::string>& out_results) const;
33 std::size_t extractEnclosureSeparatedToken(const std::string& source, const std::size_t startIndex, const char enclosureStart,
34 std::vector<std::string>& out_results) const;
35 bool isSeparator(const char character) const;
36 bool isEnclosureStart(const char startCh) const;
37 bool isEnclosurePair(const char startCh, const char endCh) const;
38};
39
40}// end namespace ph
Definition Tokenizer.h:13
void tokenize(const std::string &source, std::vector< std::string > &out_results) const
Definition Tokenizer.cpp:25
Tokenizer(const std::vector< char > &separators)
Definition Tokenizer.cpp:8
The root for all renderer implementations.
Definition EEngineProject.h:6