aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-03-17 11:29:44 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-03-17 13:00:17 +0000
commita9cfd514d33361c34d752cbea56d8a8ca9f9dede (patch)
tree7e0291e7145b6c34cd2c0c86f1c48ccf245e6e6f
parent625cc465df179040356cd49668ab69481a7f290c (diff)
Refactor the character handler of the typedatabase XML parser
The function is called from the XML parser as well as with strings from an imported file. Change the function to be a template taking a QString/QStringRef and add necessary overloads to the setters. This prevents newlines and unused content in the XML files from unnecessarily being converted to a QString. Change-Id: Ifbac37c9099d799a8a334f46f78050dcbd52fad1 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--ApiExtractor/typesystem.cpp5
-rw-r--r--ApiExtractor/typesystem.h13
-rw-r--r--ApiExtractor/typesystem_p.h3
3 files changed, 10 insertions, 11 deletions
diff --git a/ApiExtractor/typesystem.cpp b/ApiExtractor/typesystem.cpp
index 0575b3224..a815d7de6 100644
--- a/ApiExtractor/typesystem.cpp
+++ b/ApiExtractor/typesystem.cpp
@@ -145,7 +145,7 @@ bool Handler::parse(QXmlStreamReader &reader)
}
break;
case QXmlStreamReader::Characters:
- if (!characters(reader.text().toString())) {
+ if (!characters(reader.text())) {
m_error = msgReaderError(reader, m_error);
return false;
}
@@ -322,7 +322,8 @@ bool Handler::endElement(const QStringRef &localName)
return true;
}
-bool Handler::characters(const QString &ch)
+template <class String> // QString/QStringRef
+bool Handler::characters(const String &ch)
{
if (m_currentDroppedEntry || m_ignoreDepth)
return true;
diff --git a/ApiExtractor/typesystem.h b/ApiExtractor/typesystem.h
index 279d3f0de..71e7d235f 100644
--- a/ApiExtractor/typesystem.h
+++ b/ApiExtractor/typesystem.h
@@ -118,10 +118,8 @@ class CodeSnipAbstract
public:
QString code() const;
- void addCode(const QString &code)
- {
- codeList.append(CodeSnipFragment(code));
- }
+ void addCode(const QString &code) { codeList.append(CodeSnipFragment(code)); }
+ void addCode(const QStringRef &code) { addCode(code.toString()); }
void addTemplateInstance(TemplateInstance *ti)
{
@@ -533,10 +531,9 @@ public:
DocModification(TypeSystem::DocModificationMode mode, const QString& signature, double vr)
: m_mode(mode), m_signature(signature), m_version(vr) {}
- void setCode(const QString& code)
- {
- m_code = code;
- }
+ void setCode(const QString& code) { m_code = code; }
+ void setCode(const QStringRef& code) { m_code = code.toString(); }
+
QString code() const
{
return m_code;
diff --git a/ApiExtractor/typesystem_p.h b/ApiExtractor/typesystem_p.h
index d359f9b45..a3744e7c5 100644
--- a/ApiExtractor/typesystem_p.h
+++ b/ApiExtractor/typesystem_p.h
@@ -141,7 +141,8 @@ public:
private:
bool startElement(const QStringRef& localName, const QXmlStreamAttributes& atts);
bool endElement(const QStringRef& localName);
- bool characters(const QString &ch);
+ template <class String> // QString/QStringRef
+ bool characters(const String &ch);
void fetchAttributeValues(const QString &name, const QXmlStreamAttributes &atts,
QHash<QString, QString> *acceptedAttributes);