"Fossies" - the Fresh Open Source Software Archive

Member "ansifilter-2.18/src/preformatter.h" (30 Jan 2021, 3595 Bytes) of package /linux/privat/ansifilter-2.18.tar.bz2:


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. For more information about "preformatter.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.13_vs_2.14.

    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 ansifilter
   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     /**
  116       reset preformatting state to use the object with new input data
  117     */
  118     void reset ()
  119     {
  120         lineNumber=0;
  121         wrappedLines.clear();
  122     }
  123 
  124     /**
  125      \param lineNumber line number
  126       \return true if input line linenumber was wrapped
  127     */
  128     bool isWrappedLine ( int lineNumber )
  129     {
  130         return wrappedLines.count ( lineNumber );
  131     }
  132 
  133 private:
  134 
  135     unsigned int maxLineLength;
  136 
  137     std::string line, wsPrefix;
  138     unsigned int index;
  139     unsigned int numberSpaces;
  140     unsigned int lineNumber;
  141     size_t wsPrefixLength;
  142     bool hasMore, indentAfterOpenBraces;
  143     bool redefineWsPrefix;
  144     bool wrapLines, replaceTabs;
  145 
  146     std::set<int> wrappedLines;
  147 
  148     static const std::string LB_CHARS;
  149     static const std::string WS_CHARS;
  150     static const std::string INDENT_MARKERS;
  151 
  152 };
  153 
  154 }
  155 
  156 #endif