Add a 'prepend' bool option to Token::InsertToken.
If it's true, add a new token before this. Except when this is the first one in the list, because there's not a way to update the list.front (I noticed some Token functions can potentially delete the list.front(), I don't know which effects does it cause).
This commit is contained in:
parent
fdeacbaec6
commit
e0c10efdce
|
@ -898,9 +898,14 @@ const Token *Token::findmatch(const Token *tok, const char pattern[], const Toke
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Token::insertToken(const std::string &tokenStr)
|
void Token::insertToken(const std::string &tokenStr, bool prepend)
|
||||||
{
|
{
|
||||||
Token *newToken;
|
Token *newToken;
|
||||||
|
|
||||||
|
//TODO: Find a solution for the first token on the list
|
||||||
|
if (prepend && !this->previous())
|
||||||
|
return;
|
||||||
|
|
||||||
if (_str.empty())
|
if (_str.empty())
|
||||||
newToken = this;
|
newToken = this;
|
||||||
else
|
else
|
||||||
|
@ -911,6 +916,16 @@ void Token::insertToken(const std::string &tokenStr)
|
||||||
newToken->_progressValue = _progressValue;
|
newToken->_progressValue = _progressValue;
|
||||||
|
|
||||||
if (newToken != this) {
|
if (newToken != this) {
|
||||||
|
if (prepend) {
|
||||||
|
/*if (this->previous())*/ {
|
||||||
|
newToken->previous(this->previous());
|
||||||
|
newToken->previous()->next(newToken);
|
||||||
|
} /*else if (tokensFront?) {
|
||||||
|
*tokensFront? = newToken;
|
||||||
|
}*/
|
||||||
|
this->previous(newToken);
|
||||||
|
newToken->next(this);
|
||||||
|
} else {
|
||||||
if (this->next()) {
|
if (this->next()) {
|
||||||
newToken->next(this->next());
|
newToken->next(this->next());
|
||||||
newToken->next()->previous(newToken);
|
newToken->next()->previous(newToken);
|
||||||
|
@ -920,6 +935,7 @@ void Token::insertToken(const std::string &tokenStr)
|
||||||
this->next(newToken);
|
this->next(newToken);
|
||||||
newToken->previous(this);
|
newToken->previous(this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Token::eraseTokens(Token *begin, const Token *end)
|
void Token::eraseTokens(Token *begin, const Token *end)
|
||||||
|
|
|
@ -293,8 +293,10 @@ public:
|
||||||
* Insert new token after this token. This function will handle
|
* Insert new token after this token. This function will handle
|
||||||
* relations between next and previous token also.
|
* relations between next and previous token also.
|
||||||
* @param tokenStr String for the new token.
|
* @param tokenStr String for the new token.
|
||||||
|
* @param prepend Insert the new token before this token when it's not
|
||||||
|
* the first one on the tokens list.
|
||||||
*/
|
*/
|
||||||
void insertToken(const std::string &tokenStr);
|
void insertToken(const std::string &tokenStr, const bool prepend=false);
|
||||||
|
|
||||||
Token *previous() const {
|
Token *previous() const {
|
||||||
return _previous;
|
return _previous;
|
||||||
|
|
Loading…
Reference in New Issue