MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / tryEnterComment

Function tryEnterComment

app/src/DataModel/Editors/CodeFormatter.cpp:276–310  ·  view source on GitHub ↗

@brief Tries to open a JS or Lua line/block comment at line[i]; returns true if scan continues. */

Source from the content-addressed store, hash-verified

274/** @brief Tries to open a JS or Lua line/block comment at line[i]; returns true if scan continues.
275 */
276static bool tryEnterComment(
277 QStringView line, int& i, int n, Language lang, ScanState& state, bool& stop)
278{
279 const QChar c = line[i];
280 stop = false;
281
282 if (lang == Language::JavaScript && c == QLatin1Char('/') && i + 1 < n
283 && line[i + 1] == QLatin1Char('/')) {
284 stop = true;
285 return true;
286 }
287
288 if (lang == Language::Lua && c == QLatin1Char('-') && i + 1 < n
289 && line[i + 1] == QLatin1Char('-')) {
290 int level = 0;
291 int consume = 0;
292 if (i + 2 < n && tryLuaLongOpen(line, i + 2, level, consume)) {
293 state.in = ScanIn::LuaBlockComment;
294 state.luaLevel = level;
295 i += 2 + consume;
296 return true;
297 }
298 stop = true;
299 return true;
300 }
301
302 if (lang == Language::JavaScript && c == QLatin1Char('/') && i + 1 < n
303 && line[i + 1] == QLatin1Char('*')) {
304 state.in = ScanIn::JsBlockComment;
305 i += 2;
306 return true;
307 }
308
309 return false;
310}
311
312/** @brief Tries to enter a string/template/long-string at line[i]; returns true if it consumed it.
313 */

Callers 1

analyzeLineFunction · 0.70

Calls 1

tryLuaLongOpenFunction · 0.85

Tested by

no test coverage detected