diff options
| author | robojumper <robojumper@gmail.com> | 2025-03-31 03:34:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-30 21:34:21 -0400 |
| commit | daadae488119c7a8cd28548e5d502abdafbf68e0 (patch) | |
| tree | baf3b22d728e066b639e8ae967aba305ef41f9d4 /include/sized_string.h | |
| parent | e85a989271d9445d4c4e1da41dfb6d90cb0652aa (diff) | |
Link d2d (#145)
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 { |
