Skip to content

Commit d8df20a

Browse files
committed
Merge pull request godotengine#110932 from Ivorforce/string-buffer-size-comment
Add comments to `String::size` to lead people to `length()` and explain the difference.
2 parents 9f4f16c + bac9a9b commit d8df20a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

core/string/ustring.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ class [[nodiscard]] CharStringT {
180180
_FORCE_INLINE_ const T *ptr() const { return _cowdata.ptr(); }
181181
_FORCE_INLINE_ const T *get_data() const { return size() ? ptr() : &_null; }
182182

183+
// Returns the number of characters in the buffer, including the terminating NUL character.
184+
// In most cases, length() should be used instead.
183185
_FORCE_INLINE_ int size() const { return _cowdata.size(); }
186+
// Returns the number of characters in the string (excluding terminating NUL character).
184187
_FORCE_INLINE_ int length() const { return size() ? size() - 1 : 0; }
185188
_FORCE_INLINE_ bool is_empty() const { return length() == 0; }
186189

@@ -302,7 +305,10 @@ class [[nodiscard]] String {
302305
_FORCE_INLINE_ const char32_t *ptr() const { return _cowdata.ptr(); }
303306
_FORCE_INLINE_ const char32_t *get_data() const { return size() ? ptr() : &_null; }
304307

308+
// Returns the number of characters in the buffer, including the terminating NUL character.
309+
// In most cases, length() should be used instead.
305310
_FORCE_INLINE_ int size() const { return _cowdata.size(); }
311+
// Returns the number of characters in the string (excluding terminating NUL character).
306312
_FORCE_INLINE_ int length() const { return size() ? size() - 1 : 0; }
307313
_FORCE_INLINE_ bool is_empty() const { return length() == 0; }
308314

0 commit comments

Comments
 (0)