MCPcopy Create free account
hub / github.com/GNOME/gjs / gjs_debug_linear_string

Function gjs_debug_linear_string

gjs/jsapi-util-string.cpp:470–506  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468};
469
470[[nodiscard]]
471static std::string gjs_debug_linear_string(JSLinearString* str, Quotes quotes) {
472 size_t len = JS::GetLinearStringLength(str);
473
474 std::ostringstream out;
475 if (quotes == DoubleQuotes)
476 out << '"';
477
478 JS::AutoCheckCannotGC nogc;
479 if (JS::LinearStringHasLatin1Chars(str)) {
480 const JS::Latin1Char* chars = JS::GetLatin1LinearStringChars(nogc, str);
481 out << std::string(reinterpret_cast<const char*>(chars), len);
482 if (quotes == DoubleQuotes)
483 out << '"';
484 return out.str();
485 }
486
487 const char16_t* chars = JS::GetTwoByteLinearStringChars(nogc, str);
488 for (size_t ix = 0; ix < len; ix++) {
489 char16_t c = chars[ix];
490 if (c == '\n')
491 out << "\\n";
492 else if (c == '\t')
493 out << "\\t";
494 else if (c >= 32 && c < 127)
495 out << c;
496 else if (c <= 255)
497 out << "\\x" << std::setfill('0') << std::setw(2)
498 << static_cast<unsigned>(c);
499 else
500 out << "\\x" << std::setfill('0') << std::setw(4)
501 << static_cast<unsigned>(c);
502 }
503 if (quotes == DoubleQuotes)
504 out << '"';
505 return out.str();
506}
507
508std::string gjs_debug_string(JSString* str) {
509 if (!str)

Callers 2

gjs_debug_stringFunction · 0.85
gjs_debug_idFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected