"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/src/include/preformatter.h" (12 May 2020, 3661 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /***************************************************************************
    2                         PreFormatter.cpp  -  description
    3                              -------------------
    4     begin                : Mo Jan 03 2005
    5     copyright            : (C) 2005-2008 by Andre Simon
    6     email                : a.simon@mailbox.org
    7  ***************************************************************************/
    8 
    9 
   10 /*
   11 This file is part of Highlight.
   12 
   13 Highlight is free software: you can redistribute it and/or modify
   14 it under the terms of the GNU General Public License as published by
   15 the Free Software Foundation, either version 3 of the License, or
   16 (at your option) any later version.
   17 
   18 Highlight is distributed in the hope that it will be useful,
   19 but WITHOUT ANY WARRANTY; without even the implied warranty of
   20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   21 GNU General Public License for more details.
   22 
   23 You should have received a copy of the GNU General Public License
   24 along with Highlight.  If not, see <http://www.gnu.org/licenses/>.
   25 */
   26 
   27 
   28 #ifndef PreFormatter_H
   29 #define PreFormatter_H
   30 
   31 #include <string>
   32 #include <set>
   33 
   34 namespace highlight
   35 {
   36 
   37 /** \brief Class which provides intelligent line wrapping.
   38 * @author Andre Simon
   39 */
   40 
   41 class PreFormatter
   42 {
   43 public:
   44 
   45     PreFormatter();
   46 
   47     ~PreFormatter();
   48 
   49     /**
   50      Set wrapping mode
   51      \param wrap set to true if long lines should be wrapped
   52     */
   53     void setWrap ( bool wrap )
   54     {
   55         wrapLines = wrap;
   56     }
   57 
   58     /**
   59      Replace tabs by spaces
   60      \param replTabs set to true if tabs should be replaced by spaces
   61     */
   62     void setReplaceTabs ( bool replTabs )
   63     {
   64         replaceTabs = replTabs;
   65     }
   66 
   67     /**
   68      \return True if current line can be wrapped again
   69     */
   70     bool hasMoreLines();
   71 
   72     /**
   73      Sets new line to be wrapped
   74      \param newline New line
   75     */
   76     void setLine ( const std::string & newline );
   77 
   78     /**
   79      The method will indent function calls and statements
   80      \return Next line
   81     */
   82     std::string getNextLine();
   83 
   84     /**
   85      \return True if lines following open braces should be indented
   86     */
   87     bool indentCode();
   88 
   89     /**
   90       Maximum line length
   91       \param maxlength max. length of output lines
   92     */
   93     void setWrapLineLength ( unsigned int maxlength );
   94 
   95     /**
   96       Indentation mode
   97       \param indentAfterOpenBraces set true if lines should be indented after braces
   98     */
   99     void setWrapIndentBraces ( bool indentAfterOpenBraces=true );
  100 
  101     /**
  102       Number of spaces
  103       \param num number of spaces which replace a tab
  104     */
  105     void setNumberSpaces ( unsigned int num );
  106 
  107     /**
  108       \return true if preformatting is enabled
  109     */
  110     bool isEnabled()
  111     {
  112         return wrapLines || replaceTabs;
  113     }
  114 
  115     bool getReplaceTabs()
  116     {
  117         return replaceTabs;
  118     }
  119 
  120     /**
  121       reset preformatting state to use the object with new input data
  122     */
  123     void reset ()
  124     {
  125         lineNumber=0;
  126         wrappedLines.clear();
  127     }
  128 
  129     /**
  130      \param lineNumber line number
  131       \return true if input line linenumber was wrapped
  132     */
  133     bool isWrappedLine ( int lineNumber )
  134     {
  135         return wrappedLines.count ( lineNumber );
  136     }
  137 
  138 private:
  139 
  140     unsigned int maxLineLength;
  141 
  142     std::string line, wsPrefix;
  143     unsigned int index;
  144     unsigned int numberSpaces;
  145     unsigned int lineNumber;
  146     size_t wsPrefixLength;
  147     bool hasMore, indentAfterOpenBraces;
  148     bool redefineWsPrefix;
  149     bool wrapLines, replaceTabs;
  150 
  151     std::set<int> wrappedLines;
  152 
  153     static const std::string LB_CHARS;
  154     static const std::string WS_CHARS;
  155     static const std::string INDENT_MARKERS;
  156 
  157 };
  158 
  159 }
  160 
  161 #endif