00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef PreFormatter_H
00029 #define PreFormatter_H
00030
00031 #include <string>
00032 #include <set>
00033
00034 namespace highlight
00035 {
00036
00041 class PreFormatter
00042 {
00043 public:
00044
00045 PreFormatter();
00046
00047 ~PreFormatter();
00048
00053 void setWrap ( bool wrap ) {wrapLines = wrap;}
00054
00059 void setReplaceTabs ( bool replTabs ) {replaceTabs = replTabs;}
00060
00064 bool hasMoreLines();
00065
00070 void setLine ( const std::string & newline );
00071
00076 std::string getNextLine();
00077
00081 bool indentCode();
00082
00087 void setWrapLineLength ( unsigned int maxlength );
00088
00093 void setWrapIndentBraces ( bool indentAfterOpenBraces=true );
00094
00099 void setNumberSpaces ( unsigned int num );
00100
00104 bool isEnabled()
00105 {
00106 return wrapLines || replaceTabs;
00107 }
00108
00112 void reset ()
00113 {
00114 lineNumber=0;
00115 wrappedLines.clear();
00116 }
00117
00122 bool isWrappedLine ( int lineNumber )
00123 {
00124 return wrappedLines.count ( lineNumber );
00125 }
00126
00127 private:
00128
00129 unsigned int maxLineLength;
00130
00131 std::string line, wsPrefix;
00132 unsigned int index;
00133 unsigned int numberSpaces;
00134 unsigned int lineNumber;
00135 size_t wsPrefixLength;
00136 bool hasMore, indentAfterOpenBraces;
00137 bool redefineWsPrefix;
00138 bool wrapLines, replaceTabs;
00139
00140 std::set<int> wrappedLines;
00141
00142 static const std::string LB_CHARS;
00143 static const std::string WS_CHARS;
00144 static const std::string INDENT_MARKERS;
00145
00146 };
00147
00148 }
00149
00150 #endif