Adding a vector version of clang::tooling::shiftedCodePosition().

During the transition of clang::tooling::Replacements from std::set to
std::vector, functions such as clang::tooling::applyAllReplacements() have been
duplicated to take a std::vector<Replacement>. Applying this same temporary
duplication to clang::tooling::shiftedCodePosition().

llvm-svn: 189358
This commit is contained in:
Edwin Vane
2013-08-27 15:44:26 +00:00
parent 85ec25d21c
commit 18e503c995
3 changed files with 41 additions and 0 deletions

View File

@@ -203,6 +203,23 @@ unsigned shiftedCodePosition(const Replacements &Replaces, unsigned Position) {
return NewPosition;
}
// FIXME: Remove this function when Replacements is implemented as std::vector
// instead of std::set.
unsigned shiftedCodePosition(const std::vector<Replacement> &Replaces,
unsigned Position) {
unsigned NewPosition = Position;
for (std::vector<Replacement>::const_iterator I = Replaces.begin(),
E = Replaces.end();
I != E; ++I) {
if (I->getOffset() >= Position)
break;
if (I->getOffset() + I->getLength() > Position)
NewPosition += I->getOffset() + I->getLength() - Position;
NewPosition += I->getReplacementText().size() - I->getLength();
}
return NewPosition;
}
void deduplicate(std::vector<Replacement> &Replaces,
std::vector<Range> &Conflicts) {
if (Replaces.empty())