FACT++  1.0
string Tools::Wrap ( std::string &  str,
size_t  width = 78 
)

This is a static helper to remove leading and trailing whitespaces.

Usage example:

string str = " Dies ist ein test fuer einen ganz langen Satz "
"und ob er korrekt umgebrochen und formatiert wird. Alles "
"nur ein simpler test aber trotzdem ganz wichtig.";
cout << setfill('-') << setw(40) << "+" << endl;
while (1)
{
const string rc = Tools::Wrap(str, 40);
if (rc.empty())
break;
cout << rc << endl;
}

Definition at line 128 of file tools.cc.

References str.

129 {
130  const size_t pos = str.length()<width ? string::npos : str.find_last_of(' ', width);
131  if (pos==string::npos)
132  {
133  const string rc = str;
134  str = "";
135  return rc;
136  }
137 
138  const size_t indent = str.find_first_not_of(' ');
139 
140  const string rc = str.substr(0, pos);
141  const size_t p2 = str.find_first_not_of(' ', pos+1);
142 
143  str = str.substr(0, indent) + str.substr(p2==string::npos ? pos+1 : p2);
144 
145  return rc;
146 }
char str[80]
Definition: test_client.c:7