@@ -183,36 +183,34 @@ void UseStdMinMaxCheck::check(const MatchFinder::MatchResult &Result) {
183183 }
184184 };
185185
186+ const auto GetSourceText = [&](SourceLocation StartLoc,
187+ SourceLocation EndLoc) {
188+ return Lexer::getSourceText (
189+ CharSourceRange::getCharRange (
190+ Lexer::getLocForEndOfToken (StartLoc, 0 , Source, LO), EndLoc),
191+ Source, LO);
192+ };
193+
186194 // Captures:
187195 // if (cond) // Comment A
188196 // if (cond) /* Comment A */ { ... }
189197 // if (cond) /* Comment A */ x = y;
190- AppendNormalized (Lexer::getSourceText (
191- CharSourceRange::getCharRange (
192- Lexer::getLocForEndOfToken (If->getRParenLoc (), 0 , Source, LO),
193- If->getThen ()->getBeginLoc ()),
194- Source, LO));
198+ AppendNormalized (
199+ GetSourceText (If->getRParenLoc (), If->getThen ()->getBeginLoc ()));
195200
196201 if (const auto *CS = dyn_cast<CompoundStmt>(If->getThen ())) {
197202 const Stmt *Inner = CS->body_front ();
198203
199204 // Captures:
200205 // if (cond) { // Comment B ... }
201206 // if (cond) { /* Comment B */ x = y; }
202- AppendNormalized (Lexer::getSourceText (
203- CharSourceRange::getCharRange (
204- Lexer::getLocForEndOfToken (CS->getBeginLoc (), 0 , Source, LO),
205- Inner->getBeginLoc ()),
206- Source, LO));
207+ AppendNormalized (GetSourceText (CS->getBeginLoc (), Inner->getBeginLoc ()));
207208
208209 // Captures:
209210 // if (cond) { x = y; // Comment C }
210211 // if (cond) { x = y; /* Comment C */ }
211- llvm::StringRef PostInner = Lexer::getSourceText (
212- CharSourceRange::getCharRange (
213- Lexer::getLocForEndOfToken (Inner->getEndLoc (), 0 , Source, LO),
214- CS->getEndLoc ()),
215- Source, LO);
212+ llvm::StringRef PostInner =
213+ GetSourceText (Inner->getEndLoc (), CS->getEndLoc ());
216214
217215 // Strip the trailing semicolon to avoid fixes like:
218216 // x = std::min(x, y);; // comment
0 commit comments