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:
Ali El Gariani 2010-05-09 19:22:42 +00:00
parent 694617b322
commit 3f105949f3
2 changed files with 11 additions and 0 deletions

View File

@ -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 == '-'));
}

View File

@ -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'.
*