diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 78b1d689781..dbd2deb7cb6 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -21,6 +21,9 @@ /* Buffer size of maximum `uint64` plus commas and terminator. */ #define BLI_STR_FORMAT_UINT64_GROUPED_SIZE 27 +/* Buffer size of maximum `int64` plus commas and terminator. */ +#define BLI_STR_FORMAT_INT64_GROUPED_SIZE 28 + /* Buffer size of maximum `int32` with commas and terminator. */ #define BLI_STR_FORMAT_INT32_GROUPED_SIZE 15 @@ -301,6 +304,8 @@ size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], i */ size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE], uint64_t num) ATTR_NONNULL(1); +size_t BLI_str_format_int64_grouped(char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE], int64_t num) + ATTR_NONNULL(1); /** * Format a size in bytes using binary units. * 1000 -> 1 KB diff --git a/source/blender/blenlib/intern/string.cc b/source/blender/blenlib/intern/string.cc index 5b3af4adb86..18e8ab5152d 100644 --- a/source/blender/blenlib/intern/string.cc +++ b/source/blender/blenlib/intern/string.cc @@ -1192,6 +1192,18 @@ size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE return BLI_str_format_int_grouped_ex(src, dst, num_len); } +size_t BLI_str_format_int64_grouped(char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE], int64_t num) +{ + const size_t dst_maxncpy = BLI_STR_FORMAT_INT64_GROUPED_SIZE; + BLI_string_debug_size(dst, dst_maxncpy); + UNUSED_VARS_NDEBUG(dst_maxncpy); + + char src[BLI_STR_FORMAT_INT64_GROUPED_SIZE]; + const int num_len = int(SNPRINTF(src, "%" PRId64 "", num)); + + return BLI_str_format_int_grouped_ex(src, dst, num_len); +} + void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE], long long int bytes, const bool base_10) diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc index 76ea78ed0c5..cc73737a126 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc @@ -390,7 +390,9 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer { break; } default: { - value_str = fmt::format(std::locale("en_US.UTF-8"), "{:L}", value); + char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE]; + BLI_str_format_int64_grouped(dst, value); + value_str = dst; break; } } @@ -408,8 +410,9 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer { UI_but_func_tooltip_set( but, [](bContext * /*C*/, void *argN, const StringRef /*tip*/) { - return fmt::format( - std::locale("en_US.UTF-8"), "{:L} {}", *((int64_t *)argN), TIP_("bytes")); + char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE]; + BLI_str_format_int64_grouped(dst, *(int64_t *)argN); + return fmt::format("{} {}", dst, TIP_("bytes")); }, MEM_dupallocN(__func__, value), MEM_freeN); @@ -593,8 +596,9 @@ float ColumnValues::fit_column_values_width_px(const std::optional &max max_sample_size, data_.typed(), [](const int64_t value) { - return fmt::format( - std::locale("en_US.UTF-8"), "{:L}", value); + char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE]; + BLI_str_format_int64_grouped(dst, value); + return std::string(dst); }); } case SPREADSHEET_VALUE_TYPE_FLOAT: {