Source-highlight Library
chartranslator.h
1 /*
2  * Copyright (C) 1999-2009 Lorenzo Bettini, http://www.lorenzobettini.it
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  */
19 
20 #ifndef _CHARTRANSLATOR_H
21 #define _CHARTRANSLATOR_H
22 
23 #define NUM_OF_CHARS 256
24 
25 #include <string>
26 #include <boost/regex.hpp>
27 
28 #include "preformatter.h"
29 
30 namespace srchilite {
31 
40 protected:
42  unsigned int counter;
44  std::string translation_exp;
46  std::string translation_format;
48  boost::regex *reg_exp;
50  bool bol;
51 
57  virtual const std::string doPreformat(const std::string &text);
58 
59 public:
64  virtual ~CharTranslator();
65 
71  void set_translation(const std::string &s1, const std::string &s2);
72 
77  const std::string toString() const {
78  return translation_exp + " -> " + translation_format;
79  }
80 };
81 
82 typedef boost::shared_ptr<CharTranslator> CharTranslatorPtr;
83 
84 }
85 
86 #endif // _CHARTRANSLATOR_H
CharTranslator(PreFormatterPtr f=PreFormatterPtr())
Definition: chartranslator.cc:31
std::string translation_exp
the translation regular expression (for buffering)
Definition: chartranslator.h:44
Preformats text to be generated.
Definition: preformatter.h:31
std::string translation_format
the corresponding translated regular expression (for buffering)
Definition: chartranslator.h:46
const std::string toString() const
returns a string representation: what we translate and into what we translate
Definition: chartranslator.h:77
void set_translation(const std::string &s1, const std::string &s2)
Adds a translation pair.
Definition: chartranslator.cc:40
unsigned int counter
keeps track of the translation patterns added
Definition: chartranslator.h:42
C++ class: doctemplate.h.
Definition: bufferedoutput.cpp:13
bool bol
whether we are at the beginning of a new line
Definition: chartranslator.h:50
Translates specific character sequences into corresponding ones; it can also use regular expression f...
Definition: chartranslator.h:39
boost::regex * reg_exp
the actual regular expression
Definition: chartranslator.h:48
boost::shared_ptr< PreFormatter > PreFormatterPtr
shared pointer for PreFormatter
Definition: preformatter.h:20
virtual const std::string doPreformat(const std::string &text)
The actual preformatting (char translation)
Definition: chartranslator.cc:55