MCPcopy Create free account
hub / github.com/apache/thrift / writeString

Method writeString

lib/cpp/src/thrift/protocol/TDebugProtocol.cpp:331–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329}
330
331uint32_t TDebugProtocol::writeString(const string& str) {
332 // XXX Raw/UTF-8?
333
334 string to_show = str;
335 if (to_show.length() > (string::size_type)string_limit_) {
336 to_show = str.substr(0, string_prefix_size_);
337 to_show += "[...](" + to_string(str.length()) + ")";
338 }
339
340 string output = "\"";
341
342 for (string::const_iterator it = to_show.begin(); it != to_show.end(); ++it) {
343 if (*it == '\\') {
344 output += "\\\\";
345 } else if (*it == '"') {
346 output += "\\\"";
347 // passing characters <0 to std::isprint causes asserts. isprint takes an
348 // int, so we need to be careful of sign extension
349 } else if (std::isprint((unsigned char)*it)) {
350 output += *it;
351 } else {
352 switch (*it) {
353 case '\a':
354 output += "\\a";
355 break;
356 case '\b':
357 output += "\\b";
358 break;
359 case '\f':
360 output += "\\f";
361 break;
362 case '\n':
363 output += "\\n";
364 break;
365 case '\r':
366 output += "\\r";
367 break;
368 case '\t':
369 output += "\\t";
370 break;
371 case '\v':
372 output += "\\v";
373 break;
374 default:
375 output += "\\x";
376 output += byte_to_hex(*it);
377 }
378 }
379 }
380
381 output += '\"';
382 return writeItem(output);
383}
384
385uint32_t TDebugProtocol::writeBinary(const string& str) {
386 // XXX Hex?

Callers

nothing calls this directly

Calls 6

byte_to_hexFunction · 0.85
lengthMethod · 0.65
to_stringFunction · 0.50
substrMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected