Skip to content

Commit bac9a9b

Browse files
committed
Add comments to String::size to lead people to length() and explain the difference.
# Conflicts: # core/string/ustring.h
1 parent d705613 commit bac9a9b

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
@@ -179,7 +179,10 @@ class [[nodiscard]] CharStringT {
179179
_FORCE_INLINE_ const T *ptr() const { return _cowdata.ptr(); }
180180
_FORCE_INLINE_ const T *get_data() const { return size() ? ptr() : &_null; }
181181

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

@@ -299,7 +302,10 @@ class [[nodiscard]] String {
299302
_FORCE_INLINE_ const char32_t *ptr() const { return _cowdata.ptr(); }
300303
_FORCE_INLINE_ const char32_t *get_data() const { return size() ? ptr() : &_null; }
301304

305+
// Returns the number of characters in the buffer, including the terminating NUL character.
306+
// In most cases, length() should be used instead.
302307
_FORCE_INLINE_ int size() const { return _cowdata.size(); }
308+
// Returns the number of characters in the string (excluding terminating NUL character).
303309
_FORCE_INLINE_ int length() const { return size() ? size() - 1 : 0; }
304310
_FORCE_INLINE_ bool is_empty() const { return length() == 0; }
305311

0 commit comments

Comments
 (0)