Skip to content
Snippets Groups Projects
Commit 6f7aacd1 authored by Norihiro Watanabe's avatar Norihiro Watanabe
Browse files

add padLeft() to StringTools

parent 7bea8d2b
No related branches found
No related tags found
No related merge requests found
......@@ -12,13 +12,15 @@
*
*/
#include "StringTools.h"
#include <algorithm>
#include <cctype>
#include <iomanip>
// ThirdParty/logog
#include "logog/include/logog.hpp"
#include "StringTools.h"
namespace BaseLib
{
......@@ -75,6 +77,14 @@ std::string stringToUpper(std::string const& str)
std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) std::toupper);
return s;
}
std::string padLeft(std::string const& str, int maxlen, char ch)
{
std::stringstream ss(str);
ss << std::right << std::setw(maxlen) << std::setfill(ch) << str;
return ss.str();
}
} // end namespace BaseLib
#ifdef MSVC
......
......@@ -74,6 +74,11 @@ void simplify(std::string &str);
*/
std::string stringToUpper(std::string const& str);
/**
* Returns the string which is right aligned with padding on the left.
*/
std::string padLeft(std::string const& str, int maxlen, char ch=' ');
} // end namespace BaseLib
#ifdef MSVC
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment