Skip to content

Commit 45a02a4

Browse files
authored
tweak(string): Implement functions in AsciiString, UnicodeString to return the byte count of the contained string (#1407)
1 parent f70794d commit 45a02a4

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Core/GameEngine/Include/Common/AsciiString.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,14 @@ class AsciiString
154154
~AsciiString();
155155

156156
/**
157-
Return the length, in characters (not bytes!), of the string.
157+
Return the length, in characters, of the string up to the first zero or null terminator.
158158
*/
159159
int getLength() const;
160+
161+
/**
162+
Return the number of bytes used by the string up to the first zero or null terminator.
163+
*/
164+
int getByteCount() const;
160165
/**
161166
Return true iff the length of the string is zero. Equivalent
162167
to (getLength() == 0) but slightly more efficient.
@@ -391,6 +396,13 @@ inline int AsciiString::getLength() const
391396
return m_data ? strlen(peek()) : 0;
392397
}
393398

399+
// -----------------------------------------------------
400+
inline int AsciiString::getByteCount() const
401+
{
402+
validate();
403+
return m_data ? getLength() : 0;
404+
}
405+
394406
// -----------------------------------------------------
395407
inline Bool AsciiString::isEmpty() const
396408
{

Core/GameEngine/Include/Common/UnicodeString.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,14 @@ class UnicodeString
154154
~UnicodeString();
155155

156156
/**
157-
Return the length, in characters (not bytes!), of the string.
157+
Return the length, in characters, of the string up to the first zero or null terminator.
158158
*/
159159
int getLength() const;
160+
161+
/**
162+
Return the number of bytes used by the string up to the first zero or null terminator.
163+
*/
164+
int getByteCount() const;
160165
/**
161166
Return true iff the length of the string is zero. Equivalent
162167
to (getLength() == 0) but slightly more efficient.
@@ -341,6 +346,13 @@ inline int UnicodeString::getLength() const
341346
return m_data ? wcslen(peek()) : 0;
342347
}
343348

349+
// -----------------------------------------------------
350+
inline int UnicodeString::getByteCount() const
351+
{
352+
validate();
353+
return m_data ? getLength() * sizeof(WideChar) : 0;
354+
}
355+
344356
// -----------------------------------------------------
345357
inline Bool UnicodeString::isEmpty() const
346358
{

0 commit comments

Comments
 (0)