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;
|
||||
}
|
||||
|
||||
void Token::insertToken(const std::string &tokenStr)
|
||||
void Token::insertToken(const std::string &tokenStr, bool prepend)
|
||||
{
|
||||
Token *newToken;
|
||||
|
||||
//TODO: Find a solution for the first token on the list
|
||||
if (prepend && !this->previous())
|
||||
return;
|
||||
|
||||
if (_str.empty())
|
||||
newToken = this;
|
||||
else
|
||||
|
@ -911,6 +916,16 @@ void Token::insertToken(const std::string &tokenStr)
|
|||
newToken->_progressValue = _progressValue;
|
||||
|
||||
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()) {
|
||||
newToken->next(this->next());
|
||||
newToken->next()->previous(newToken);
|
||||
|
@ -921,6 +936,7 @@ void Token::insertToken(const std::string &tokenStr)
|
|||
newToken->previous(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Token::eraseTokens(Token *begin, const Token *end)
|
||||
{
|
||||
|
|
|
@ -293,8 +293,10 @@ public:
|
|||
* Insert new token after this token. This function will handle
|
||||
* relations between next and previous token also.
|
||||
* @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 {
|
||||
return _previous;
|
||||
|
|
Loading…
Reference in New Issue