mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-15 17:25:32 +00:00
Add an utility function to render signed percentage.
Using Unicode minus and +0% convention (to indicate that it's not an "empty" 0%)
This commit is contained in:
parent
694617b322
commit
3f105949f3
@ -249,6 +249,14 @@ bool string_bool(const std::string& str, bool def) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string signed_percent(int val)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
//NOTE: "−" is the Unicode minus
|
||||
oss << (val >= 0 ? "+" : "−") << abs(val) << "%";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
static bool is_username_char(char c) {
|
||||
return ((c == '_') || (c == '-'));
|
||||
}
|
||||
|
@ -129,6 +129,9 @@ std::string &strip(std::string &str);
|
||||
/** Convert no, false, off, 0, 0.0 to false, empty to def, and others to true */
|
||||
bool string_bool(const std::string& str,bool def=false);
|
||||
|
||||
/** Convert number into percentage (using the Unicode "−" and +0% convention */
|
||||
std::string signed_percent(int val);
|
||||
|
||||
/**
|
||||
* Try to complete the last word of 'text' with the 'wordlist'.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user