"Fossies" - the Fresh Open Source Software Archive

Member "ansifilter-2.14/src/bbcodegenerator.cpp" (3 Apr 2019, 2815 Bytes) of package /linux/privat/ansifilter-2.14.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 "bbcodegenerator.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.13_vs_2.14.

    1 /***************************************************************************
    2                     bbcodegenerator.cpp  -  description
    3                              -------------------
    4 
    5     copyright            : (C) 2011 by Andre Simon
    6     email                : a.simon@mailbox.org
    7  ***************************************************************************/
    8 
    9 /*
   10 This file is part of ANSIFilter.
   11 
   12 ANSIFilter is free software: you can redistribute it and/or modify
   13 it under the terms of the GNU General Public License as published by
   14 the Free Software Foundation, either version 3 of the License, or
   15 (at your option) any later version.
   16 
   17 ANSIFilter is distributed in the hope that it will be useful,
   18 but WITHOUT ANY WARRANTY; without even the implied warranty of
   19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   20 GNU General Public License for more details.
   21 
   22 You should have received a copy of the GNU General Public License
   23 along with ANSIFilter.  If not, see <http://www.gnu.org/licenses/>.
   24 */
   25 
   26 #include <fstream>
   27 #include <iostream>
   28 #include <sstream>
   29 
   30 #include "bbcodegenerator.h"
   31 #include "version.h"
   32 
   33 namespace ansifilter
   34 {
   35 
   36 BBCodeGenerator::BBCodeGenerator ():
   37     CodeGenerator(BBCODE),
   38     fileSuffix(".bbcode")
   39 {
   40     newLineTag="\n";
   41     spacer=" ";
   42 }
   43 
   44 string BBCodeGenerator::getOpenTag()
   45 {
   46     ostringstream fmtStream;
   47 
   48     if (elementStyle.isFgColorSet()) {
   49         fmtStream << "[color=#"
   50           << elementStyle.getFgColour().getRed(HTML)
   51           << elementStyle.getFgColour().getGreen(HTML)
   52           << elementStyle.getFgColour().getBlue(HTML)
   53           << "]";
   54     }
   55 
   56     if ( elementStyle.isBold() ) fmtStream << "[b]";
   57     if ( elementStyle.isItalic() ) fmtStream << "[i]";
   58     if ( elementStyle.isUnderline() ) fmtStream << "[u]";
   59 
   60 
   61     string fmt  = fmtStream.str();
   62     tagIsOpen = fmt.size()>0;
   63     if (tagIsOpen) {
   64       ostringstream spanTag;
   65       spanTag<<fmt;
   66       return spanTag.str();
   67     }
   68     return "";
   69 }
   70 
   71 string BBCodeGenerator::getCloseTag()
   72 {
   73     ostringstream s;
   74 
   75     if (tagIsOpen){
   76         if ( elementStyle.isUnderline() ) s << "[/u]";
   77         if ( elementStyle.isItalic() ) s << "[/i]";
   78         if ( elementStyle.isBold() ) s << "[/b]";
   79         if ( elementStyle.isFgColorSet() ) s << "[/color]";
   80     }
   81     tagIsOpen = false;
   82     return  s.str();
   83 }
   84 
   85 
   86 
   87 string BBCodeGenerator::getHeader()
   88 {
   89     return "";
   90 }
   91 
   92 string BBCodeGenerator::getFooter()
   93 {
   94 
   95     return "";
   96 }
   97 
   98 void BBCodeGenerator::printBody()
   99 {
  100     processInput();
  101 }
  102 
  103 string BBCodeGenerator::maskCharacter(unsigned char c)
  104 {
  105 
  106     switch (c) {
  107 
  108     case '\t' : // see deletion of nonprintable chars below
  109         return "\t";
  110         break;
  111     default :
  112         if (c>0x1f ) { // printable?
  113             return string( 1, c );
  114         } else {
  115             return "";
  116         }
  117     }
  118 
  119     return "";
  120 }
  121 
  122 }