Enhancement

- Added integer versions of leftJustify, rightJustify.
This commit is contained in:
Paul Beckingham 2011-04-29 01:01:08 -04:00
parent d0a91acf28
commit 937f2d9c8f
3 changed files with 31 additions and 1 deletions

View file

@ -28,6 +28,7 @@
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <strings.h>
@ -715,12 +716,29 @@ std::string format (double value, int width, int precision)
return s.str ();
}
////////////////////////////////////////////////////////////////////////////////
std::string leftJustify (const int input, const int width)
{
std::stringstream s;
s << input;
std::string output = s.str ();
return output + std::string (width - output.length (), ' ');
}
////////////////////////////////////////////////////////////////////////////////
std::string leftJustify (const std::string& input, const int width)
{
return input + std::string (width - input.length (), ' ');
}
////////////////////////////////////////////////////////////////////////////////
std::string rightJustify (const int input, const int width)
{
std::stringstream s;
s << std::setw (width) << std::setfill (' ') << input;
return s.str ();
}
////////////////////////////////////////////////////////////////////////////////
std::string rightJustify (const std::string& input, const int width)
{

View file

@ -66,7 +66,9 @@ std::string format (int);
std::string formatHex (int);
std::string format (float, int, int);
std::string format (double, int, int);
std::string leftJustify (const int, const int);
std::string leftJustify (const std::string&, const int);
std::string rightJustify (const int, const int);
std::string rightJustify (const std::string&, const int);
// UTF-8 aware.