reformat
This commit is contained in:
parent
29980e299c
commit
f4dd438fcc
24 changed files with 457 additions and 413 deletions
|
@ -4,7 +4,7 @@
|
|||
using namespace mstch;
|
||||
|
||||
token::type token::token_info(char c) {
|
||||
switch (c) {
|
||||
switch (c) {
|
||||
case '>': return type::partial;
|
||||
case '^': return type::inverted_section_open;
|
||||
case '/': return type::section_close;
|
||||
|
@ -12,27 +12,27 @@ token::type token::token_info(char c) {
|
|||
case '#': return type::section_open;
|
||||
case '!': return type::comment;
|
||||
default: return type::variable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
token::token(const std::string& str, std::size_t left, std::size_t right):
|
||||
m_raw(str), m_eol(false), m_ws_only(false)
|
||||
m_raw(str), m_eol(false), m_ws_only(false)
|
||||
{
|
||||
if(left != 0 && right != 0) {
|
||||
if(str[left] == '{' && str[str.size() - right - 1] == '}') {
|
||||
m_type = type::unescaped_variable;
|
||||
m_name = {first_not_ws(str.begin() + left + 1, str.end() - right),
|
||||
first_not_ws(str.rbegin() + 1 + right, str.rend() - left) + 1};
|
||||
} else {
|
||||
auto first = first_not_ws(str.begin() + left, str.end() - right);
|
||||
m_type = token_info(*first);
|
||||
if(m_type != type::variable)
|
||||
first = first_not_ws(first + 1, str.end() - right);
|
||||
m_name = {first, first_not_ws(str.rbegin() + right, str.rend() - left) + 1};
|
||||
}
|
||||
if (left != 0 && right != 0) {
|
||||
if (str[left] == '{' && str[str.size() - right - 1] == '}') {
|
||||
m_type = type::unescaped_variable;
|
||||
m_name = {first_not_ws(str.begin() + left + 1, str.end() - right),
|
||||
first_not_ws(str.rbegin() + 1 + right, str.rend() - left) + 1};
|
||||
} else {
|
||||
m_type = type::text;
|
||||
m_eol = (str.size() > 0 && str[str.size() - 1] == '\n');
|
||||
m_ws_only = (str.find_first_not_of(" \n\t") == std::string::npos);
|
||||
auto c = first_not_ws(str.begin() + left, str.end() - right);
|
||||
m_type = token_info(*c);
|
||||
if (m_type != type::variable)
|
||||
c = first_not_ws(c + 1, str.end() - right);
|
||||
m_name = {c, first_not_ws(str.rbegin() + right, str.rend() - left) + 1};
|
||||
}
|
||||
} else {
|
||||
m_type = type::text;
|
||||
m_eol = (str.size() > 0 && str[str.size() - 1] == '\n');
|
||||
m_ws_only = (str.find_first_not_of(" \n\t") == std::string::npos);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue