MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / FormatInteger

Function FormatInteger

Source/utils/format_int.cpp:9–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7namespace devilution {
8
9std::string FormatInteger(int n)
10{
11 constexpr size_t GroupSize = 3;
12
13 char buf[40];
14 char *begin = buf;
15 const char *end = BufCopy(buf, n);
16 const size_t len = end - begin;
17
18 std::string out;
19 const size_t prefixLen = n < 0 ? 1 : 0;
20 const size_t numLen = len - prefixLen;
21 if (numLen <= GroupSize) {
22 out.append(begin, len);
23 return out;
24 }
25
26 const string_view separator = _(/* TRANSLATORS: Thousands separator */ ",");
27 out.reserve(len + separator.size() * (numLen - 1) / GroupSize);
28 if (n < 0) {
29 out += '-';
30 ++begin;
31 }
32
33 size_t mlen = numLen % GroupSize;
34 if (mlen == 0)
35 mlen = GroupSize;
36 out.append(begin, mlen);
37 begin += mlen;
38 for (; begin != end; begin += GroupSize) {
39 AppendStrView(out, separator);
40 out.append(begin, GroupSize);
41 }
42
43 return out;
44}
45
46} // namespace devilution

Callers 12

TESTFunction · 0.85
PrintSStringFunction · 0.85
DrawSTextFunction · 0.85
DrawInfoBoxFunction · 0.85
DrawGoldSplitFunction · 0.85
CheckInvHLightFunction · 0.85
GetItemStrFunction · 0.85
DrawGameFunction · 0.85
AddItemToLabelQueueFunction · 0.85
CheckXPBarInfoFunction · 0.85
DrawStashFunction · 0.85
charpanel.cppFile · 0.85

Calls 3

AppendStrViewFunction · 0.85
BufCopyFunction · 0.70
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.68