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:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user