mirror of https://github.com/OpenTTD/OpenTTD
Codechange: add method for reading a string from a savegame given a length
parent
f90fa2a4d1
commit
83479a4e12
|
@ -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.
|
* Save/Load a \c std::string.
|
||||||
* @param ptr the string being manipulated
|
* @param ptr the string being manipulated
|
||||||
|
@ -953,8 +965,7 @@ static void SlStdString(void *ptr, VarType conv)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
str->resize(len);
|
SlReadString(*str, len);
|
||||||
SlCopyBytes(str->data(), len);
|
|
||||||
|
|
||||||
StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK;
|
StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK;
|
||||||
if ((conv & SLF_ALLOW_CONTROL) != 0) {
|
if ((conv & SLF_ALLOW_CONTROL) != 0) {
|
||||||
|
|
|
@ -1328,6 +1328,7 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld);
|
||||||
size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
|
size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
|
||||||
|
|
||||||
uint8_t SlReadByte();
|
uint8_t SlReadByte();
|
||||||
|
void SlReadString(std::string &str, size_t length);
|
||||||
void SlWriteByte(uint8_t b);
|
void SlWriteByte(uint8_t b);
|
||||||
|
|
||||||
void SlGlobList(const SaveLoadTable &slt);
|
void SlGlobList(const SaveLoadTable &slt);
|
||||||
|
|
Loading…
Reference in New Issue