2018-08-02 13:06:37 +02:00
|
|
|
#include "utils.h"
|
|
|
|
|
2019-10-07 14:08:01 +02:00
|
|
|
#include <algorithm>
|
2018-08-02 13:06:37 +02:00
|
|
|
#include <iomanip>
|
|
|
|
#include <numeric>
|
|
|
|
|
|
|
|
std::string formatCentAsEuroString(const int cent, int width)
|
|
|
|
{
|
|
|
|
std::stringstream currStream;
|
|
|
|
|
|
|
|
try {
|
|
|
|
std::locale myLocale("de_DE.utf8");
|
|
|
|
currStream.imbue(myLocale);
|
|
|
|
currStream << std::right << std::setw(width) << std::showbase
|
|
|
|
<< std::put_money(cent, false);
|
|
|
|
} catch (std::runtime_error& err) {
|
2018-08-08 15:55:35 +02:00
|
|
|
currStream << std::fixed << std::setw(width >= 4 ? width - 4 : width)
|
|
|
|
<< std::setprecision(2) << cent / 100.0L << " €";
|
2018-08-02 13:06:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return currStream.str();
|
2018-08-08 09:25:37 +02:00
|
|
|
}
|
2018-08-08 15:55:35 +02:00
|
|
|
|
2019-02-25 08:57:10 +01:00
|
|
|
std::string& ltrim(std::string& str, const std::string& chars)
|
|
|
|
{
|
|
|
|
str.erase(0, str.find_first_not_of(chars));
|
|
|
|
return str;
|
|
|
|
}
|
2019-10-07 14:08:01 +02:00
|
|
|
|
2019-02-25 08:57:10 +01:00
|
|
|
std::string& rtrim(std::string& str, const std::string& chars)
|
|
|
|
{
|
|
|
|
str.erase(str.find_last_not_of(chars) + 1);
|
|
|
|
return str;
|
|
|
|
}
|
2019-10-07 14:08:01 +02:00
|
|
|
|
2019-02-25 08:57:10 +01:00
|
|
|
std::string& trim(std::string& str, const std::string& chars)
|
|
|
|
{
|
|
|
|
return ltrim(rtrim(str, chars), chars);
|
2019-09-26 16:41:39 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 14:08:01 +02:00
|
|
|
bool case_insensitive_match(std::string s1, std::string s2)
|
|
|
|
{
|
|
|
|
// convert s1 and s2 into lower case strings
|
|
|
|
transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
|
|
|
|
transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
|
|
|
|
if (s1.compare(s2) == 0)
|
|
|
|
return true; // The strings are same
|
|
|
|
return false; // not matched
|
2019-10-10 08:09:16 +02:00
|
|
|
}
|