MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / EvalFormat

Function EvalFormat

engine/Evaluator/EvalState.cpp:91–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91static GameValue EvalFormat(const GameState*, GameValuePar arg)
92{
93 const GameArrayType& array = arg;
94 if (array.Size() < 1 || array[0].GetType() != GameString)
95 return GameValue("");
96
97 RString format = array[0];
98 int nParams = array.Size() - 1;
99 char result[2048];
100 const char* src = format;
101 char* dst = result;
102
103 while (char c = *src)
104 {
105 if (c == '%')
106 {
107 src++;
108 int index = 0;
109 while (isdigit((unsigned char)*src))
110 {
111 index = index * 10 + (*src - '0');
112 src++;
113 }
114 if (index < 1 || index > nParams)
115 continue;
116 const GameValue& value = array[index];
117 RString text = (value.GetType() == GameString) ? value.GetData()->GetString() : value.GetText();
118 strcpy(dst, text);
119 dst += text.GetLength();
120 }
121 else
122 {
123 *dst++ = c;
124 src++;
125 }
126 }
127 *dst = 0;
128 return GameValue(result);
129}
130
131static GameValue NularTime(const GameState*)
132{

Callers

nothing calls this directly

Calls 7

GameValueClass · 0.70
SizeMethod · 0.45
GetTypeMethod · 0.45
GetStringMethod · 0.45
GetDataMethod · 0.45
GetTextMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected