MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / SlStdString

Function SlStdString

src/saveload/saveload.cpp:1050–1091  ·  view source on GitHub ↗

* Save/Load a \c std::string. * @param ptr the string being manipulated * @param conv must be SLE_FILE_STRING */

Source from the content-addressed store, hash-verified

1048 * @param conv must be SLE_FILE_STRING
1049 */
1050static void SlStdString(void *ptr, VarType conv)
1051{
1052 std::string *str = reinterpret_cast<std::string *>(ptr);
1053
1054 switch (_sl.action) {
1055 case SLA_SAVE: {
1056 size_t len = str->length();
1057 SlWriteArrayLength(len);
1058 SlCopyBytes(const_cast<void *>(static_cast<const void *>(str->data())), len);
1059 break;
1060 }
1061
1062 case SLA_LOAD_CHECK:
1063 case SLA_LOAD: {
1064 size_t len = SlReadArrayLength();
1065 if (GetVarMemType(conv) == SLE_VAR_NULL) {
1066 SlSkipBytes(len);
1067 return;
1068 }
1069
1070 SlReadString(*str, len);
1071
1072 StringValidationSettings settings = StringValidationSetting::ReplaceWithQuestionMark;
1073 if ((conv & SLF_ALLOW_CONTROL) != 0) {
1074 settings.Set(StringValidationSetting::AllowControlCode);
1075 if (IsSavegameVersionBefore(SLV_ENCODED_STRING_FORMAT)) FixSCCEncoded(*str, IsSavegameVersionBefore(SLV_169));
1076 if (IsSavegameVersionBefore(SLV_FIX_SCC_ENCODED_NEGATIVE)) FixSCCEncodedNegative(*str);
1077 }
1078 if ((conv & SLF_ALLOW_NEWLINE) != 0) {
1079 settings.Set(StringValidationSetting::AllowNewline);
1080 }
1081 if ((conv & SLF_REPLACE_TABCRLF) != 0) {
1082 settings.Set(StringValidationSetting::ReplaceTabCrNlWithSpace);
1083 }
1084 StrMakeValidInPlace(*str, settings);
1085 }
1086
1087 case SLA_PTRS: break;
1088 case SLA_NULL: break;
1089 default: NOT_REACHED();
1090 }
1091}
1092
1093/**
1094 * Internal function to save/Load a list of SL_VARs.

Callers 3

SlSaveLoadMemberMethod · 0.85
SlObjectMemberFunction · 0.85
SlTableHeaderFunction · 0.85

Calls 13

SlWriteArrayLengthFunction · 0.85
SlCopyBytesFunction · 0.85
SlReadArrayLengthFunction · 0.85
GetVarMemTypeFunction · 0.85
SlSkipBytesFunction · 0.85
SlReadStringFunction · 0.85
IsSavegameVersionBeforeFunction · 0.85
FixSCCEncodedFunction · 0.85
FixSCCEncodedNegativeFunction · 0.85
StrMakeValidInPlaceFunction · 0.85
NOT_REACHEDFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected