MCPcopy Create free account
hub / github.com/AnetaTexler/FaceBlit / wrap_string

Function wrap_string

VS/include/dlib/string/string.h:497–579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 4

print_optionsMethod · 0.50
set_info_stringMethod · 0.50
set_info_stringMethod · 0.50

Calls 2

strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected