From 00197a668b3463ff050d224967407241a98486cb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 28 Dec 2014 15:58:13 +1100 Subject: [PATCH] BLI_string_utf8: add BLI_strncpy_utf8_rlen --- source/blender/blenlib/BLI_string_utf8.h | 1 + source/blender/blenlib/intern/string_utf8.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index 89754be25ba..3e599865416 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 9697fcf09e9..ef0fcc7f1e3 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) {