summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2010-02-09 15:45:28 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2010-02-09 15:45:28 (GMT)
commitc908a57a54b7ad63ec06b7dcf7b3c5a4d54dd999 (patch)
treed313be14b4574a78354ec9dad8dcd1e6fd0c54de /tools
parent3abc322eb6834aa61cc77d73dbd17c4389accb00 (diff)
parent4027c52d9fb6ea1bca13e1f3a2bc5ac5032387e0 (diff)
downloadQt-c908a57a54b7ad63ec06b7dcf7b3c5a4d54dd999.zip
Qt-c908a57a54b7ad63ec06b7dcf7b3c5a4d54dd999.tar.gz
Qt-c908a57a54b7ad63ec06b7dcf7b3c5a4d54dd999.tar.bz2
Merge branch 'qdoc-i18n'
Diffstat (limited to 'tools')
-rw-r--r--tools/qdoc3/config.cpp4
-rw-r--r--tools/qdoc3/config.h3
-rw-r--r--tools/qdoc3/cppcodeparser.cpp12
-rw-r--r--tools/qdoc3/doc.cpp3
-rw-r--r--tools/qdoc3/htmlgenerator.cpp137
-rw-r--r--tools/qdoc3/htmlgenerator.h3
-rw-r--r--tools/qdoc3/linguistgenerator.cpp4
-rw-r--r--tools/qdoc3/pagegenerator.cpp2
-rw-r--r--tools/qdoc3/pagegenerator.h6
-rw-r--r--tools/qdoc3/qsakernelparser.cpp6
-rw-r--r--tools/qdoc3/qscodeparser.cpp6
-rw-r--r--tools/qdoc3/test/qt-api-only_zh_CN.qdocconf30
-rw-r--r--tools/qdoc3/test/qt-build-docs.qdocconf16
-rw-r--r--tools/qdoc3/test/qt-build-docs_zh_CN.qdocconf92
-rw-r--r--tools/qdoc3/test/qt-html-templates_zh_CN.qdocconf25
-rw-r--r--tools/qdoc3/test/qt.qdocconf11
-rw-r--r--tools/qdoc3/tokenizer.cpp25
-rw-r--r--tools/qdoc3/tokenizer.h9
18 files changed, 298 insertions, 96 deletions
diff --git a/tools/qdoc3/config.cpp b/tools/qdoc3/config.cpp
index f62ec24..acb1576 100644
--- a/tools/qdoc3/config.cpp
+++ b/tools/qdoc3/config.cpp
@@ -671,7 +671,9 @@ void Config::load(Location location, const QString& fileName)
location.fatal(tr("Cannot open file '%1': %2").arg(fileName).arg(fin.errorString()));
}
- QString text = fin.readAll();
+ QTextStream stream(&fin);
+ stream.setCodec("UTF-8");
+ QString text = stream.readAll();
text += QLatin1String("\n\n");
text += QChar('\0');
fin.close();
diff --git a/tools/qdoc3/config.h b/tools/qdoc3/config.h
index 5e7e6f1..6f23469 100644
--- a/tools/qdoc3/config.h
+++ b/tools/qdoc3/config.h
@@ -140,8 +140,10 @@ class Config
#define CONFIG_INDEXES "indexes"
#define CONFIG_LANGUAGE "language"
#define CONFIG_MACRO "macro"
+#define CONFIG_NATURALLANGUAGE "naturallanguage"
#define CONFIG_OBSOLETELINKS "obsoletelinks"
#define CONFIG_OUTPUTDIR "outputdir"
+#define CONFIG_OUTPUTENCODING "outputencoding"
#define CONFIG_OUTPUTLANGUAGE "outputlanguage"
#define CONFIG_OUTPUTFORMATS "outputformats"
#define CONFIG_PROJECT "project"
@@ -150,6 +152,7 @@ class Config
#define CONFIG_SLOW "slow"
#define CONFIG_SHOWINTERNAL "showinternal"
#define CONFIG_SOURCEDIRS "sourcedirs"
+#define CONFIG_SOURCEENCODING "sourceencoding"
#define CONFIG_SOURCES "sources"
#define CONFIG_SPURIOUS "spurious"
#define CONFIG_STYLESHEETS "stylesheets"
diff --git a/tools/qdoc3/cppcodeparser.cpp b/tools/qdoc3/cppcodeparser.cpp
index 7d08c77..c8655a4 100644
--- a/tools/qdoc3/cppcodeparser.cpp
+++ b/tools/qdoc3/cppcodeparser.cpp
@@ -281,8 +281,8 @@ void CppCodeParser::parseHeaderFile(const Location& location,
const QString& filePath,
Tree *tree)
{
- FILE *in = fopen(QFile::encodeName(filePath), "r");
- if (!in) {
+ QFile in(filePath);
+ if (!in.open(QIODevice::ReadOnly)) {
location.error(tr("Cannot open C++ header file '%1'").arg(filePath));
return;
}
@@ -295,7 +295,7 @@ void CppCodeParser::parseHeaderFile(const Location& location,
matchDeclList(tree->root());
if (!fileTokenizer.version().isEmpty())
tree->setVersion(fileTokenizer.version());
- fclose(in);
+ in.close();
if (fileLocation.fileName() == "qiterator.h")
parseQiteratorDotH(location, filePath);
@@ -312,8 +312,8 @@ void CppCodeParser::parseSourceFile(const Location& location,
const QString& filePath,
Tree *tree)
{
- FILE *in = fopen(QFile::encodeName(filePath), "r");
- if (!in) {
+ QFile in(filePath);
+ if (!in.open(QIODevice::ReadOnly)) {
location.error(tr("Cannot open C++ source file '%1' (%2)").arg(filePath).arg(strerror(errno)));
return;
}
@@ -325,7 +325,7 @@ void CppCodeParser::parseSourceFile(const Location& location,
readToken();
usedNamespaces.clear();
matchDocsAndStuff();
- fclose(in);
+ in.close();
}
/*!
diff --git a/tools/qdoc3/doc.cpp b/tools/qdoc3/doc.cpp
index 17a6efd..ad4cdde 100644
--- a/tools/qdoc3/doc.cpp
+++ b/tools/qdoc3/doc.cpp
@@ -3056,7 +3056,8 @@ QString Doc::canonicalTitle(const QString &title)
slurping = true;
}
else {
- // !alnum && slurping -> nothin
+ result += title[i];
+ lastAlnum = result.size();
}
}
result.truncate(lastAlnum);
diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp
index 15386f1..15afd7d 100644
--- a/tools/qdoc3/htmlgenerator.cpp
+++ b/tools/qdoc3/htmlgenerator.cpp
@@ -54,6 +54,7 @@
#include <qdebug.h>
#include <qlist.h>
#include <qiterator.h>
+#include <qtextcodec.h>
QT_BEGIN_NAMESPACE
@@ -266,6 +267,15 @@ void HtmlGenerator::initializeGenerator(const Config &config)
projectUrl = config.getString(CONFIG_URL);
+ outputEncoding = config.getString(CONFIG_OUTPUTENCODING);
+ if (outputEncoding.isEmpty())
+ outputEncoding = QLatin1String("ISO-8859-1");
+ outputCodec = QTextCodec::codecForName(outputEncoding.toLocal8Bit());
+
+ naturalLanguage = config.getString(CONFIG_NATURALLANGUAGE);
+ if (naturalLanguage.isEmpty())
+ naturalLanguage = QLatin1String("en");
+
QSet<QString> editionNames = config.subVars(CONFIG_EDITION);
QSet<QString>::ConstIterator edition = editionNames.begin();
while (edition != editionNames.end()) {
@@ -431,11 +441,11 @@ int HtmlGenerator::generateAtom(const Atom *atom,
endLink();
}
else {
- out() << protect(atom->string());
+ out() << protectEnc(atom->string());
}
}
else {
- out() << protect(atom->string());
+ out() << protectEnc(atom->string());
}
break;
case Atom::BaseName:
@@ -483,7 +493,7 @@ int HtmlGenerator::generateAtom(const Atom *atom,
case Atom::C:
out() << formattingLeftMap()[ATOM_FORMATTING_TELETYPE];
if (inLink) {
- out() << protect(plainCode(atom->string()));
+ out() << protectEnc(plainCode(atom->string()));
}
else {
out() << highlightedCode(atom->string(), marker, relative);
@@ -516,7 +526,7 @@ int HtmlGenerator::generateAtom(const Atom *atom,
// fallthrough
case Atom::CodeBad:
out() << "<pre><font color=\"#404040\">"
- << trimmedTrailing(protect(plainCode(indent(codeIndent,atom->string()))))
+ << trimmedTrailing(protectEnc(plainCode(indent(codeIndent,atom->string()))))
<< "</font></pre>\n";
break;
case Atom::FootnoteLeft:
@@ -768,7 +778,7 @@ int HtmlGenerator::generateAtom(const Atom *atom,
out() << "<a name=\""
<< Doc::canonicalTitle((*s).name)
<< "\"></a>\n";
- out() << "<h3>" << protect((*s).name) << "</h3>\n";
+ out() << "<h3>" << protectEnc((*s).name) << "</h3>\n";
if (idx == Class)
generateCompactList(0, marker, ncmap.value(), QString("Q"));
else if (idx == MemberFunction) {
@@ -792,7 +802,7 @@ int HtmlGenerator::generateAtom(const Atom *atom,
<< linkForNode(pmap.key(), 0)
<< "\">";
QStringList pieces = fullName(pmap.key(), 0, marker).split("::");
- out() << protect(pieces.last());
+ out() << protectEnc(pieces.last());
out() << "</a>" << ":</p>\n";
generateSection(nlist, 0, marker, CodeMarker::Summary);
@@ -820,12 +830,12 @@ int HtmlGenerator::generateAtom(const Atom *atom,
out() << "<p align=\"center\">";
if (fileName.isEmpty()) {
out() << "<font color=\"red\">[Missing image "
- << protect(atom->string()) << "]</font>";
+ << protectEnc(atom->string()) << "]</font>";
}
else {
- out() << "<img src=\"" << protect(fileName) << "\"";
+ out() << "<img src=\"" << protectEnc(fileName) << "\"";
if (!text.isEmpty())
- out() << " alt=\"" << protect(text) << "\"";
+ out() << " alt=\"" << protectEnc(text) << "\"";
out() << " />";
helpProjectWriter->addExtraFile(fileName);
}
@@ -923,7 +933,7 @@ int HtmlGenerator::generateAtom(const Atom *atom,
// ### Trenton
out() << "<tr><td valign=\"top\"><tt>"
- << protect(plainCode(marker->markedUpEnumValue(atom->next()->string(),
+ << protectEnc(plainCode(marker->markedUpEnumValue(atom->next()->string(),
relative)))
<< "</tt></td><td align=\"center\" valign=\"top\">";
@@ -936,7 +946,7 @@ int HtmlGenerator::generateAtom(const Atom *atom,
if (itemValue.isEmpty())
out() << "?";
else
- out() << "<tt>" << protect(itemValue) << "</tt>";
+ out() << "<tt>" << protectEnc(itemValue) << "</tt>";
skipAhead = 1;
}
@@ -1052,7 +1062,7 @@ int HtmlGenerator::generateAtom(const Atom *atom,
generateLink(atom, relative, marker);
}
else {
- out() << protect(atom->string());
+ out() << protectEnc(atom->string());
}
break;
case Atom::TableLeft:
@@ -1166,7 +1176,7 @@ int HtmlGenerator::generateAtom(const Atom *atom,
out() << "<font color=\"red\"><b>&lt;Missing HTML&gt;</b></font>";
break;
case Atom::UnknownCommand:
- out() << "<font color=\"red\"><b><code>\\" << protect(atom->string())
+ out() << "<font color=\"red\"><b><code>\\" << protectEnc(atom->string())
<< "</code></b></font>";
break;
#ifdef QDOC_QML
@@ -1295,7 +1305,7 @@ void HtmlGenerator::generateClassLikeNode(const InnerNode *inner,
out() << "<a name=\""
<< registerRef((*s).name.toLower())
<< "\"></a>\n";
- out() << "<h2>" << protect((*s).name) << "</h2>\n";
+ out() << "<h2>" << protectEnc((*s).name) << "</h2>\n";
generateSection(s->members, inner, marker, CodeMarker::Summary);
}
if (!s->reimpMembers.isEmpty()) {
@@ -1304,7 +1314,7 @@ void HtmlGenerator::generateClassLikeNode(const InnerNode *inner,
out() << "<a name=\""
<< registerRef(name.toLower())
<< "\"></a>\n";
- out() << "<h2>" << protect(name) << "</h2>\n";
+ out() << "<h2>" << protectEnc(name) << "</h2>\n";
generateSection(s->reimpMembers, inner, marker, CodeMarker::Summary);
}
@@ -1343,7 +1353,7 @@ void HtmlGenerator::generateClassLikeNode(const InnerNode *inner,
s = sections.begin();
while (s != sections.end()) {
out() << "<hr />\n";
- out() << "<h2>" << protect((*s).name) << "</h2>\n";
+ out() << "<h2>" << protectEnc((*s).name) << "</h2>\n";
NodeList::ConstIterator m = (*s).members.begin();
while (m != (*s).members.end()) {
@@ -1518,7 +1528,7 @@ void HtmlGenerator::generateFakeNode(const FakeNode *fake, CodeMarker *marker)
s = sections.begin();
while (s != sections.end()) {
out() << "<a name=\"" << registerRef((*s).name) << "\"></a>\n";
- out() << "<h2>" << protect((*s).name) << "</h2>\n";
+ out() << "<h2>" << protectEnc((*s).name) << "</h2>\n";
generateQmlSummary(*s,fake,marker);
++s;
}
@@ -1534,7 +1544,7 @@ void HtmlGenerator::generateFakeNode(const FakeNode *fake, CodeMarker *marker)
sections = marker->qmlSections(qml_cn,CodeMarker::Detailed);
s = sections.begin();
while (s != sections.end()) {
- out() << "<h2>" << protect((*s).name) << "</h2>\n";
+ out() << "<h2>" << protectEnc((*s).name) << "</h2>\n";
NodeList::ConstIterator m = (*s).members.begin();
while (m != (*s).members.end()) {
generateDetailedQmlMember(*m, fake, marker);
@@ -1554,7 +1564,7 @@ void HtmlGenerator::generateFakeNode(const FakeNode *fake, CodeMarker *marker)
s = sections.begin();
while (s != sections.end()) {
out() << "<a name=\"" << registerRef((*s).name) << "\"></a>\n";
- out() << "<h2>" << protect((*s).name) << "</h2>\n";
+ out() << "<h2>" << protectEnc((*s).name) << "</h2>\n";
generateSectionList(*s, fake, marker, CodeMarker::Summary);
++s;
}
@@ -1583,7 +1593,7 @@ void HtmlGenerator::generateFakeNode(const FakeNode *fake, CodeMarker *marker)
s = sections.begin();
while (s != sections.end()) {
out() << "<hr />\n";
- out() << "<h2>" << protect((*s).name) << "</h2>\n";
+ out() << "<h2>" << protectEnc((*s).name) << "</h2>\n";
NodeList::ConstIterator m = (*s).members.begin();
while (m != (*s).members.end()) {
@@ -1629,11 +1639,11 @@ void HtmlGenerator::generateHeader(const QString& title,
CodeMarker *marker,
bool mainPage)
{
- out() << "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
+ out() << QString("<?xml version=\"1.0\" encoding=\"%1\"?>\n").arg(outputEncoding);
out() << "<!DOCTYPE html\n"
- " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">\n"
- "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
+ " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">\n";
+ out() << QString("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"%1\" lang=\"%1\">\n").arg(naturalLanguage);
QString shortVersion;
if ((project != "Qtopia") && (project != "Qt Extended")) {
@@ -1653,7 +1663,9 @@ void HtmlGenerator::generateHeader(const QString& title,
}
out() << "<head>\n"
- " <title>" << shortVersion << protect(title) << "</title>\n";
+ " <title>" << shortVersion << protectEnc(title) << "</title>\n";
+ out() << QString("<meta http-equiv=\"Content-type\" content=\"text/html; charset=%1\" />").arg(outputEncoding);
+
if (!style.isEmpty())
out() << " <style type=\"text/css\">" << style << "</style>\n";
@@ -1662,8 +1674,8 @@ void HtmlGenerator::generateHeader(const QString& title,
QMapIterator<QString, QString> i(metaMap);
while (i.hasNext()) {
i.next();
- out() << " <meta name=\"" << protect(i.key()) << "\" contents=\""
- << protect(i.value()) << "\" />\n";
+ out() << " <meta name=\"" << protectEnc(i.key()) << "\" contents=\""
+ << protectEnc(i.value()) << "\" />\n";
}
}
@@ -1687,9 +1699,9 @@ void HtmlGenerator::generateHeader(const QString& title,
navigationLinks += "[Previous: <a href=\"" + anchorPair.first + "\">";
if (linkPair.first == linkPair.second && !anchorPair.second.isEmpty())
- navigationLinks += protect(anchorPair.second);
+ navigationLinks += protectEnc(anchorPair.second);
else
- navigationLinks += protect(linkPair.second);
+ navigationLinks += protectEnc(linkPair.second);
navigationLinks += "</a>]\n";
}
if (node->links().contains(Node::ContentsLink)) {
@@ -1705,9 +1717,9 @@ void HtmlGenerator::generateHeader(const QString& title,
navigationLinks += "[<a href=\"" + anchorPair.first + "\">";
if (linkPair.first == linkPair.second && !anchorPair.second.isEmpty())
- navigationLinks += protect(anchorPair.second);
+ navigationLinks += protectEnc(anchorPair.second);
else
- navigationLinks += protect(linkPair.second);
+ navigationLinks += protectEnc(linkPair.second);
navigationLinks += "</a>]\n";
}
if (node->links().contains(Node::NextLink)) {
@@ -1723,9 +1735,9 @@ void HtmlGenerator::generateHeader(const QString& title,
navigationLinks += "[Next: <a href=\"" + anchorPair.first + "\">";
if (linkPair.first == linkPair.second && !anchorPair.second.isEmpty())
- navigationLinks += protect(anchorPair.second);
+ navigationLinks += protectEnc(anchorPair.second);
else
- navigationLinks += protect(linkPair.second);
+ navigationLinks += protectEnc(linkPair.second);
navigationLinks += "</a>]\n";
}
if (node->links().contains(Node::IndexLink)) {
@@ -1776,7 +1788,7 @@ void HtmlGenerator::generateTitle(const QString& title,
const Node *relative,
CodeMarker *marker)
{
- out() << "<h1 class=\"title\">" << protect(title);
+ out() << "<h1 class=\"title\">" << protectEnc(title);
if (!subTitle.isEmpty()) {
out() << "<br />";
if (subTitleSize == SmallSubTitle)
@@ -2014,18 +2026,18 @@ QString HtmlGenerator::generateLowStatusMemberFile(const InnerNode *inner,
out() << "<p><ul><li><a href=\""
<< linkForNode(inner, 0) << "\">"
- << protect(inner->name())
+ << protectEnc(inner->name())
<< " class reference</a></li></ul></p>\n";
for (i = 0; i < sections.size(); ++i) {
- out() << "<h2>" << protect(sections.at(i).name) << "</h2>\n";
+ out() << "<h2>" << protectEnc(sections.at(i).name) << "</h2>\n";
generateSectionList(sections.at(i), inner, marker, CodeMarker::Summary);
}
sections = marker->sections(inner, CodeMarker::Detailed, status);
for (i = 0; i < sections.size(); ++i) {
out() << "<hr />\n";
- out() << "<h2>" << protect(sections.at(i).name) << "</h2>\n";
+ out() << "<h2>" << protectEnc(sections.at(i).name) << "</h2>\n";
NodeList::ConstIterator m = sections.at(i).members.begin();
while (m != sections.at(i).members.end()) {
@@ -2118,7 +2130,7 @@ void HtmlGenerator::generateAnnotatedList(const Node *relative,
}
else {
out() << "<td>";
- out() << protect(node->doc().briefText().toString());
+ out() << protectEnc(node->doc().briefText().toString());
out() << "</td>";
}
out() << "</tr>\n";
@@ -2320,7 +2332,7 @@ void HtmlGenerator::generateCompactList(const Node *relative,
<< linkForNode(it.value(), relative)
<< "\">";
QStringList pieces = fullName(it.value(), relative, marker).split("::");
- out() << protect(pieces.last());
+ out() << protectEnc(pieces.last());
out() << "</a>";
if (pieces.size() > 1) {
out() << " (";
@@ -2362,7 +2374,7 @@ void HtmlGenerator::generateFunctionIndex(const Node *relative,
#else
out() << "<p>";
#endif
- out() << protect(f.key()) << ":";
+ out() << protectEnc(f.key()) << ":";
currentLetter = f.key()[0].unicode();
while (islower(currentLetter) && currentLetter >= nextLetter) {
@@ -2416,7 +2428,7 @@ void HtmlGenerator::generateLegaleseList(const Node *relative,
QString marked = marker->markedUpSynopsis(node, relative, style);
QRegExp templateTag("(<[^@>]*>)");
if (marked.indexOf(templateTag) != -1) {
- QString contents = protect(marked.mid(templateTag.pos(1),
+ QString contents = protectEnc(marked.mid(templateTag.pos(1),
templateTag.cap(1).length()));
marked.replace(templateTag.pos(1), templateTag.cap(1).length(),
contents);
@@ -2455,7 +2467,7 @@ void HtmlGenerator::generateQmlItem(const Node *node,
QString marked = marker->markedUpQmlItem(node,summary);
QRegExp templateTag("(<[^@>]*>)");
if (marked.indexOf(templateTag) != -1) {
- QString contents = protect(marked.mid(templateTag.pos(1),
+ QString contents = protectEnc(marked.mid(templateTag.pos(1),
templateTag.cap(1).length()));
marked.replace(templateTag.pos(1), templateTag.cap(1).length(),
contents);
@@ -2561,7 +2573,7 @@ void HtmlGenerator::generateOverviewList(const Node *relative, CodeMarker * /* m
const FakeNode *groupNode = groupTitlesMap[groupTitle];
out() << QString("<h3><a href=\"%1\">%2</a></h3>\n").arg(
linkForNode(groupNode, relative)).arg(
- protect(groupNode->fullTitle()));
+ protectEnc(groupNode->fullTitle()));
if (fakeNodeMap[groupNode].count() == 0)
continue;
@@ -2573,7 +2585,7 @@ void HtmlGenerator::generateOverviewList(const Node *relative, CodeMarker * /* m
if (title.startsWith("The "))
title.remove(0, 4);
out() << "<li><a href=\"" << linkForNode(fakeNode, relative) << "\">"
- << protect(title) << "</a></li>\n";
+ << protectEnc(title) << "</a></li>\n";
}
out() << "</ul>\n";
}
@@ -2587,7 +2599,7 @@ void HtmlGenerator::generateOverviewList(const Node *relative, CodeMarker * /* m
if (title.startsWith("The "))
title.remove(0, 4);
out() << "<li><a href=\"" << linkForNode(fakeNode, relative) << "\">"
- << protect(title) << "</a></li>\n";
+ << protectEnc(title) << "</a></li>\n";
}
out() << "</ul>\n";
}
@@ -2750,7 +2762,7 @@ void HtmlGenerator::generateSectionInheritedList(const Section& section,
}
out() << " inherited from <a href=\"" << fileName((*p).first)
<< "#" << HtmlGenerator::cleanRef(section.name.toLower()) << "\">"
- << protect(marker->plainFullName((*p).first, relative))
+ << protectEnc(marker->plainFullName((*p).first, relative))
<< "</a></li>\n";
++p;
}
@@ -2765,7 +2777,7 @@ void HtmlGenerator::generateSynopsis(const Node *node,
QString marked = marker->markedUpSynopsis(node, relative, style);
QRegExp templateTag("(<[^@>]*>)");
if (marked.indexOf(templateTag) != -1) {
- QString contents = protect(marked.mid(templateTag.pos(1),
+ QString contents = protectEnc(marked.mid(templateTag.pos(1),
templateTag.cap(1).length()));
marked.replace(templateTag.pos(1), templateTag.cap(1).length(),
contents);
@@ -3034,7 +3046,7 @@ void HtmlGenerator::generateSectionInheritedList(const Section& section,
}
out() << " inherited from <a href=\"" << fileName((*p).first)
<< "#" << HtmlGenerator::cleanRef(section.name.toLower()) << "\">"
- << protect(marker->plainFullName((*p).first, relative))
+ << protectEnc(marker->plainFullName((*p).first, relative))
<< "</a></li>\n";
++p;
}
@@ -3048,7 +3060,7 @@ void HtmlGenerator::generateSynopsis(const Node *node,
QString marked = marker->markedUpSynopsis(node, relative, style);
QRegExp templateTag("(<[^@>]*>)");
if (marked.indexOf(templateTag) != -1) {
- QString contents = protect(marked.mid(templateTag.pos(1),
+ QString contents = protectEnc(marked.mid(templateTag.pos(1),
templateTag.cap(1).length()));
marked.replace(templateTag.pos(1), templateTag.cap(1).length(),
contents);
@@ -3246,7 +3258,7 @@ void HtmlGenerator::generateLink(const Atom* atom,
if (funcLeftParen.indexIn(atom->string()) != -1 && marker->recognizeLanguage("Cpp")) {
// hack for C++: move () outside of link
int k = funcLeftParen.pos(1);
- out() << protect(atom->string().left(k));
+ out() << protectEnc(atom->string().left(k));
if (link.isEmpty()) {
if (showBrokenLinks)
out() << "</i>";
@@ -3254,7 +3266,7 @@ void HtmlGenerator::generateLink(const Atom* atom,
out() << "</a>";
}
inLink = false;
- out() << protect(atom->string().mid(k));
+ out() << protectEnc(atom->string().mid(k));
} else if (marker->recognizeLanguage("Java")) {
// hack for Java: remove () and use <tt> when appropriate
bool func = atom->string().endsWith("()");
@@ -3262,13 +3274,13 @@ void HtmlGenerator::generateLink(const Atom* atom,
if (tt)
out() << "<tt>";
if (func) {
- out() << protect(atom->string().left(atom->string().length() - 2));
+ out() << protectEnc(atom->string().left(atom->string().length() - 2));
} else {
- out() << protect(atom->string());
+ out() << protectEnc(atom->string());
}
out() << "</tt>";
} else {
- out() << protect(atom->string());
+ out() << protectEnc(atom->string());
}
}
@@ -3342,7 +3354,12 @@ QString HtmlGenerator::registerRef(const QString& ref)
return clean;
}
-QString HtmlGenerator::protect(const QString& string)
+QString HtmlGenerator::protectEnc(const QString &string)
+{
+ return protect(string, outputEncoding);
+}
+
+QString HtmlGenerator::protect(const QString &string, const QString &outputEncoding)
{
#define APPEND(x) \
if (html.isEmpty()) { \
@@ -3365,7 +3382,7 @@ QString HtmlGenerator::protect(const QString& string)
APPEND("&gt;");
} else if (ch == QLatin1Char('"')) {
APPEND("&quot;");
- } else if (ch.unicode() > 0x007F
+ } else if ((outputEncoding == "ISO-8859-1" && ch.unicode() > 0x007F)
|| (ch == QLatin1Char('*') && i + 1 < n && string.at(i) == QLatin1Char('/'))
|| (ch == QLatin1Char('.') && i > 2 && string.at(i - 2) == QLatin1Char('.'))) {
// we escape '*/' and the last dot in 'e.g.' and 'i.e.' for the Javadoc generator
@@ -3495,7 +3512,7 @@ QString HtmlGenerator::refForNode(const Node *node)
ref = node->name() + "-var";
break;
case Node::Target:
- return protect(node->name());
+ return protectEnc(node->name());
}
return registerRef(ref);
}
@@ -3569,7 +3586,7 @@ void HtmlGenerator::generateFullName(const Node *apparentNode,
}
}
out() << "\">";
- out() << protect(fullName(apparentNode, relative, marker));
+ out() << protectEnc(fullName(apparentNode, relative, marker));
out() << "</a>";
}
@@ -3630,12 +3647,12 @@ void HtmlGenerator::generateDetailedMember(const Node *node,
else if (node->type() == Node::Enum) {
const EnumNode *enume = static_cast<const EnumNode *>(node);
if (enume->flagsType()) {
- out() << "<p>The " << protect(enume->flagsType()->name())
+ out() << "<p>The " << protectEnc(enume->flagsType()->name())
<< " type is a typedef for "
<< "<a href=\"qflags.html\">QFlags</a>&lt;"
- << protect(enume->name())
+ << protectEnc(enume->name())
<< "&gt;. It stores an OR combination of "
- << protect(enume->name())
+ << protectEnc(enume->name())
<< " values.</p>\n";
}
}
diff --git a/tools/qdoc3/htmlgenerator.h b/tools/qdoc3/htmlgenerator.h
index 19a7c78..5ed26e0 100644
--- a/tools/qdoc3/htmlgenerator.h
+++ b/tools/qdoc3/htmlgenerator.h
@@ -104,7 +104,8 @@ class HtmlGenerator : public PageGenerator
virtual QString format();
virtual void generateTree(const Tree *tree, CodeMarker *marker);
- static QString protect(const QString& string);
+ QString protectEnc(const QString &string);
+ static QString protect(const QString &string, const QString &encoding = "ISO-8859-1");
static QString cleanRef(const QString& ref);
static QString sinceTitle(int i) { return sinceTitles[i]; }
diff --git a/tools/qdoc3/linguistgenerator.cpp b/tools/qdoc3/linguistgenerator.cpp
index d1bd22d..21678e0 100644
--- a/tools/qdoc3/linguistgenerator.cpp
+++ b/tools/qdoc3/linguistgenerator.cpp
@@ -89,7 +89,7 @@ QString LinguistGenerator::fileExtension(const Node * /* node */)
void LinguistGenerator::generateClassLikeNode(const InnerNode *inner, CodeMarker *marker)
{
- out().setCodec("utf-8");
+ out().setCodec("UTF-8");
QDomDocument document("TS");
QDomElement documentElement = document.createElement("TS");
@@ -100,7 +100,7 @@ void LinguistGenerator::generateClassLikeNode(const InnerNode *inner, CodeMarker
documentElement.appendChild(element);
QDomProcessingInstruction process = document.createProcessingInstruction(
- "xml", QString("version=\"1.0\" encoding=\"%1\"").arg("utf-8"));
+ "xml", QString("version=\"1.0\" encoding=\"%1\"").arg("UTF-8"));
document.appendChild(process);
document.appendChild(documentElement);
diff --git a/tools/qdoc3/pagegenerator.cpp b/tools/qdoc3/pagegenerator.cpp
index 07edcc4..bc73eb0 100644
--- a/tools/qdoc3/pagegenerator.cpp
+++ b/tools/qdoc3/pagegenerator.cpp
@@ -177,7 +177,7 @@ void PageGenerator::beginSubPage(const Location& location,
location.fatal(tr("Cannot open output file '%1'")
.arg(outFile->fileName()));
QTextStream *out = new QTextStream(outFile);
- out->setCodec("ISO-8859-1");
+ out->setCodec(outputCodec);
outStreamStack.push(out);
}
diff --git a/tools/qdoc3/pagegenerator.h b/tools/qdoc3/pagegenerator.h
index db24edd..20a6c3c 100644
--- a/tools/qdoc3/pagegenerator.h
+++ b/tools/qdoc3/pagegenerator.h
@@ -54,6 +54,8 @@
QT_BEGIN_NAMESPACE
+class QTextCodec;
+
class ClassNode;
class InnerNode;
class NamespaceNode;
@@ -76,6 +78,10 @@ class PageGenerator : public Generator
virtual void generateInnerNode(const InnerNode *node, CodeMarker *marker);
QTextStream& out();
+ QString naturalLanguage;
+ QString outputEncoding;
+ QTextCodec *outputCodec;
+
private:
QStack<QTextStream *> outStreamStack;
};
diff --git a/tools/qdoc3/qsakernelparser.cpp b/tools/qdoc3/qsakernelparser.cpp
index 9320a17..8f12eda 100644
--- a/tools/qdoc3/qsakernelparser.cpp
+++ b/tools/qdoc3/qsakernelparser.cpp
@@ -70,8 +70,8 @@ void QsaKernelParser::parseSourceFile( const Location& location,
const QString& filePath,
Tree * /* tree */ )
{
- FILE *in = fopen( QFile::encodeName(filePath), "r" );
- if ( in == 0 ) {
+ QFile in(filePath);
+ if (!in.open(QIODevice::ReadOnly)) {
location.error( tr("Cannot open QSA kernel file '%1'").arg(filePath) );
return;
}
@@ -171,7 +171,7 @@ void QsaKernelParser::parseSourceFile( const Location& location,
readToken();
}
}
- fclose( in );
+ in.close();
}
void QsaKernelParser::doneParsingSourceFiles( Tree * /* tree */ )
diff --git a/tools/qdoc3/qscodeparser.cpp b/tools/qdoc3/qscodeparser.cpp
index 8b3bc98..3b8bc1a 100644
--- a/tools/qdoc3/qscodeparser.cpp
+++ b/tools/qdoc3/qscodeparser.cpp
@@ -151,8 +151,8 @@ void QsCodeParser::parseHeaderFile(const Location& location,
{
qsTre = tree;
- FILE *in = fopen(QFile::encodeName(filePath), "r");
- if (in == 0) {
+ QFile in(filePath);
+ if (!in.open(QIODevice::ReadOnly)) {
location.error(tr("Cannot open Qt Script class list '%1'")
.arg(filePath));
return;
@@ -175,7 +175,7 @@ void QsCodeParser::parseHeaderFile(const Location& location,
}
tok = fileTokenizer.getToken();
}
- fclose(in);
+ in.close();
}
void QsCodeParser::parseSourceFile(const Location& location,
diff --git a/tools/qdoc3/test/qt-api-only_zh_CN.qdocconf b/tools/qdoc3/test/qt-api-only_zh_CN.qdocconf
new file mode 100644
index 0000000..c722ee8
--- /dev/null
+++ b/tools/qdoc3/test/qt-api-only_zh_CN.qdocconf
@@ -0,0 +1,30 @@
+include(qt-build-docs_zh_CN.qdocconf)
+
+# Ensures that the generated index contains a URL that can be used by the
+# tools documentation (assistant.qdocconf, designer.qdocconf, linguist.qdocconf,
+# qmake.qdocconf).
+
+url = ./
+
+# Ensures that the documentation for the tools is not included in the generated
+# .qhp file.
+
+qhp.Qt.excluded += $QT_SOURCE_TREE/doc/src/development/assistant-manual.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/simpletextviewer.qdoc \
+ $QT_SOURCE_TREE/doc/src/development/designer-manual.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/calculatorbuilder.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/calculatorform.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/customwidgetplugin.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/taskmenuextension.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/containerextension.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/worldtimeclockbuilder.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/worldtimeclockplugin.qdoc \
+ $QT_SOURCE_TREE/doc/src/internationalization/linguist-manual.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/hellotr.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/arrowpad.qdoc \
+ $QT_SOURCE_TREE/doc/src/examples/trollprint.qdoc \
+ $QT_SOURCE_TREE/doc/src/development/qmake-manual.qdoc
+
+outputdir = $QT_BUILD_TREE/doc-build/html-qt_zh_CN
+tagfile = $QT_BUILD_TREE/doc-build/html-qt_zh_CN/qt.tags
+base = file:$QT_BUILD_TREE/doc-build/html-qt_zh_CN
diff --git a/tools/qdoc3/test/qt-build-docs.qdocconf b/tools/qdoc3/test/qt-build-docs.qdocconf
index e8595f6..4f1ae5d 100644
--- a/tools/qdoc3/test/qt-build-docs.qdocconf
+++ b/tools/qdoc3/test/qt-build-docs.qdocconf
@@ -8,9 +8,13 @@ project = Qt
description = Qt Reference Documentation
url = http://qt.nokia.com/doc/4.7
-edition.Desktop.modules = QtCore QtDBus QtGui QtNetwork QtOpenGL QtScript QtScriptTools QtSql QtSvg \
- QtWebKit QtXml QtXmlPatterns Qt3Support QtHelp \
- QtDesigner QtAssistant QAxContainer Phonon \
+sourceencoding = UTF-8
+outputencoding = UTF-8
+naturallanguage = en_US
+
+edition.Desktop.modules = QtCore QtDBus QtGui QtNetwork QtOpenGL QtScript \
+ QtScriptTools QtSql QtSvg QtWebKit QtXml QtXmlPatterns \
+ Qt3Support QtHelp QtDesigner QtAssistant QAxContainer Phonon \
QAxServer QtUiTools QtTest QtDBus
edition.DesktopLight.modules = QtCore QtDBus QtGui Qt3SupportLight QtTest
@@ -90,11 +94,13 @@ excludedirs = $QT_SOURCE_TREE/src/3rdparty/clucene \
$QT_SOURCE_TREE/src/3rdparty/webkit/WebCore \
$QT_SOURCE_TREE/src/3rdparty/wintab \
$QT_SOURCE_TREE/src/3rdparty/zlib \
- $QT_SOURCE_TREE/doc/src/snippets \
$QT_SOURCE_TREE/src/3rdparty/phonon/gstreamer \
$QT_SOURCE_TREE/src/3rdparty/phonon/ds9 \
$QT_SOURCE_TREE/src/3rdparty/phonon/qt7 \
- $QT_SOURCE_TREE/src/3rdparty/phonon/waveout
+ $QT_SOURCE_TREE/src/3rdparty/phonon/mmf \
+ $QT_SOURCE_TREE/src/3rdparty/phonon/waveout \
+ $QT_SOURCE_TREE/doc/src/snippets \
+ $QT_SOURCE_TREE/doc/src/zh_CN
sources.fileextensions = "*.cpp *.qdoc *.mm"
examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp"
diff --git a/tools/qdoc3/test/qt-build-docs_zh_CN.qdocconf b/tools/qdoc3/test/qt-build-docs_zh_CN.qdocconf
new file mode 100644
index 0000000..18b72a1
--- /dev/null
+++ b/tools/qdoc3/test/qt-build-docs_zh_CN.qdocconf
@@ -0,0 +1,92 @@
+include(compat.qdocconf)
+include(macros.qdocconf)
+include(qt-cpp-ignore.qdocconf)
+include(qt-html-templates_zh_CN.qdocconf)
+include(qt-defines.qdocconf)
+
+project = Qt
+description = Qt Reference Documentation
+url = http://qt.nokia.com/doc/zh_CN/4.7
+
+sourceencoding = UTF-8
+outputencoding = UTF-8
+naturallanguage = zh-Hans
+
+indexes = $QT_BUILD_TREE/doc-build/html-qt/qt.index
+
+edition.Desktop.modules = QtCore QtDBus QtGui QtNetwork QtOpenGL QtScript \
+ QtScriptTools QtSql QtSvg QtWebKit QtXml QtXmlPatterns \
+ Qt3Support QtHelp QtDesigner QtAssistant QAxContainer Phonon \
+ QAxServer QtUiTools QtTest QtDBus
+
+edition.DesktopLight.modules = QtCore QtDBus QtGui Qt3SupportLight QtTest
+edition.DesktopLight.groups = -graphicsview-api
+
+qhp.projects = Qt
+
+qhp.Qt.file = qt.qhp
+qhp.Qt.namespace = com.trolltech.qt.470
+qhp.Qt.virtualFolder = qdoc
+qhp.Qt.title = 教程
+qhp.Qt.indexTitle = 教程
+qhp.Qt.selectors = fake:example
+
+qhp.Qt.filterAttributes = qt 4.7.0 qtrefdoc zh_CN
+qhp.Qt.customFilters.Qt.name = Qt 4.7.0
+qhp.Qt.customFilters.Qt.filterAttributes = qt 4.7.0
+
+# Files not referenced in any qdoc file (last four are needed by qtdemo)
+# See also extraimages.HTML
+qhp.Qt.extraFiles = classic.css \
+ images/qt-logo.png \
+ images/taskmenuextension-example.png \
+ images/coloreditorfactoryimage.png \
+ images/dynamiclayouts-example.png \
+ images/stylesheet-coffee-plastique.png
+
+language = Cpp
+
+sourcedirs = $QT_SOURCE_TREE/doc/src/zh_CN
+
+excludedirs = $QT_SOURCE_TREE/src/3rdparty/clucene \
+ $QT_SOURCE_TREE/src/3rdparty/des \
+ $QT_SOURCE_TREE/src/3rdparty/freetype \
+ $QT_SOURCE_TREE/src/3rdparty/harfbuzz \
+ $QT_SOURCE_TREE/src/3rdparty/kdebase \
+ $QT_SOURCE_TREE/src/3rdparty/libjpeg \
+ $QT_SOURCE_TREE/src/3rdparty/libmng \
+ $QT_SOURCE_TREE/src/3rdparty/libpng \
+ $QT_SOURCE_TREE/src/3rdparty/libtiff \
+ $QT_SOURCE_TREE/src/3rdparty/md4 \
+ $QT_SOURCE_TREE/src/3rdparty/md5 \
+ $QT_SOURCE_TREE/src/3rdparty/patches \
+ $QT_SOURCE_TREE/src/3rdparty/sha1 \
+ $QT_SOURCE_TREE/src/3rdparty/sqlite \
+ $QT_SOURCE_TREE/src/3rdparty/webkit/JavaScriptCore \
+ $QT_SOURCE_TREE/src/3rdparty/webkit/WebCore \
+ $QT_SOURCE_TREE/src/3rdparty/wintab \
+ $QT_SOURCE_TREE/src/3rdparty/zlib \
+ $QT_SOURCE_TREE/doc/src/snippets \
+ $QT_SOURCE_TREE/src/3rdparty/phonon/gstreamer \
+ $QT_SOURCE_TREE/src/3rdparty/phonon/ds9 \
+ $QT_SOURCE_TREE/src/3rdparty/phonon/qt7 \
+ $QT_SOURCE_TREE/src/3rdparty/phonon/mmf \
+ $QT_SOURCE_TREE/src/3rdparty/phonon/waveout
+
+sources.fileextensions = "*.cpp *.qdoc *.mm"
+examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp"
+examples.imageextensions = "*.png"
+
+exampledirs = $QT_SOURCE_TREE/doc/src \
+ $QT_SOURCE_TREE/examples \
+ $QT_SOURCE_TREE/examples/tutorials \
+ $QT_SOURCE_TREE \
+ $QT_SOURCE_TREE/qmake/examples \
+ $QT_SOURCE_TREE/src/3rdparty/webkit/WebKit/qt/docs
+imagedirs = $QT_SOURCE_TREE/doc/src/images \
+ $QT_SOURCE_TREE/examples
+outputdir = $QT_BUILD_TREE/doc/html_zh_CN
+tagfile = $QT_BUILD_TREE/doc/html_zh_CN/qt.tags
+base = file:$QT_BUILD_TREE/doc/html_zh_CN
+
+HTML.generatemacrefs = "true"
diff --git a/tools/qdoc3/test/qt-html-templates_zh_CN.qdocconf b/tools/qdoc3/test/qt-html-templates_zh_CN.qdocconf
new file mode 100644
index 0000000..5fb68cf
--- /dev/null
+++ b/tools/qdoc3/test/qt-html-templates_zh_CN.qdocconf
@@ -0,0 +1,25 @@
+HTML.stylesheets = classic.css
+HTML.postheader = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n" \
+ "<tr>\n" \
+ "<td align=\"left\" valign=\"top\" width=\"32\">" \
+ "<a href=\"http://qt.nokia.com/\"><img src=\"images/qt-logo.png\" align=\"left\" border=\"0\" /></a>" \
+ "</td>\n" \
+ "<td width=\"1\">&nbsp;&nbsp;</td>" \
+ "<td class=\"postheader\" valign=\"center\">" \
+ "<a href=\"http://qt.nokia.com/doc/4.7/index.html\">" \
+ "<font color=\"#004faf\">主页</font></a>&nbsp;&middot;" \
+ " <a href=\"http://qt.nokia.com/doc/4.7/classes.html\">" \
+ "<font color=\"#004faf\">所有类</font></a>&nbsp;&middot;" \
+ " <a href=\"http://qt.nokia.com/doc/4.7/functions.html\">" \
+ "<font color=\"#004faf\">所有函数</font></a>&nbsp;&middot;" \
+ " <a href=\"http://qt.nokia.com/doc/4.7/overviews.html\">" \
+ "<font color=\"#004faf\">简介</font></a>" \
+ "</td>" \
+ "</tr></table>"
+
+HTML.footer = "<p /><address><hr /><div align=\"center\">\n" \
+ "<table width=\"100%\" cellspacing=\"0\" border=\"0\"><tr class=\"address\">\n" \
+ "<td width=\"40%\" align=\"left\">版权所有 &copy; 2010 诺基亚公司和/或其子公司</td>\n" \
+ "<td width=\"20%\" align=\"center\"><a href=\"trademarks.html\">商标</a></td>\n" \
+ "<td width=\"40%\" align=\"right\"><div align=\"right\">Qt \\version</div></td>\n" \
+ "</tr></table></div></address>"
diff --git a/tools/qdoc3/test/qt.qdocconf b/tools/qdoc3/test/qt.qdocconf
index a066021..1039c18 100644
--- a/tools/qdoc3/test/qt.qdocconf
+++ b/tools/qdoc3/test/qt.qdocconf
@@ -10,9 +10,13 @@ version = %VERSION%
description = Qt Reference Documentation
url = http://qt.nokia.com/doc/4.7
+sourceencoding = UTF-8
+outputencoding = UTF-8
+naturallanguage = en_US
+
edition.Desktop.modules = QtCore QtDBus QtGui QtNetwork QtOpenGL QtScript \
QtScriptTools QtSql QtSvg QtWebKit QtXml QtXmlPatterns \
- Qt3Support QtHelp QtDesigner QAxContainer Phonon \
+ Qt3Support QtHelp QtDesigner QtAssistant QAxContainer Phonon \
QAxServer QtUiTools QtTest QtDBus
edition.DesktopLight.modules = QtCore QtDBus QtGui Qt3SupportLight QtTest
edition.DesktopLight.groups = -graphicsview-api
@@ -91,12 +95,13 @@ excludedirs = $QTDIR/src/3rdparty/clucene \
$QTDIR/src/3rdparty/webkit/WebCore \
$QTDIR/src/3rdparty/wintab \
$QTDIR/src/3rdparty/zlib \
- $QTDIR/doc/src/snippets \
$QTDIR/src/3rdparty/phonon/gstreamer \
$QTDIR/src/3rdparty/phonon/ds9 \
$QTDIR/src/3rdparty/phonon/qt7 \
$QTDIR/src/3rdparty/phonon/mmf \
- $QTDIR/src/3rdparty/phonon/waveout
+ $QTDIR/src/3rdparty/phonon/waveout \
+ $QTDIR/doc/src/snippets \
+ $QTDIR/doc/src/zh_CN
sources.fileextensions = "*.cpp *.qdoc *.mm"
examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp"
diff --git a/tools/qdoc3/tokenizer.cpp b/tools/qdoc3/tokenizer.cpp
index b391759..7c10de6 100644
--- a/tools/qdoc3/tokenizer.cpp
+++ b/tools/qdoc3/tokenizer.cpp
@@ -47,6 +47,7 @@
#include <qhash.h>
#include <qregexp.h>
#include <qstring.h>
+#include <qtextcodec.h>
#include <ctype.h>
#include <string.h>
@@ -97,6 +98,8 @@ static QRegExp *definedX = 0;
static QRegExp *defines = 0;
static QRegExp *falsehoods = 0;
+static QTextCodec *sourceCodec = 0;
+
/*
This function is a perfect hash function for the 37 keywords of C99
(with a hash table size of 512). It should perform well on our
@@ -118,13 +121,10 @@ static void insertKwordIntoHash(const char *s, int number)
kwordHashTable[k] = number;
}
-Tokenizer::Tokenizer(const Location& loc, FILE *in)
+Tokenizer::Tokenizer(const Location& loc, QFile &in)
{
init();
- QFile file;
- file.open(in, QIODevice::ReadOnly);
- yyIn = file.readAll();
- file.close();
+ yyIn = in.readAll();
yyPos = 0;
start(loc);
}
@@ -483,6 +483,11 @@ void Tokenizer::initialize(const Config &config)
{
QString versionSym = config.getString(CONFIG_VERSIONSYM);
+ QString sourceEncoding = config.getString(CONFIG_SOURCEENCODING);
+ if (sourceEncoding.isEmpty())
+ sourceEncoding = QLatin1String("ISO-8859-1");
+ sourceCodec = QTextCodec::codecForName(sourceEncoding.toLocal8Bit());
+
comment = new QRegExp("/(?:\\*.*\\*/|/.*\n|/[^\n]*$)");
comment->setMinimal(true);
versionX = new QRegExp("$cannot possibly match^");
@@ -750,4 +755,14 @@ bool Tokenizer::isTrue(const QString &condition)
return !falsehoods->exactMatch(t);
}
+QString Tokenizer::lexeme() const
+{
+ return sourceCodec->toUnicode(yyLex);
+}
+
+QString Tokenizer::previousLexeme() const
+{
+ return sourceCodec->toUnicode(yyPrevLex);
+}
+
QT_END_NAMESPACE
diff --git a/tools/qdoc3/tokenizer.h b/tools/qdoc3/tokenizer.h
index 519cffb..f55d2ef 100644
--- a/tools/qdoc3/tokenizer.h
+++ b/tools/qdoc3/tokenizer.h
@@ -46,11 +46,10 @@
#ifndef TOKENIZER_H
#define TOKENIZER_H
+#include <qfile.h>
#include <qstack.h>
#include <qstring.h>
-#include <stdio.h>
-
#include "location.h"
QT_BEGIN_NAMESPACE
@@ -99,7 +98,7 @@ class Tokenizer
{
public:
Tokenizer(const Location& loc, const QByteArray &in);
- Tokenizer(const Location& loc, FILE *in);
+ Tokenizer(const Location& loc, QFile &file);
~Tokenizer();
@@ -108,8 +107,8 @@ class Tokenizer
bool parsingFnOrMacro() const { return parsingMacro; }
const Location &location() const { return yyTokLoc; }
- QString previousLexeme() const { return QString(yyPrevLex); }
- QString lexeme() const { return QString(yyLex); }
+ QString previousLexeme() const;
+ QString lexeme() const;
QString version() const { return yyVersion; }
int braceDepth() const { return yyBraceDepth; }
int parenDepth() const { return yyParenDepth; }