Codechange: add method for reading a string from a savegame given a length

This commit is contained in:
Rubidium 2025-01-19 23:19:52 +01:00 committed by rubidium42
parent f90fa2a4d1
commit 83479a4e12
2 changed files with 14 additions and 2 deletions

View File

@ -928,6 +928,18 @@ static void FixSCCEncoded(std::string &str)
}
}
/**
* Read the given amount of bytes from the buffer into the string.
* @param str The string to write to.
* @param length The amount of bytes to read into the string.
* @note Does not perform any validation on validity of the string.
*/
void SlReadString(std::string &str, size_t length)
{
str.resize(length);
SlCopyBytes(str.data(), length);
}
/**
* Save/Load a \c std::string.
* @param ptr the string being manipulated
@ -953,8 +965,7 @@ static void SlStdString(void *ptr, VarType conv)
return;
}
str->resize(len);
SlCopyBytes(str->data(), len);
SlReadString(*str, len);
StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK;
if ((conv & SLF_ALLOW_CONTROL) != 0) {

View File

@ -1328,6 +1328,7 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld);
size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
uint8_t SlReadByte();
void SlReadString(std::string &str, size_t length);
void SlWriteByte(uint8_t b);
void SlGlobList(const SaveLoadTable &slt);