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:
Diffstat (limited to 'source/blender/blenlib/intern/string.c')
-rw-r--r--source/blender/blenlib/intern/string.c63
1 files changed, 50 insertions, 13 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 66b9cee50c3..a92b226d033 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -35,6 +35,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
+#include <inttypes.h>
#include "MEM_guardedalloc.h"
@@ -779,6 +780,21 @@ void BLI_str_toupper_ascii(char *str, const size_t len)
}
/**
+ * Strip whitespace from end of the string.
+ */
+void BLI_str_rstrip(char *str)
+{
+ for (int i = (int)strlen(str) - 1; i > 0; i--) {
+ if (isspace(str[i])) {
+ str[i] = '\0';
+ }
+ else {
+ break;
+ }
+ }
+}
+
+/**
* Strip trailing zeros from a float, eg:
* 0.0000 -> 0.0
* 2.0010 -> 2.001
@@ -960,24 +976,13 @@ size_t BLI_str_partition_ex(
return end ? (size_t)(end - str) : 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)
+static size_t BLI_str_format_int_grouped_ex(char src[16], char dst[16], int num_len)
{
- char src[16];
char *p_src = src;
char *p_dst = dst;
const char separator = ',';
- int num_len, commas;
-
- num_len = sprintf(src, "%d", num);
+ int commas;
if (*p_src == '-') {
*p_dst++ = *p_src++;
@@ -996,6 +1001,38 @@ size_t BLI_str_format_int_grouped(char dst[16], int num)
}
/**
+ * 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];
+ int num_len = sprintf(src, "%d", num);
+
+ return BLI_str_format_int_grouped_ex(src, dst, num_len);
+}
+
+/**
+ * Format uint64_t 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_uint64_grouped(char dst[16], uint64_t num)
+{
+ char src[16];
+ int num_len = sprintf(src, "%"PRIu64"", num);
+
+ return BLI_str_format_int_grouped_ex(src, dst, num_len);
+}
+
+/**
* Format a size in bytes using binary units.
* 1000 -> 1 KB
* Number of decimal places grows with the used unit (e.g. 1.5 MB, 1.55 GB, 1.545 TB).