Skip to content

Commit 0d4fe7b

Browse files
committed
Add set functions too
1 parent 3101971 commit 0d4fe7b

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

Core/GameEngine/Include/Common/AsciiString.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,20 @@ class AsciiString
206206
refcount.)
207207
*/
208208
void set(const AsciiString& stringSrc);
209+
209210
/**
210211
Replace the contents of self with the given string.
211212
Note that a copy of the string is made; the input ptr is not saved.
212213
*/
213214
void set(const char* s);
214215

216+
/**
217+
Replace the contents of self with the given string and length.
218+
Note that a copy of the string is made; the input ptr is not saved.
219+
The length must not be larger than the actual string length.
220+
*/
221+
void set(const char* s, int len);
222+
215223
/**
216224
replace contents of self with the given string. Note the
217225
nomenclature is translate rather than set; this is because

Core/GameEngine/Include/Common/UnicodeString.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,20 @@ class UnicodeString
206206
refcount.)
207207
*/
208208
void set(const UnicodeString& stringSrc);
209+
209210
/**
210211
Replace the contents of self with the given string.
211212
Note that a copy of the string is made; the input ptr is not saved.
212213
*/
213214
void set(const WideChar* s);
214215

216+
/**
217+
Replace the contents of self with the given string and length.
218+
Note that a copy of the string is made; the input ptr is not saved.
219+
The length must not be larger than the actual string length.
220+
*/
221+
void set(const WideChar* s, int len);
222+
215223
/**
216224
replace contents of self with the given string. Note the
217225
nomenclature is translate rather than set; this is because

Core/GameEngine/Source/Common/System/AsciiString.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,18 @@ void AsciiString::set(const AsciiString& stringSrc)
235235

236236
// -----------------------------------------------------
237237
void AsciiString::set(const char* s)
238+
{
239+
int len = s ? strlen(s) : 0;
240+
set(s, len);
241+
}
242+
243+
// -----------------------------------------------------
244+
void AsciiString::set(const char* s, int len)
238245
{
239246
validate();
240247
if (!m_data || s != peek())
241248
{
242-
int len = s ? strlen(s) : 0;
243-
if (len)
249+
if (len > 0)
244250
{
245251
ensureUniqueBufferOfSize(len + 1, false, s, NULL);
246252
}

Core/GameEngine/Source/Common/System/UnicodeString.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,18 @@ void UnicodeString::set(const UnicodeString& stringSrc)
184184

185185
// -----------------------------------------------------
186186
void UnicodeString::set(const WideChar* s)
187+
{
188+
int len = s ? wcslen(s) : 0;
189+
set(s, len);
190+
}
191+
192+
// -----------------------------------------------------
193+
void UnicodeString::set(const WideChar* s, int len)
187194
{
188195
validate();
189196
if (!m_data || s != peek())
190197
{
191-
int len = s ? wcslen(s) : 0;
192-
if (len)
198+
if (len > 0)
193199
{
194200
ensureUniqueBufferOfSize(len + 1, false, s, NULL);
195201
}

0 commit comments

Comments
 (0)