From 4c172f7ca6cff1387220696166a6e0ee9758ac98 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 10 Jun 2020 18:26:11 +0200 Subject: BLI: support constructing StringRef from start and end pointer --- source/blender/blenlib/BLI_string_ref.hh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source/blender/blenlib/BLI_string_ref.hh') diff --git a/source/blender/blenlib/BLI_string_ref.hh b/source/blender/blenlib/BLI_string_ref.hh index 8ed923068a8..073137fe175 100644 --- a/source/blender/blenlib/BLI_string_ref.hh +++ b/source/blender/blenlib/BLI_string_ref.hh @@ -229,6 +229,16 @@ class StringRef : public StringRefBase { { } + /** + * Create a StringRef from a start and end pointer. This invokes undefined behavior when the + * second point points to a smaller address than the first one. + */ + StringRef(const char *begin, const char *one_after_end) + : StringRefBase(begin, (uint)(one_after_end - begin)) + { + BLI_assert(begin <= one_after_end); + } + /** * Reference a std::string. Remember that when the std::string is destructed, the StringRef * will point to uninitialized memory. -- cgit v1.2.3