| 371 | } |
| 372 | |
| 373 | void Token::replace(Token *replaceThis, Token *start, Token *end) |
| 374 | { |
| 375 | // Fix the whole in the old location of start and end |
| 376 | if (start->previous()) |
| 377 | start->previous()->next(end->next()); |
| 378 | |
| 379 | if (end->next()) |
| 380 | end->next()->previous(start->previous()); |
| 381 | |
| 382 | // Move start and end to their new location |
| 383 | if (replaceThis->previous()) |
| 384 | replaceThis->previous()->next(start); |
| 385 | |
| 386 | if (replaceThis->next()) |
| 387 | replaceThis->next()->previous(end); |
| 388 | |
| 389 | start->previous(replaceThis->previous()); |
| 390 | end->next(replaceThis->next()); |
| 391 | |
| 392 | if (end->mTokensFrontBack->back == end) { |
| 393 | while (end->next()) |
| 394 | end = end->next(); |
| 395 | end->mTokensFrontBack->back = end; |
| 396 | } |
| 397 | |
| 398 | // Update mProgressValue, fileIndex and linenr |
| 399 | for (Token *tok = start; tok != end->next(); tok = tok->next()) |
| 400 | tok->mImpl->mProgressValue = replaceThis->mImpl->mProgressValue; |
| 401 | |
| 402 | // Delete old token, which is replaced |
| 403 | delete replaceThis; |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * @throws InternalError thrown on unexpected command or missing varid with %varid% |