This commit is contained in:
robojumper
2025-03-31 03:34:21 +02:00
committed by GitHub
parent e85a989271
commit daadae4881
7 changed files with 127 additions and 85 deletions
+18 -14
View File
@@ -44,23 +44,27 @@ 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;
}
strncpy(mChars + destLen, src, copyLen);
// make sure string is null terminated
size_t offset = destLen + copyLen;
mChars[offset] = '\0';
append(src);
}
}
void append(const char *src) {
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;
}
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 {
return strequals(mChars, other);
}