MCPcopy Create free account
hub / github.com/demoth/jake2 / MacroExpandString

Method MacroExpandString

qcommon/src/main/java/jake2/qcommon/exec/Cmd.java:139–190  ·  view source on GitHub ↗

Cmd_MacroExpandString.

(String text)

Source from the content-addressed store, hash-verified

137 * Cmd_MacroExpandString.
138 */
139 public static String MacroExpandString(String text) {
140
141 boolean inquote = false;
142
143 if (text.length() >= Defines.MAX_STRING_CHARS) {
144 Com.Printf("Line exceeded " + Defines.MAX_STRING_CHARS
145 + " chars, discarded.\n");
146 return null;
147 }
148
149 int expanded = 0;
150 StringBuilder result = new StringBuilder();
151 for (int i = 0; i < text.length(); i++) {
152 if (text.charAt(i) == '"')
153 inquote = !inquote;
154
155 if (inquote) {
156 result.append(text.charAt(i));
157 continue; // don't expand inside quotes
158 }
159
160 if (text.charAt(i) != '$') {
161 result.append(text.charAt(i));
162 continue;
163 }
164
165 // scan out the complete macro, without $
166 String token = Com.Parse(new Com.ParseHelp(text, i + 1));
167
168 i += token.length();
169 token = Cvar.getInstance().VariableString(token);
170 result.append(token);
171
172 if (result.length() >= Defines.MAX_STRING_CHARS) {
173 Com.Printf("Expanded line exceeded " + Defines.MAX_STRING_CHARS
174 + " chars, discarded.\n");
175 return null;
176 }
177
178 if (++expanded == 100) {
179 Com.Printf("Macro expansion loop, discarded.\n");
180 return null;
181 }
182 }
183
184 if (inquote) {
185 Com.Printf("Line has unmatched quote, discarded.\n");
186 return null;
187 }
188
189 return result.toString();
190 }
191
192 /**
193 * Cmd_TokenizeString

Callers 3

testExpandMacroMethod · 0.95
testExpandMacroMiddleMethod · 0.95
TokenizeStringMethod · 0.95

Calls 5

PrintfMethod · 0.95
ParseMethod · 0.95
getInstanceMethod · 0.95
VariableStringMethod · 0.80
toStringMethod · 0.45

Tested by 2

testExpandMacroMethod · 0.76
testExpandMacroMiddleMethod · 0.76