Decompile fn_17182 (IntToSignedString)
Batch #7100 by eAthena: 0 byte-identical, 1 confirmed by peer review. - fn_17182 IntToSignedString: logic confirmed by peer review Peer-reviewed-by: Lumen, Snow, Landruca Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
This commit is contained in:
parent
b2896ee0cf
commit
f496c11050
1 changed files with 32 additions and 0 deletions
|
|
@ -103,3 +103,35 @@ std::string IntToString(int value, unsigned int digits) {
|
|||
|
||||
return text;
|
||||
}
|
||||
|
||||
// OFFSET: 0x00A95790
|
||||
// FUNCTION: fn_17182
|
||||
std::string IntToSignedString(int value, bool grouped, bool showPlus) {
|
||||
if (!grouped) {
|
||||
return IntToString(value, 0);
|
||||
}
|
||||
|
||||
const unsigned int bits = static_cast<unsigned int>(value);
|
||||
const unsigned int magnitude = value < 0 ? 0u - bits : bits;
|
||||
std::string digits = IntToString(static_cast<int>(magnitude), 0);
|
||||
std::string text;
|
||||
const bool negative = value < 0;
|
||||
for (std::size_t i = 0; i < digits.size(); ++i) {
|
||||
if ((digits.size() - i) % 3 == 0) {
|
||||
text += std::string(",");
|
||||
}
|
||||
text += digits.at(i);
|
||||
}
|
||||
|
||||
if (text.at(0) == ',') {
|
||||
text.erase(0, 1);
|
||||
}
|
||||
|
||||
if (negative) {
|
||||
text.insert(text.begin(), '-');
|
||||
} else if (showPlus && value != 0) {
|
||||
text.insert(text.begin(), '+');
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue