rodecomp/Source/Utility/Text/GroupedInteger.cpp
ragnarok-clanker fa710d95fa Decompile 2 functions in Source/Utility/Text/GroupedInteger.cpp
Batch #11058 by cremane: 2 byte-identical, 0 confirmed by peer review.

- fn_18249 FormatGroupedInteger: byte-identical
- fn_18250 FormatGroupedInteger: byte-identical

Peer-reviewed-by: Yommy, dori, StrawberrysherbetIX
Merged automatically: every function is byte-identical to the original.
2026-11-04 23:19:10 +00:00

75 lines
1.6 KiB
C++

#include "Utility/Text/GroupedInteger.h"
#include <cstdio>
#include <cstring>
namespace {
// OFFSET: 0x00AF8730
// FUNCTION: fn_18263
void GroupDigits(const char* digits, int length, char* output, int capacity) {
int written = 0;
if (digits[0] == '-') {
written = 1;
output[0] = '-';
--length;
}
const char* next = digits + written;
int phase = 3 * (length / 3) - length + 2;
for (; *next != '\0'; phase = (phase + 1) % 3) {
if (written >= capacity) {
break;
}
output[written++] = *next++;
if (phase == 1) {
if (written >= capacity) {
break;
}
output[written++] = ',';
}
}
output[written - 1] = '\0';
}
}
// OFFSET: 0x00AF60E0
// FUNCTION: fn_18249
char* FormatGroupedInteger(std::int64_t value, char* output, int capacity) {
if (output && capacity > 0) {
char digits[32];
const int length = _snprintf_s(digits, _TRUNCATE, "%I64d", value);
GroupDigits(digits, length, output, capacity);
}
return output;
}
// OFFSET: 0x00AF6140
// FUNCTION: fn_18250
char* FormatGroupedInteger(int value, char* output, int capacity) {
if (output && capacity > 0) {
char digits[32];
const int length = _snprintf_s(digits, _TRUNCATE, "%d", value);
GroupDigits(digits, length, output, capacity);
}
return output;
}
// OFFSET: 0x00AF82D0
// FUNCTION: fn_18262
const char* ReverseFindChar(const char* text, char target) {
for (const char* current = text + std::strlen(text) - 1; current >= text; --current) {
if (*current == target) {
return current;
}
}
return nullptr;
}