49 std::
string separator;
71 const
std::
string &separator);
89 ud.levels.push_back(bu);
98 ud.levels.push_back(ul);
109 const UnitLevel bu = {
"¤", 1, 0,
""};
110 ud.levels.push_back(bu);
139 ud.levels.push_back(bu);
143 if (xmlNameEqual(uLevel,
"level"))
156 ud.levels.push_back(ul);
161 logger->
log(
"Error bad unit count: %d for %s in %s",
170 const UnitLevel lev =
177 ud.levels.push_back(lev);
185 if (xmlNameEqual(node,
"unit"))
204 XmlNodeConstPtrConst root = doc.
rootNode();
206 if ((root ==
nullptr) || !xmlNameEqual(root,
"units"))
208 logger->
log(
"Error loading unit definition file: "
215 if (xmlNameEqual(node,
"include"))
222 else if (xmlNameEqual(node,
"unit"))
225 UnitDescription ud =
loadUnit(node);
226 if (type ==
"weight")
230 else if (type ==
"currency")
237 logger->
log(
"Error unknown unit type: %s", type.c_str());
240 else if (xmlNameEqual(node,
"currency"))
248 const UnitDescription &ud)
256 return strprintf(
"0%s", ul.symbol.c_str());
259 double amount = ud.conversion * value;
260 const unsigned int sz =
CAST_U32(ud.levels.size());
263 if (ud.mix && !ud.levels.empty() && ud.levels[1].count < amount)
266 UnitLevel pl = ud.levels[0];
272 levelAmount /= ul.count;
274 amount -=
static_cast<double>(levelAmount * ul.count);
279 amount), pl.separator).append(pl.symbol);
282 for (
unsigned int i = 2; i < sz; i++)
289 nextAmount = levelAmount / ul.count;
290 levelAmount %= ul.count;
296 pl.separator).append(pl.symbol).append(output);
301 levelAmount = nextAmount;
308 for (
unsigned int i = 0; i < sz; i++)
311 if (amount < ul.count && ul.count > 0)
313 ul = ud.levels[i - 1];
321 ul.separator).append(ul.symbol);
363 const std::string &separator)
365 std::string lastPart;
366 const size_t point = str.find(
'.');
367 if (point != std::string::npos)
369 lastPart = str.substr(point);
370 str = str.substr(0, point);
376 size_t sz = str.size();
381 result = std::string(separator).append(str.substr(
382 sz - 3)).append(result);
386 result = str.substr(sz - 3).append(result);
388 str = str.substr(0, str.size() - 3);
394 result = std::string(str).append(separator).append(result);
400 return result + lastPart;
static void loadXmlFile(const std::string &file, const std::string &name, BadgesInfos &arr, const SkipError skipError)
#define loadXmlDir(name, function)
#define reportAlways(...)
std::string getStringValue(const std::string &key) const
void log(const char *const log_text,...)
void log1(const char *const log_text)
const std::string DEFAULT_CURRENCY
#define for_each_xml_child_node(var, parent)
#define A_DEFAULT_COPY(func)
bool existsCurrency(const std::string &name)
std::string formatCurrency64(const int64_t value)
std::string formatCurrency(const int value)
std::string formatWeight(const int value)
void loadXmlFile(const std::string &fileName, const SkipError skipError)
int getProperty(const xmlNodePtr node, const char *const name, int def)
std::map< std::string, UnitDescription > mCurrencies
UnitDescription defaultWeight
UnitDescription defaultCurrency
const bool SkipError_false
const bool SkipError_true
std::string strprintf(const char *const format,...)
static std::string splitNumber(std::string str, const std::string &separator)
static UnitDescription loadUnit(xmlNodePtr node)
static std::string formatUnit(const int value, const UnitDescription &ud)
static void loadCurrencies(xmlNodePtr parentNode)
const bool UseVirtFs_true