calc: Migration to libshared
This commit is contained in:
56
src/text.cpp
56
src/text.cpp
@@ -377,59 +377,3 @@ void replace_positional (
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
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)
|
||||
{
|
||||
auto len = static_cast <int> (utf8_text_width (input));
|
||||
|
||||
if (len == width)
|
||||
return input;
|
||||
|
||||
if (len > width)
|
||||
return input.substr (0, width);
|
||||
|
||||
return input + std::string (width - utf8_text_width (input), ' ');
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string rightJustifyZero (const int input, const int width)
|
||||
{
|
||||
std::stringstream s;
|
||||
s << std::setw (width) << std::setfill ('0') << input;
|
||||
return s.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
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)
|
||||
{
|
||||
auto len = static_cast <int> (utf8_text_width (input));
|
||||
|
||||
if (len == width)
|
||||
return input;
|
||||
|
||||
if (len > width)
|
||||
return input.substr (0, width);
|
||||
|
||||
return ((width > len)
|
||||
? std::string (width - len, ' ')
|
||||
: "")
|
||||
+ input;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user