[Bf-blender-cvs] [ee045d2] blender-v2.73-release: BLI_string_utf8: add BLI_strncpy_utf8_rlen

Campbell Barton noreply at git.blender.org
Tue Jan 6 10:56:27 CET 2015


Commit: ee045d2bd52477e9006e3cd8852826d55ff6444c
Author: Campbell Barton
Date:   Sun Dec 28 15:58:13 2014 +1100
Branches: blender-v2.73-release
https://developer.blender.org/rBee045d2bd52477e9006e3cd8852826d55ff6444c

BLI_string_utf8: add BLI_strncpy_utf8_rlen

===================================================================

M	source/blender/blenlib/BLI_string_utf8.h
M	source/blender/blenlib/intern/string_utf8.c

===================================================================

diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h
index 89754be..3e59986 100644
--- a/source/blender/blenlib/BLI_string_utf8.h
+++ b/source/blender/blenlib/BLI_string_utf8.h
@@ -34,6 +34,7 @@ extern "C" {
 #include "BLI_compiler_attrs.h"
 
 char        *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL();
+size_t       BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL();
 char        *BLI_strncat_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL();
 int          BLI_utf8_invalid_byte(const char *str, int length) ATTR_NONNULL();
 int          BLI_utf8_invalid_strip(char *str, int length) ATTR_NONNULL();
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c
index 9697fcf..ef0fcc7 100644
--- a/source/blender/blenlib/intern/string_utf8.c
+++ b/source/blender/blenlib/intern/string_utf8.c
@@ -209,6 +209,22 @@ char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t
 	return r_dst;
 }
 
+size_t BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, size_t maxncpy)
+{
+	char *r_dst = dst;
+
+	BLI_assert(maxncpy != 0);
+
+#ifdef DEBUG_STRSIZE
+	memset(dst, 0xff, sizeof(*dst) * maxncpy);
+#endif
+
+	/* note: currently we don't attempt to deal with invalid utf8 chars */
+	BLI_STR_UTF8_CPY(dst, src, maxncpy);
+
+	return (size_t)(dst - r_dst);
+}
+
 char *BLI_strncat_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy)
 {
 	while (*dst && maxncpy > 0) {




More information about the Bf-blender-cvs mailing list