Improvements in token.cpp:

- Shortened stringify output - 4 or more subsequent empty lines are abbreviated
- Fixed detection of comparision operators
- Make use of _type: Replaced three asserts by one
This commit is contained in:
PKEuS 2012-08-02 11:36:54 -07:00
parent 1b40668e04
commit 5e862351e9
1 changed files with 20 additions and 16 deletions

View File

@ -91,12 +91,12 @@ void Token::update_property_info()
_str == "||" || _str == "||" ||
_str == "!") _str == "!")
_type = eLogicalOp; _type = eLogicalOp;
else if (_str == "==" || else if ((_str == "==" ||
_str == "!=" || _str == "!=" ||
_str == "<" || _str == "<" ||
_str == "<=" || _str == "<=" ||
_str == ">" || _str == ">" ||
_str == ">=") _str == ">=") && !_link)
_type = eComparisonOp; _type = eComparisonOp;
else if (_str == "++" || else if (_str == "++" ||
_str == "--") _str == "--")
@ -159,9 +159,7 @@ void Token::concatStr(std::string const& b)
std::string Token::strValue() const std::string Token::strValue() const
{ {
assert(_str.length() >= 2); assert(_type == eString);
assert(_str[0] == '"');
assert(_str[_str.length()-1] == '"');
return _str.substr(1, _str.length() - 2); return _str.substr(1, _str.length() - 2);
} }
@ -1000,13 +998,19 @@ std::string Token::stringifyList(bool varid, bool attributes, bool linenumbers,
} }
if (linebreaks && (lineNumber != tok->linenr() || fileChange)) { if (linebreaks && (lineNumber != tok->linenr() || fileChange)) {
while (lineNumber < tok->linenr()) { if (lineNumber+4 < tok->linenr() && fileInd == static_cast<int>(tok->_fileIndex)) {
++lineNumber; ret << '\n' << lineNumber+1 << ":\n|\n";
ret << '\n'; ret << tok->linenr()-1 << ":\n";
if (linenumbers) { ret << tok->linenr() << ": ";
ret << lineNumber << ':'; } else {
if (lineNumber == tok->linenr()) while (lineNumber < tok->linenr()) {
ret << ' '; ++lineNumber;
ret << '\n';
if (linenumbers) {
ret << lineNumber << ':';
if (lineNumber == tok->linenr())
ret << ' ';
}
} }
} }
lineNumber = tok->linenr(); lineNumber = tok->linenr();