Use std::to_string instead of snprintf
This commit is contained in:
parent
2d9bd45816
commit
bff9327eb2
9
iwyu.cc
9
iwyu.cc
|
@ -89,7 +89,6 @@
|
|||
|
||||
#include <algorithm> // for swap, find, make_pair
|
||||
#include <cstddef> // for size_t
|
||||
#include <cstdio> // for snprintf
|
||||
#include <cstdlib> // for atoi, exit
|
||||
#include <cstring>
|
||||
#include <deque> // for swap
|
||||
|
@ -232,12 +231,6 @@ using std::vector;
|
|||
|
||||
namespace {
|
||||
|
||||
string IntToString(int i) {
|
||||
char buf[64]; // big enough for any number
|
||||
snprintf(buf, sizeof(buf), "%d", i);
|
||||
return buf;
|
||||
}
|
||||
|
||||
bool CanIgnoreLocation(SourceLocation loc) {
|
||||
// If we're in a macro expansion, we always want to treat this as
|
||||
// being in the expansion location, never the as-written location,
|
||||
|
@ -451,7 +444,7 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
|
|||
// etc.
|
||||
string AnnotatedName(const string& name) const {
|
||||
return (PrintableCurrentLoc() + ": (" +
|
||||
IntToString(current_ast_node_->depth()) + GetSymbolAnnotation() +
|
||||
std::to_string(current_ast_node_->depth()) + GetSymbolAnnotation() +
|
||||
(current_ast_node_->in_forward_declare_context() ?
|
||||
", fwd decl" : "") +
|
||||
") [ " + name + " ] ");
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "iwyu_include_picker.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -36,27 +35,21 @@ namespace include_what_you_use {
|
|||
|
||||
namespace {
|
||||
|
||||
string IntToString(int i) {
|
||||
char buf[64]; // big enough for any number
|
||||
snprintf(buf, sizeof(buf), "%d", i);
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Returns a string representing the first element where actual (a vector),
|
||||
// and expected (an array) differ, or "" if they're identical.
|
||||
template <size_t kCount> string VectorDiff(const string (&expected)[kCount],
|
||||
const vector<string>& actual) {
|
||||
for (int i = 0; i < std::min(kCount, actual.size()); ++i) {
|
||||
if (expected[i] != actual[i]) {
|
||||
return ("Differ at #" + IntToString(i) + ": expected=" + expected[i] +
|
||||
return ("Differ at #" + std::to_string(i) + ": expected=" + expected[i] +
|
||||
", actual=" + actual[i]);
|
||||
}
|
||||
}
|
||||
if (kCount < actual.size()) {
|
||||
return ("Differ at #" + IntToString(kCount) +
|
||||
return ("Differ at #" + std::to_string(kCount) +
|
||||
": expected at EOF, actual=" + actual[kCount]);
|
||||
} else if (actual.size() < kCount) {
|
||||
return ("Differ at #" + IntToString(kCount) + ": expected=" +
|
||||
return ("Differ at #" + std::to_string(kCount) + ": expected=" +
|
||||
expected[actual.size()] + ", actual at EOF");
|
||||
} else {
|
||||
return "";
|
||||
|
|
Loading…
Reference in New Issue