From bac9a9be85fba6390623e58e502efa64d4df26ad Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Fri, 26 Sep 2025 16:47:15 +0200 Subject: [PATCH] Add comments to `String::size` to lead people to `length()` and explain the difference. # Conflicts: # core/string/ustring.h --- core/string/ustring.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/string/ustring.h b/core/string/ustring.h index 4f28d2db2ea..0340bff9f66 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -179,7 +179,10 @@ public: _FORCE_INLINE_ const T *ptr() const { return _cowdata.ptr(); } _FORCE_INLINE_ const T *get_data() const { return size() ? ptr() : &_null; } + // Returns the number of characters in the buffer, including the terminating NUL character. + // In most cases, length() should be used instead. _FORCE_INLINE_ int size() const { return _cowdata.size(); } + // Returns the number of characters in the string (excluding terminating NUL character). _FORCE_INLINE_ int length() const { return size() ? size() - 1 : 0; } _FORCE_INLINE_ bool is_empty() const { return length() == 0; } @@ -299,7 +302,10 @@ public: _FORCE_INLINE_ const char32_t *ptr() const { return _cowdata.ptr(); } _FORCE_INLINE_ const char32_t *get_data() const { return size() ? ptr() : &_null; } + // Returns the number of characters in the buffer, including the terminating NUL character. + // In most cases, length() should be used instead. _FORCE_INLINE_ int size() const { return _cowdata.size(); } + // Returns the number of characters in the string (excluding terminating NUL character). _FORCE_INLINE_ int length() const { return size() ? size() - 1 : 0; } _FORCE_INLINE_ bool is_empty() const { return length() == 0; }