MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / FormatParagraph

Function FormatParagraph

src/utilstrencodings.cpp:355–394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

353}
354
355std::string FormatParagraph(const std::string& in, size_t width, size_t indent)
356{
357 std::stringstream out;
358 size_t ptr = 0;
359 size_t indented = 0;
360 while (ptr < in.size())
361 {
362 size_t lineend = in.find_first_of('\n', ptr);
363 if (lineend == std::string::npos) {
364 lineend = in.size();
365 }
366 const size_t linelen = lineend - ptr;
367 const size_t rem_width = width - indented;
368 if (linelen <= rem_width) {
369 out << in.substr(ptr, linelen + 1);
370 ptr = lineend + 1;
371 indented = 0;
372 } else {
373 size_t finalspace = in.find_last_of(" \n", ptr + rem_width);
374 if (finalspace == std::string::npos || finalspace < ptr) {
375 // No place to break; just include the entire word and move on
376 finalspace = in.find_first_of("\n ", ptr);
377 if (finalspace == std::string::npos) {
378 // End of the string, just add it and break
379 out << in.substr(ptr);
380 break;
381 }
382 }
383 out << in.substr(ptr, finalspace - ptr) << "\n";
384 if (in[finalspace] == '\n') {
385 indented = 0;
386 } else if (indent) {
387 out << std::string(indent, ' ');
388 indented = indent;
389 }
390 ptr = finalspace + 1;
391 }
392 }
393 return out.str();
394}
395
396std::string i64tostr(int64_t n)
397{

Callers 3

AppInitFunction · 0.85
HelpMessageOptFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 2

strMethod · 0.80
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68