"Fossies" - the Fresh Open Source Software Archive

Member "ansifilter-2.18/src/bbcodegenerator.cpp" (30 Jan 2021, 3021 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 "bbcodegenerator.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.17_vs_2.18.

    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 //[url=https://www.bbcode.org/]This be bbcode.org![/url]
   86 string BBCodeGenerator::getHyperlink(string uri, string txt){
   87     ostringstream os;
   88     os <<"[url="<<uri<<"]"<<txt<<"[/url]";
   89     return os.str();
   90 }
   91 
   92 string BBCodeGenerator::getHeader()
   93 {
   94     return "";
   95 }
   96 
   97 string BBCodeGenerator::getFooter()
   98 {
   99 
  100     return "";
  101 }
  102 
  103 void BBCodeGenerator::printBody()
  104 {
  105     processInput();
  106 }
  107 
  108 string BBCodeGenerator::maskCharacter(unsigned char c)
  109 {
  110 
  111     switch (c) {
  112 
  113     case '\t' : // see deletion of nonprintable chars below
  114         return "\t";
  115         break;
  116     default :
  117         if (c>0x1f ) { // printable?
  118             return string( 1, c );
  119         } else {
  120             return "";
  121         }
  122     }
  123 
  124     return "";
  125 }
  126 
  127 }