1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 21:43:06 +01:00

Move format_readable_size and format_readable_speed into Localisation

This commit is contained in:
Matt
2019-02-04 14:16:33 +01:00
parent f310fd2e07
commit 57eccef347
4 changed files with 51 additions and 53 deletions

View File

@@ -292,36 +292,6 @@ static void window_network_information_update(rct_window* w)
_networkHistory.push_back(_networkLastDeltaStats);
}
static void format_readable_size(char* buf, size_t bufSize, uint64_t bytes)
{
constexpr uint32_t SizeTable[] = { STR_SIZE_BYTE, STR_SIZE_KILOBYTE, STR_SIZE_MEGABYTE, STR_SIZE_GIGABYTE,
STR_SIZE_TERABYTE };
double size = bytes;
size_t idx = 0;
while (size >= 1024.0)
{
size /= 1024.0;
idx++;
}
char sizeType[128] = {};
format_string(sizeType, sizeof(sizeType), SizeTable[idx], nullptr);
sprintf(buf, "%.03f %s", size, sizeType);
}
static void format_readable_speed(char* buf, size_t bufSize, uint64_t bytes)
{
char sizeText[128] = {};
format_readable_size(sizeText, sizeof(sizeText), bytes);
const char* args[1] = {
sizeText,
};
format_string(buf, bufSize, STR_NETWORK_SPEED_SEC, args);
}
static void window_network_information_invalidate(rct_window* w)
{
window_network_set_pressed_tab(w);

View File

@@ -1403,6 +1403,36 @@ void format_string_to_upper(utf8* dest, size_t size, rct_string_id format, const
dest[upperString.size()] = '\0';
}
void format_readable_size(char* buf, size_t bufSize, uint64_t sizeBytes)
{
constexpr uint32_t SizeTable[] = { STR_SIZE_BYTE, STR_SIZE_KILOBYTE, STR_SIZE_MEGABYTE, STR_SIZE_GIGABYTE,
STR_SIZE_TERABYTE };
double size = sizeBytes;
size_t idx = 0;
while (size >= 1024.0)
{
size /= 1024.0;
idx++;
}
char sizeType[128] = {};
format_string(sizeType, sizeof(sizeType), SizeTable[idx], nullptr);
sprintf(buf, "%.03f %s", size, sizeType);
}
void format_readable_speed(char* buf, size_t bufSize, uint64_t sizeBytes)
{
char sizeText[128] = {};
format_readable_size(sizeText, sizeof(sizeText), sizeBytes);
const char* args[1] = {
sizeText,
};
format_string(buf, bufSize, STR_NETWORK_SPEED_SEC, args);
}
money32 string_to_money(const char* string_to_monetise)
{
const char* decimal_char = language_get_string(STR_LOCALE_DECIMAL_POINT);

View File

@@ -29,6 +29,17 @@ void format_string(char* dest, size_t size, rct_string_id format, const void* ar
void format_string_raw(char* dest, size_t size, const char* src, const void* args);
void format_string_to_upper(char* dest, size_t size, rct_string_id format, const void* args);
void generate_string_file();
/**
* Formats sizeBytes into buf as a human readable text, e.x.: "1024 MB"
*/
void format_readable_size(char* buf, size_t bufSize, uint64_t sizeBytes);
/**
* Formats sizeBytesPerSec into buf as a human readable text, e.x.: "1024 MB/sec"
*/
void format_readable_speed(char* buf, size_t bufSize, uint64_t sizeBytesPerSec);
utf8* get_string_end(const utf8* text);
size_t get_string_size(const utf8* text);
int32_t get_string_length(const utf8* text);