rodecomp/Source/Utility/Text/GroupedInteger.cpp
ragnarok-clanker 1b3f943b32 Decompile fn_18263 (?GroupDigits@?A0xcfd8b2e7@@YAXPBDHPADH@Z)
Batch #11402 by Yommy: 1 byte-identical, 0 confirmed by peer review.

- fn_18263 ?GroupDigits@?A0xcfd8b2e7@@YAXPBDHPADH@Z: byte-identical

Merged automatically: every function is byte-identical to the original.
2026-11-05 00:02:23 +00:00

73 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;
}
int phase = 3 * (length / 3) - length + 2;
for (int index = written; digits[index] != '\0'; phase = (phase + 1) % 3) {
if (capacity <= written) {
break;
}
output[written++] = digits[index++];
if (phase == 1) {
if (capacity <= written) {
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;
}