diff options
Diffstat (limited to 'include/sized_string.h')
| -rw-r--r-- | include/sized_string.h | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/include/sized_string.h b/include/sized_string.h index 64b01a5a..c0670728 100644 --- a/include/sized_string.h +++ b/include/sized_string.h @@ -44,21 +44,25 @@ struct SizedString { void operator+=(const char *src) { if (src != nullptr) { - size_t destLen = strlen(mChars); - size_t copyLen = strlen(src); - - // Make sure copy length isnt more than destination length - if (destLen + copyLen + 1 >= Size) { - size_t tmpLen = Size - destLen; - copyLen = tmpLen - 1; - } + append(src); + } + } - strncpy(mChars + destLen, src, copyLen); + void append(const char *src) { + size_t destLen = strlen(mChars); + size_t copyLen = strlen(src); - // make sure string is null terminated - size_t offset = destLen + copyLen; - mChars[offset] = '\0'; + // Make sure copy length isnt more than destination length + if (destLen + copyLen + 1 >= Size) { + size_t tmpLen = Size - destLen; + copyLen = tmpLen - 1; } + + strncpy(mChars + destLen, src, copyLen); + + // make sure string is null terminated + size_t offset = destLen + copyLen; + mChars[offset] = '\0'; } bool operator==(const char *other) const { |
