00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef TCLAP_PRINTSENSIBLY_H
00024 #define TCLAP_PRINTSENSIBLY_H
00025
00026 #include <iostream>
00027 #include <algorithm>
00028 #include <string>
00029
00030 namespace TCLAP {
00031
00042 inline void spacePrint( std::ostream& os,
00043 const std::string& s,
00044 int maxWidth,
00045 int indentSpaces=0,
00046 int secondLineOffset=0 )
00047 {
00048 int len = (int)(s.length());
00049
00050 if ( (len + indentSpaces > maxWidth) && maxWidth > 0 )
00051 {
00052 int allowedLen = maxWidth - indentSpaces;
00053 int start = 0;
00054 while ( start < len )
00055 {
00056
00057 int stringLen = std::min( len - start, allowedLen );
00058
00059
00060 if ( stringLen == allowedLen )
00061 while ( s[stringLen+start] != ' ' &&
00062 s[stringLen+start] != ',' &&
00063 s[stringLen+start] != '|' )
00064 stringLen--;
00065
00066
00067 for ( int i = 0; i < stringLen; i++ )
00068 if ( s[start+i] == '\n' )
00069 stringLen = i+1;
00070
00071
00072 for ( int i = 0; i < indentSpaces; i++ )
00073 os << " ";
00074
00075 if ( start == 0 )
00076 {
00077
00078 indentSpaces += secondLineOffset;
00079
00080
00081 allowedLen -= secondLineOffset;
00082 }
00083
00084 os << s.substr(start,stringLen) << std::endl;
00085
00086
00087 if ( s[stringLen+start] == ' ' )
00088 start++;
00089
00090 start += stringLen;
00091 }
00092 }
00093 else
00094 {
00095 for ( int i = 0; i < indentSpaces; i++ )
00096 os << " ";
00097 os << s << std::endl;
00098 }
00099 }
00100
00101 }
00102
00103 #endif