From 6f7aacd16fd02e0b572f06cfdce21d9ed02f335c Mon Sep 17 00:00:00 2001
From: Norihiro Watanabe <norihiro.watanabe@ufz.de>
Date: Thu, 16 Oct 2014 11:52:53 +0200
Subject: [PATCH] add padLeft() to StringTools

---
 BaseLib/StringTools.cpp | 12 +++++++++++-
 BaseLib/StringTools.h   |  5 +++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/BaseLib/StringTools.cpp b/BaseLib/StringTools.cpp
index 7acb1e4913e..738af0fcd30 100644
--- a/BaseLib/StringTools.cpp
+++ b/BaseLib/StringTools.cpp
@@ -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
diff --git a/BaseLib/StringTools.h b/BaseLib/StringTools.h
index 1754f50d087..9a9411007df 100644
--- a/BaseLib/StringTools.h
+++ b/BaseLib/StringTools.h
@@ -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
-- 
GitLab