"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/src/core/ansigenerator.cpp" (12 May 2020, 2956 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                     ansigenerator.cpp  -  description
    3                              -------------------
    4     begin                : Jul 5 2004
    5     copyright            : (C) 2004-2007 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 #include <sstream>
   29 
   30 #include "ansigenerator.h"
   31 
   32 namespace highlight
   33 {
   34 
   35 string  AnsiGenerator::getOpenTag ( const string&font,
   36                                     const string&fgCol, const string&bgCol )
   37 {
   38     ostringstream s;
   39     s  << "\033["<<font;
   40     if ( !fgCol.empty() )
   41         s<<";"<<fgCol;
   42     if ( !bgCol.empty() )
   43         s<<";"<<bgCol;
   44     s << "m";
   45     return  s.str();
   46 }
   47 
   48 
   49 AnsiGenerator::AnsiGenerator() : CodeGenerator ( ESC_ANSI )
   50 {
   51 
   52     newLineTag = "\n";
   53     spacer = " ";
   54 }
   55 
   56 AnsiGenerator::~AnsiGenerator() {}
   57 
   58 void AnsiGenerator::initOutputTags()
   59 {
   60     openTags.push_back ( "" );
   61     openTags.push_back ( getOpenTag ( "00", "31" ) ); //str
   62     openTags.push_back ( getOpenTag ( "00", "34" ) );//number
   63     openTags.push_back ( getOpenTag ( "00", "34" ) );//sl comment
   64     openTags.push_back ( getOpenTag ( "00", "34" ) );//ml comment
   65     openTags.push_back ( getOpenTag ( "00", "35" ) );//escapeChar
   66     openTags.push_back ( getOpenTag ( "00", "35" ) );//directive
   67     openTags.push_back ( getOpenTag ( "00", "31" ) );//directive string
   68     openTags.push_back ( getOpenTag ( "00", "30" ) );//linenum
   69     openTags.push_back ( getOpenTag ( "00", "00" ) );//symbol
   70     openTags.push_back ( getOpenTag ( "00", "35" ) );//interpolation
   71 
   72     closeTags.push_back ( "" );
   73     for (unsigned int i=1; i<NUMBER_BUILTIN_STATES; i++ ) {
   74         closeTags.push_back ( "\033[m" );
   75     }
   76 }
   77 
   78 string AnsiGenerator::getHeader()
   79 {
   80     return string();
   81 }
   82 
   83 void AnsiGenerator::printBody()
   84 {
   85     processRootState();
   86 }
   87 
   88 string AnsiGenerator::getFooter()
   89 {
   90     return string();
   91 }
   92 
   93 string AnsiGenerator::maskCharacter ( unsigned char c )
   94 {
   95     return string ( 1, c );
   96 }
   97 
   98 string AnsiGenerator::getKeywordOpenTag ( unsigned int styleID )
   99 {
  100     return ( styleID ) ?getOpenTag ( "00", "32", "" ) :getOpenTag ( "00", "33" );
  101 }
  102 
  103 string AnsiGenerator::getKeywordCloseTag ( unsigned int styleID )
  104 {
  105     return "\033[m";
  106 }
  107 
  108 }