(986a3bf)
Go to the source code of this file.
|
static std::string | formatUnit (const int value, const UnitDescription &ud) |
|
static std::string | splitNumber (std::string str, const std::string &separator) |
|
static UnitDescription | loadUnit (xmlNodePtr node) |
|
static void | loadCurrencies (xmlNodePtr parentNode) |
|
◆ formatUnit()
static std::string formatUnit |
( |
const int |
value, |
|
|
const UnitDescription & |
ud |
|
) |
| |
|
static |
Definition at line 247 of file unitsdb.cpp.
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);
std::string strprintf(const char *const format,...)
static std::string splitNumber(std::string str, const std::string &separator)
References CAST_S32, CAST_U32, splitNumber(), and strprintf().
Referenced by UnitsDb::formatCurrency(), UnitsDb::formatCurrency64(), and UnitsDb::formatWeight().
◆ loadCurrencies()
static void loadCurrencies |
( |
xmlNodePtr |
parentNode | ) |
|
|
static |
Definition at line 181 of file unitsdb.cpp.
185 if (xmlNameEqual(node,
"unit"))
#define reportAlways(...)
const std::string DEFAULT_CURRENCY
#define for_each_xml_child_node(var, parent)
int getProperty(const xmlNodePtr node, const char *const name, int def)
std::map< std::string, UnitDescription > mCurrencies
UnitDescription defaultCurrency
static UnitDescription loadUnit(xmlNodePtr node)
References DEFAULT_CURRENCY, anonymous_namespace{unitsdb.cpp}::defaultCurrency, for_each_xml_child_node, XML::getProperty(), loadUnit(), anonymous_namespace{unitsdb.cpp}::mCurrencies, and reportAlways.
Referenced by UnitsDb::loadXmlFile().
◆ loadUnit()
static UnitDescription loadUnit |
( |
xmlNodePtr |
node | ) |
|
|
static |
◆ splitNumber()
static std::string splitNumber |
( |
std::string |
str, |
|
|
const std::string & |
separator |
|
) |
| |
|
static |
Definition at line 362 of file unitsdb.cpp.
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;
References STD_MOVE.
Referenced by formatUnit().