From f9404d5cb7689925b5134e89835712c6b3400631 Mon Sep 17 00:00:00 2001 From: Sascha Volkenandt Date: Fri, 5 Jan 2007 22:14:24 +0000 Subject: - added function StringToInt --- tools.cpp | 9 +++++++++ tools.h | 1 + 2 files changed, 10 insertions(+) diff --git a/tools.cpp b/tools.cpp index 6531cd8..e135c0b 100644 --- a/tools.cpp +++ b/tools.cpp @@ -49,4 +49,13 @@ vector< string > StringSplit( string const& text, char delimiter ) return result; } +int StringToInt( std::string const& string, int base ) +{ + char* end; + int result = strtol( string.c_str(), &end, base ); + if ( *end == '\0' ) + return result; + return 0; +} + } diff --git a/tools.h b/tools.h index 0c98fed..7db052e 100644 --- a/tools.h +++ b/tools.h @@ -13,6 +13,7 @@ namespace vdrlive { std::string FormatDateTime( char const* format, time_t time ); std::string StringReplace( std::string const& text, std::string const& substring, std::string const& replacement ); std::vector< std::string > StringSplit( std::string const& text, char delimiter ); +int StringToInt( std::string const& string, int base = 10 ); struct bad_lexical_cast: std::runtime_error { -- cgit v1.2.3