From d4e1c733756a76f817fd86b345c04ed59311ede3 Mon Sep 17 00:00:00 2001 From: Philip Liard Date: Fri, 25 Feb 2011 15:51:21 +0000 Subject: [PATCH] Adding SimpleItoa(int64). --- cpp/src/stringutil.cc | 12 +++++++++++- cpp/src/stringutil.h | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cpp/src/stringutil.cc b/cpp/src/stringutil.cc index d07b41e6f..10337a2d9 100644 --- a/cpp/src/stringutil.cc +++ b/cpp/src/stringutil.cc @@ -35,7 +35,8 @@ string operator+(const string& s, int n) { return result; } -string SimpleItoa(int n) { +template +string GenericSimpleItoa(const T& n) { stringstream ss; ss << n; @@ -45,6 +46,15 @@ string SimpleItoa(int n) { return result; } +string SimpleItoa(int n) { + return GenericSimpleItoa(n); +} + +string SimpleItoa(uint64 n) { + return GenericSimpleItoa(n); +} + + bool TryStripPrefixString(const string& in, const string& prefix, string* out) { assert(out); const bool has_prefix = in.compare(0, prefix.length(), prefix) == 0; diff --git a/cpp/src/stringutil.h b/cpp/src/stringutil.h index 69ea9ce95..fe0b641fe 100644 --- a/cpp/src/stringutil.h +++ b/cpp/src/stringutil.h @@ -20,6 +20,8 @@ #include #include +#include + namespace i18n { namespace phonenumbers { @@ -28,7 +30,8 @@ using std::string; // Support string("hello") + 10 string operator+(const string& s, int n); -// Convert integer into string +// Convert integer to string. +string SimpleItoa(uint64 n); string SimpleItoa(int n); // Return true if 'in' starts with 'prefix' and write into 'out'