1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/**
* C++ class: doctemplate.h
*
* Description: The template for a document containing the output of
* highlighting
*
* Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2005-2007
* Copyright: See COPYING file that comes with this distribution
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doctemplate.h"
#include "substfun.h"
namespace srchilite {
#define TITLE_VAR_TEXT "$title" // the text of the title variable
#define INPUT_LANG_VAR_TEXT "$inputlang" // the text of the input lang variable
#define CSS_VAR_TEXT "$css" // the text of the css variable
#define ADDITIONAL_VAR_TEXT "$additional" // the text of the additional text variable
#define HEADER_VAR_TEXT "$header" // the text of the header variable
#define FOOTER_VAR_TEXT "$footer" // the text of the footer variable
#define BACKGROUND_VAR_TEXT "$docbgcolor" // the text of the background variable
#define TITLE_VAR "\\" TITLE_VAR_TEXT // the name of the title variable as regexp
#define INPUT_LANG_VAR "\\" INPUT_LANG_VAR_TEXT // the name of the input lang variable as regexp
#define CSS_VAR "\\" CSS_VAR_TEXT // the name of the css variable as regexp
#define ADDITIONAL_VAR "\\" ADDITIONAL_VAR_TEXT // the text of the additional text variable as regexp
#define HEADER_VAR "\\" HEADER_VAR_TEXT // the text of the header variable as regexp
#define FOOTER_VAR "\\" FOOTER_VAR_TEXT // the text of the footer variable as regexp
#define BACKGROUND_VAR "\\" BACKGROUND_VAR_TEXT // the text of the background variable as regexp
using namespace std;
DocTemplate::DocTemplate(const string &begin, const string &end) :
begin_repr(begin), end_repr(end)
{
}
string
DocTemplate::output_begin(const string &title, const string &cs, const string &add,
const string &header, const string &footer, const std::string &background,
const string &input_lang)
{
boost::regex title_exp(TITLE_VAR);
boost::regex css_exp(CSS_VAR);
boost::regex additional_exp(ADDITIONAL_VAR);
boost::regex header_exp(HEADER_VAR);
boost::regex footer_exp(FOOTER_VAR);
boost::regex background_exp(BACKGROUND_VAR);
boost::regex input_lang_exp(INPUT_LANG_VAR);
string ret = subst(title_exp, begin_repr, title);
ret = subst(css_exp, ret, cs);
ret = subst(additional_exp, ret, add);
ret = subst(header_exp, ret, header);
ret = subst(footer_exp, ret, footer);
ret = subst(background_exp, ret, background);
ret = subst(input_lang_exp, ret, input_lang);
return ret;
}
string
DocTemplate::output_end(const string &title, const string &cs, const string &add,
const string &header, const string &footer, const std::string &background,
const string &input_lang)
{
boost::regex title_exp(TITLE_VAR);
boost::regex css_exp(CSS_VAR);
boost::regex additional_exp(ADDITIONAL_VAR);
boost::regex header_exp(HEADER_VAR);
boost::regex footer_exp(FOOTER_VAR);
boost::regex background_exp(BACKGROUND_VAR);
boost::regex input_lang_exp(INPUT_LANG_VAR);
string ret = subst(title_exp, end_repr, title);
ret = subst(css_exp, ret, cs);
ret = subst(additional_exp, ret, add);
ret = subst(header_exp, ret, header);
ret = subst(footer_exp, ret, footer);
ret = subst(background_exp, ret, background);
ret = subst(input_lang_exp, ret, input_lang);
return ret;
}
}
|