summaryrefslogtreecommitdiff
path: root/include/sized_string.h
diff options
context:
space:
mode:
authorrobojumper <robojumper@gmail.com>2025-03-31 03:34:21 +0200
committerGitHub <noreply@github.com>2025-03-30 21:34:21 -0400
commitdaadae488119c7a8cd28548e5d502abdafbf68e0 (patch)
treebaf3b22d728e066b639e8ae967aba305ef41f9d4 /include/sized_string.h
parente85a989271d9445d4c4e1da41dfb6d90cb0652aa (diff)
Link d2d (#145)
Diffstat (limited to 'include/sized_string.h')
-rw-r--r--include/sized_string.h28
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 {