TextMateLib 1.0
Modern C++ implementation of the TextMate syntax highlighting engine
Loading...
Searching...
No Matches
matcher.cpp
1#include "matcher.h"
2#include <regex>
3
4namespace tml {
5
6bool isIdentifier(const std::string& token) {
7 if (token.empty()) {
8 return false;
9 }
10 std::regex identifierPattern("[\\w\\.:]+");
11 return std::regex_match(token, identifierPattern);
12}
13
14bool isIdentifier(const std::string* token) {
15 if (!token || token->empty()) {
16 return false;
17 }
18 return isIdentifier(*token);
19}
20
21SelectorTokenizer::SelectorTokenizer(const std::string& input)
22 : _input(input), _position(0) {
23}
24
25std::string* SelectorTokenizer::next() {
26 std::regex tokenPattern("([LR]:|[\\w\\.:][\\.:\\-\\w]*|[\\,\\|\\-\\(\\)])");
27 std::smatch match;
28
29 std::string remaining = _input.substr(_position);
30 if (std::regex_search(remaining, match, tokenPattern)) {
31 _position += match.position() + match.length();
32 return new std::string(match.str());
33 }
34
35 return nullptr;
36}
37
38// Template instantiation would go in the cpp file
39// But since this is a template, we need to keep implementation in header or explicitly instantiate
40
41} // namespace tml