From 68cc982dcb7c1063a96f7ec9b7ccb95da4919d6b Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 10 Feb 2020 13:54:57 +0100 Subject: BLI: improve various C++ data structures The changes come from the `functions` branch, where I'm using these structures a lot. This also includes a new `BLI::Optional` type, which is similar to `std::Optional` which can be used when Blender starts using C++17. --- source/blender/blenlib/BLI_string_ref.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source/blender/blenlib/BLI_string_ref.h') diff --git a/source/blender/blenlib/BLI_string_ref.h b/source/blender/blenlib/BLI_string_ref.h index 76163a2754c..54c2f0e7209 100644 --- a/source/blender/blenlib/BLI_string_ref.h +++ b/source/blender/blenlib/BLI_string_ref.h @@ -109,6 +109,8 @@ class StringRefBase { * Returns true when the string ends with the given suffix. Otherwise false. */ bool endswith(StringRef suffix) const; + + StringRef substr(uint start, uint size) const; }; /** @@ -242,6 +244,12 @@ inline bool StringRefBase::endswith(StringRef suffix) const return true; } +inline StringRef StringRefBase::substr(uint start, uint size) const +{ + BLI_assert(start + size <= m_size); + return StringRef(m_data + start, size); +} + } // namespace BLI #endif /* __BLI_STRING_REF_H__ */ -- cgit v1.2.3