[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-source-highlight] Embedding inputlang as information
From: |
Masatake YAMATO |
Subject: |
Re: [Help-source-highlight] Embedding inputlang as information |
Date: |
Mon, 04 Apr 2011 16:56:57 +0900 (JST) |
> Hi,
>
> thank you for replying.
>
>> Hi there
>>
>> I still haven't had time to work on this. However, your patch looks
>> OK. As I said in my previous email I think I will not add that
>> additional argument in the constructor, but make it settable in a set
>> method in order not to break compatibility, or probably add an
>> overloaded constructor with the additional parameter.
>
> Implementing with the overloaded constructor aproach is much easier for
> me. I'll submit the patch.
Instread of overloading, I've written a patch which uses default value for
parameter.
Masatake YAMATO
diff --git a/lib/srchilite/docgenerator.cc b/lib/srchilite/docgenerator.cc
index 1e1ae73..6494e6f 100644
--- a/lib/srchilite/docgenerator.cc
+++ b/lib/srchilite/docgenerator.cc
@@ -31,6 +31,7 @@ void
DocGenerator::generate_start_doc(std::ostream *sout)
{
bool docTitle = (title.size () > 0);
+ bool docInputLang = (input_lang.size () > 0);
bool inputFileName = (input_file_name.size () > 0);
*sout <<
@@ -42,7 +43,8 @@ DocGenerator::generate_start_doc(std::ostream *sout)
"\nby Lorenzo
Bettini\nhttp://www.lorenzobettini.it\nhttp://www.gnu.org/software/src-highlite",
doc_header,
doc_footer,
- doc_background
+ doc_background,
+ docInputLang ? input_lang: "unknown"
);
}
@@ -56,7 +58,8 @@ DocGenerator::generate_end_doc(std::ostream *sout)
"\nby Lorenzo
Bettini\nhttp://www.lorenzobettini.it\nhttp://www.gnu.org/software/src-highlite",
doc_header,
doc_footer,
- doc_background
+ doc_background,
+ ""
);
}
diff --git a/lib/srchilite/docgenerator.h b/lib/srchilite/docgenerator.h
index 16a2804..3a6282d 100644
--- a/lib/srchilite/docgenerator.h
+++ b/lib/srchilite/docgenerator.h
@@ -47,16 +47,18 @@ protected:
string css_url;
string doc_background;
bool entire_doc;
+ string input_lang;
DocTemplate docTemplate;
public:
DocGenerator(const string &s, const string &i, const string &h,
- const string &f, const string &c, const string &back, bool entire,
+ const string &f, const string &c, const string &back, bool entire,
+ const string &l,
const string &start_tmpl, const string &end_tmpl) :
title(s), gen_source_highlight_version(true), input_file_name(i),
doc_header(h), doc_footer(f), css_url(c), doc_background(back),
- entire_doc(entire), docTemplate(DocTemplate(start_tmpl,
+ entire_doc(entire), input_lang(l), docTemplate(DocTemplate(start_tmpl,
end_tmpl)) {
}
DocGenerator(const string &start_tmpl, const string &end_tmpl) :
@@ -97,6 +99,10 @@ public:
title = _title;
}
+ void setInputLang(const std::string &_input_lang) {
+ input_lang = _input_lang;
+ }
+
void setBackgroundColor(const std::string &bg) {
doc_background = bg;
}
diff --git a/lib/srchilite/doctemplate.cpp b/lib/srchilite/doctemplate.cpp
index 32b4e2f..63309c5 100644
--- a/lib/srchilite/doctemplate.cpp
+++ b/lib/srchilite/doctemplate.cpp
@@ -14,12 +14,14 @@
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
@@ -35,7 +37,8 @@ DocTemplate::DocTemplate(const string &begin, const string
&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 &header, const string &footer, const std::string &background,
+ const string &input_lang)
{
boost::regex title_exp(TITLE_VAR);
boost::regex css_exp(CSS_VAR);
@@ -43,6 +46,7 @@ DocTemplate::output_begin(const string &title, const string
&cs, const string &a
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);
@@ -50,13 +54,15 @@ DocTemplate::output_begin(const string &title, const string
&cs, const string &a
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 &header, const string &footer, const std::string &background,
+ const string &input_lang)
{
boost::regex title_exp(TITLE_VAR);
boost::regex css_exp(CSS_VAR);
@@ -64,6 +70,7 @@ DocTemplate::output_end(const string &title, const string
&cs, const string &add
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);
@@ -71,6 +78,7 @@ DocTemplate::output_end(const string &title, const string
&cs, const string &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;
}
diff --git a/lib/srchilite/doctemplate.h b/lib/srchilite/doctemplate.h
index 7ee0e1a..6df986e 100644
--- a/lib/srchilite/doctemplate.h
+++ b/lib/srchilite/doctemplate.h
@@ -22,10 +22,12 @@ public:
std::string output_begin(const std::string &title, const std::string &cs,
const std::string &add, const std::string &header,
- const std::string &footer, const std::string &background);
+ const std::string &footer, const std::string &background,
+ const std::string &input_lang = "");
std::string output_end(const std::string &title, const std::string &cs,
const std::string &add, const std::string &header,
- const std::string &footer, const std::string &background);
+ const std::string &footer, const std::string &background,
+ const std::string &input_lang = "unknown");
const std::string &toStringBegin() const {
return begin_repr;
diff --git a/lib/srchilite/sourcehighlight.cpp
b/lib/srchilite/sourcehighlight.cpp
index 9c0a55b..3abaed7 100644
--- a/lib/srchilite/sourcehighlight.cpp
+++ b/lib/srchilite/sourcehighlight.cpp
@@ -257,6 +257,9 @@ void SourceHighlight::highlight(const std::string &input,
noDocGenerator->setTitle(input);
}
+ docGenerator->setInputLang(inputLang);
+ noDocGenerator->setInputLang(inputLang);
+
if (ctagsFormatter) {
// if we need to generate references, then set the file info
ctagsFormatter->setFileInfo(input, output);
@@ -334,6 +337,8 @@ void SourceHighlight::highlight(std::istream &input,
std::ostream &output,
documentGenerator->setTitle(title);
}
+ documentGenerator->setInputLang(inputLang);
+
// first generate the start of the output file
documentGenerator->generate_start_doc(&output);
diff --git a/lib/srchilite/sourcehighlight.h b/lib/srchilite/sourcehighlight.h
index 7d61972..4cef31e 100644
--- a/lib/srchilite/sourcehighlight.h
+++ b/lib/srchilite/sourcehighlight.h
@@ -64,6 +64,9 @@ class SourceHighlight {
/// the title for the output document (defaults to the source file name)
std::string title;
+ /// the input lang for the output document
+ std::string inputLang;
+
/// the value for the css
std::string css;
@@ -272,6 +275,10 @@ public:
void setTitle(const std::string &_title) {
title = _title;
}
+
+ void setInputLang(const std::string &_inputLang) {
+ inputLang = _inputLang;
+ }
void setCss(const std::string &_css) {
css = _css;
diff --git a/lib/tests/test_outlangparser_main.cpp
b/lib/tests/test_outlangparser_main.cpp
index 467604b..db3f783 100644
--- a/lib/tests/test_outlangparser_main.cpp
+++ b/lib/tests/test_outlangparser_main.cpp
@@ -45,7 +45,7 @@ this is simply the footer: $footer",
textstyles->docTemplate.toStringEnd());
string start = textstyles->docTemplate.output_begin("title", "css",
- "additional", "header", "footer", "");
+ "additional", "header", "footer", "", "inputlang");
cout << "DocTemplate start:\n" << start << endl;
assertEquals(
@@ -59,7 +59,7 @@ and this is some additional stuff: additional",
start);
string end = textstyles->docTemplate.output_end("title", "css",
- "additional", "header", "footer", "");
+ "additional", "header", "footer", "", "inputlang");
cout << "DocTemplate end:\n" << end << endl;
assertEquals(
diff --git a/lib/tests/test_textgenerator_main.cpp
b/lib/tests/test_textgenerator_main.cpp
index aeaef3b..ed58660 100644
--- a/lib/tests/test_textgenerator_main.cpp
+++ b/lib/tests/test_textgenerator_main.cpp
@@ -74,9 +74,9 @@ int main() {
DocTemplate docTemplate(start, end);
string transformed_start = docTemplate.output_begin("TITLE", "CSS",
- "ADDITIONAL", "HEADER\n", "\nFOOTER", "");
+ "ADDITIONAL", "HEADER\n", "\nFOOTER", "", "INPUTLANG");
string transformed_end = docTemplate.output_end("TITLE", "CSS",
- "ADDITIONAL", "HEADER\n", "\nFOOTER", "");
+ "ADDITIONAL", "HEADER\n", "\nFOOTER", "", "INPUTLANG");
cout << "orig start : " << start << endl;
cout << "transformed: " << transformed_start << endl;
diff --git a/src/xhtml.outlang b/src/xhtml.outlang
index ecc1a27..cd5d02c 100644
--- a/src/xhtml.outlang
+++ b/src/xhtml.outlang
@@ -7,6 +7,7 @@ doctemplate
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<meta name=\"GENERATOR\" content=\"$additional\" />
+<meta name=\"INPUTLANG\" content=\"$inputlang\" />
<title>$title</title>
</head>
<body style=\"background-color: $docbgcolor\">
diff --git a/src/xhtmlcss.outlang b/src/xhtmlcss.outlang
index 215800f..1b1387f 100644
--- a/src/xhtmlcss.outlang
+++ b/src/xhtmlcss.outlang
@@ -7,6 +7,7 @@ doctemplate
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<meta name=\"GENERATOR\" content=\"$additional\" />
+<meta name=\"INPUTLANG\" content=\"$inputlang\" />
<title>$title</title>
<link rel=\"stylesheet\" href=\"$css\" type=\"text/css\" />
</head>
diff --git a/tests/test_ref.xhtml b/tests/test_ref.xhtml
index 05f27ec..280895d 100644
--- a/tests/test_ref.xhtml
+++ b/tests/test_ref.xhtml
@@ -7,6 +7,7 @@
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite" />
+<meta name="INPUTLANG" content="cpp.lang" />
<title>XHTML with refs</title>
<link rel="stylesheet" href="../src/default.css" type="text/css" />
</head>
diff --git a/tests/test_xhtml_css_doc.html b/tests/test_xhtml_css_doc.html
index 5b85a1f..96d9b4a 100644
--- a/tests/test_xhtml_css_doc.html
+++ b/tests/test_xhtml_css_doc.html
@@ -7,6 +7,7 @@
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite" />
+<meta name="INPUTLANG" content="./../src/java.lang" />
<title>source file</title>
<link rel="stylesheet" href="../doc/mono.css" type="text/css" />
</head>
diff --git a/tests/test_xhtml_doc.html b/tests/test_xhtml_doc.html
index fcdd6cd..34b195c 100644
--- a/tests/test_xhtml_doc.html
+++ b/tests/test_xhtml_doc.html
@@ -7,6 +7,7 @@
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite" />
+<meta name="INPUTLANG" content="./../src/java.lang" />
<title>source file</title>
</head>
<body style="background-color: white">
- Re: [Help-source-highlight] Embedding inputlang as information,
Masatake YAMATO <=