MCPcopy Create free account
hub / github.com/davisking/dlib / wrap_string

Function wrap_string

dlib/string/string.h:494–574  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

492 typename alloc
493 >
494 const std::basic_string<charT,traits,alloc> wrap_string (
495 const std::basic_string<charT,traits,alloc>& str,
496 const unsigned long first_pad = 0,
497 const unsigned long rest_pad = 0,
498 const unsigned long max_per_line = 79
499 )
500 {
501 DLIB_ASSERT ( first_pad < max_per_line && rest_pad < max_per_line &&
502 rest_pad >= first_pad,
503 "\tconst std::basic_string<charT,traits,alloc> wrap_string()"
504 << "\n\tfirst_pad: " << first_pad
505 << "\n\trest_pad: " << rest_pad
506 << "\n\tmax_per_line: " << max_per_line );
507
508 std::basic_ostringstream<charT,traits,alloc> sout;
509 std::basic_istringstream<charT,traits,alloc> sin(str);
510
511 for (unsigned long i = 0; i < rest_pad; ++i)
512 sout << _dT(charT," ");
513 const std::basic_string<charT,traits,alloc> pad(sout.str());
514 sout.str(_dT(charT,""));
515
516 for (unsigned long i = 0; i < first_pad; ++i)
517 sout << _dT(charT," ");
518
519
520 typename std::basic_string<charT,traits,alloc>::size_type remaining = max_per_line - rest_pad;
521
522 std::basic_string<charT,traits,alloc> temp;
523
524 sin >> temp;
525 while (sin)
526 {
527 if (temp.size() > remaining)
528 {
529 if (temp.size() + rest_pad >= max_per_line)
530 {
531 std::string::size_type i = 0;
532 for (; i < temp.size(); ++i)
533 {
534 sout << temp[i];
535 --remaining;
536 if (remaining == 0)
537 {
538 sout << _dT(charT,"\n") << pad;
539 remaining = max_per_line - rest_pad;
540 }
541 }
542 }
543 else
544 {
545 sout << _dT(charT,"\n") << pad << temp;
546 remaining = max_per_line - rest_pad - temp.size();
547 }
548 }
549 else if (temp.size() == remaining)
550 {
551 sout << temp;

Callers 9

display_aboutMethod · 0.85
print_manualFunction · 0.85
print_optionsMethod · 0.85
set_info_stringMethod · 0.85
set_info_stringMethod · 0.85

Calls 2

strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected