Administrative source import: native x86 compilation passed for 423 authored units. Source placement and submission states are migrated separately; this commit does not imply peer acceptance.
Previous head: 35d2a8cb36
Payload SHA256: 592f016d2730c5593bb653aa054c1e5f76a6df72c8f5a09e66f74876e2e33dee
75 lines
1.6 KiB
C++
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 = std::snprintf(digits, sizeof(digits), "%lld", static_cast<long long>(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 = std::snprintf(digits, sizeof(digits), "%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;
|
|
}
|