Skip to content
Snippets Groups Projects
Commit a579773f authored by Robert Menzel's avatar Robert Menzel
Browse files

added function to convert an int to a string with padding (e.g. for filenames)

parent 32d9b53a
Branches
No related tags found
No related merge requests found
......@@ -48,6 +48,9 @@ namespace StringHelpers
//! strips a string of all leading and trailing characters out of a given list (but leaves the ones in between)
std::string stripOfCharacters( const std::string &_string, const std::string &_charsToStrip );
//! converts an int to a string but adds leading zeros (e.g. _maxPadding = 2, 1 -> 01)
std::string intToString( const int _number, const int _maxPadding = 0 );
//! Convert a primitive type to a string (e.g. string s = toString(1.5f)), also supports some GLM types (but not complete)
template<class T>
std::string toString(const T& _t);
......
......@@ -7,6 +7,7 @@
#include <ACGL/Utils/StringHelpers.hh>
#include <ACGL/Math/Math.hh>
#include <algorithm> // transform
#include <iomanip> // setfill
namespace ACGL{
namespace Utils{
......@@ -109,6 +110,17 @@ namespace StringHelpers
return stripOfCharacters( _string, whitespaces );
}
std::string intToString( const int _number, const int _maxPadding )
{
std::ostringstream stream;
if (_maxPadding > 0) {
stream << std::setfill('0') << std::setw(_maxPadding) << _number;
} else {
stream << _number;
}
return stream.str();
}
template<class T>
std::string toString(const T& _t)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment