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

Method Encode

src/script/api/script_text.cpp:222–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222void ScriptText::ParamCheck::Encode(StringBuilder &builder, std::string_view cmd)
223{
224 if (this->cmd.empty()) this->cmd = cmd;
225 if (this->used) return;
226
227 struct visitor {
228 StringBuilder &builder;
229
230 void operator()(const std::monostate &) { }
231
232 void operator()(std::string value)
233 {
234 this->builder.PutUtf8(SCC_ENCODED_STRING);
235 StrMakeValidInPlace(value, {StringValidationSetting::ReplaceWithQuestionMark, StringValidationSetting::AllowNewline, StringValidationSetting::ReplaceTabCrNlWithSpace});
236 this->builder.Put(value);
237 }
238
239 void operator()(const SQInteger &value)
240 {
241 this->builder.PutUtf8(SCC_ENCODED_NUMERIC);
242 /* Sign-extend the value, then store as unsigned */
243 this->builder.PutIntegerBase<uint64_t>(static_cast<uint64_t>(static_cast<int64_t>(value)), 16);
244 }
245
246 void operator()(const ScriptTextRef &value)
247 {
248 this->builder.PutUtf8(SCC_ENCODED);
249 this->builder.PutIntegerBase(value->string.base(), 16);
250 }
251 };
252
253 builder.PutUtf8(SCC_RECORD_SEPARATOR);
254 std::visit(visitor{builder}, *this->param);
255 this->used = true;
256}
257
258void ScriptText::_GetEncodedText(StringBuilder &builder, int &param_count, ParamSpan args, bool first)
259{

Callers 1

_GetEncodedTextMethod · 0.45

Calls 2

PutUtf8Method · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected