Skip to content
Snippets Groups Projects
Commit ebf94bfc authored by Mark Olesen's avatar Mark Olesen
Browse files

cleanup text wrapping code in argList

parent 6e3ed58a
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,7 @@ License ...@@ -34,6 +34,7 @@ License
#include "JobInfo.H" #include "JobInfo.H"
#include "labelList.H" #include "labelList.H"
#include <cctype>
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
...@@ -157,48 +158,53 @@ void Foam::argList::printOptionUsage ...@@ -157,48 +158,53 @@ void Foam::argList::printOptionUsage
} }
} }
// text wrap - this could probably be made more efficient // text wrap
string::size_type pos = 0; string::size_type pos = 0;
while (pos != string::npos && strLen - pos > textWidth) while (pos != string::npos && pos + textWidth < strLen)
{ {
string::size_type prev = pos; // potential end point and next point
string::size_type wordEnd = str.find_first_of(" \t\n", pos); string::size_type curr = pos + textWidth - 1;
string::size_type next = string::npos; string::size_type next = string::npos;
while (wordEnd != string::npos && (wordEnd - pos) < textWidth) if (isspace(str[curr]) || isspace(str[curr+1]))
{ {
prev = wordEnd; // we were lucky: ended on a space or the next one is a space
next = str.find_first_not_of(" \t\n", wordEnd); next = str.find_first_not_of(" \t\n", curr + 1);
}
else
{
// search for end of the previous word break
string::size_type prev = str.find_last_of(" \t\n", curr);
if (next == string::npos) // reposition to the end of the previous word if possible
{ if (prev != string::npos && prev > pos)
wordEnd = string::npos;
}
else
{ {
wordEnd = str.find_first_of(" \t\n", next); curr = prev;
} }
} }
if (pos != string::npos) if (next == string::npos)
{ {
// indent next line next = curr + 1;
if (pos) }
// indent following lines (not the first one)
if (pos)
{
for (string::size_type i = 0; i < usageMin; ++i)
{ {
for (string::size_type i = 0; i < usageMin; ++i) Info<<' ';
{
Info<<' ';
}
} }
Info<< str.substr(pos, (prev - pos)).c_str() << nl;
pos = next;
} }
Info<< str.substr(pos, (curr - pos)).c_str() << nl;
pos = next;
} }
// output the remainder of the string
if (pos != string::npos) if (pos != string::npos)
{ {
// indent next line // indent following lines (not the first one)
if (pos) if (pos)
{ {
for (string::size_type i = 0; i < usageMin; ++i) for (string::size_type i = 0; i < usageMin; ++i)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment