Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-07-17 08:54:12 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-07-17 08:54:12 +0400
commit4cc93123c8120f1f52af44c18236114b5cf5d999 (patch)
treeeb09ce28e40753985cbe55085aaebae9fd24e870 /source/blender/blenlib/intern/string.c
parent49a51154970569b0154196ac25f82a9db4e712a0 (diff)
Add thousands separators to scene stats (D646)
by januz with own modifications
Diffstat (limited to 'source/blender/blenlib/intern/string.c')
-rw-r--r--source/blender/blenlib/intern/string.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index f396abbeb8d..aa705aaf63e 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -741,3 +741,38 @@ size_t BLI_str_partition_ex(const char *str, const char delim[], char **sep, cha
return strlen(str);
}
+
+/**
+ * Format ints with decimal grouping.
+ * 1000 -> 1,000
+ *
+ * \param dst The resulting string
+ * \param num Number to format
+ * \return The length of \a dst
+ */
+size_t BLI_str_format_int_grouped(char dst[16], int num)
+{
+ char src[16];
+ char *p_src = src;
+ char *p_dst = dst;
+
+ const char separator = ',';
+ int num_len, commas;
+
+ num_len = sprintf(src, "%d", num);
+
+ if (*p_src == '-') {
+ *p_dst++ = *p_src++;
+ num_len--;
+ }
+
+ for (commas = 2 - num_len % 3; *p_src; commas = (commas + 1) % 3) {
+ *p_dst++ = *p_src++;
+ if (commas == 1) {
+ *p_dst++ = separator;
+ }
+ }
+ *--p_dst = '\0';
+
+ return (size_t)(p_dst - dst);
+}