dissolve getMacroArgs() function
authorOswald Buddenhagen <oswald.buddenhagen@digia.com>
Tue, 10 Dec 2013 20:54:23 +0000 (21:54 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 7 Jan 2014 18:49:08 +0000 (19:49 +0100)
the replacement is less efficient, but also less obscure and more
robust.

Change-Id: Iee0538b5515c01116a4227f35d52f8166f1c730d
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
src/linguist/lupdate/cpp.cpp

index aa32cda..80cb422 100644 (file)
@@ -253,7 +253,6 @@ private:
 
     int getChar();
     TokenType getToken();
-    bool getMacroArgs();
 
     void processComment();
 
@@ -465,33 +464,6 @@ int CppParser::getChar()
     }
 }
 
-// This ignores commas, parens and comments.
-// IOW, it understands only a single, simple argument.
-bool CppParser::getMacroArgs()
-{
-    // Failing this assertion would mean losing the preallocated buffer.
-    Q_ASSERT(yyWord.isDetached());
-
-    while (isspace(yyCh))
-        yyCh = getChar();
-    if (yyCh != '(')
-        return false;
-    do {
-        yyCh = getChar();
-    } while (isspace(yyCh));
-    ushort *ptr = (ushort *)yyWord.unicode();
-    while (yyCh != ')') {
-        if (yyCh == EOF)
-            return false;
-        *ptr++ = yyCh;
-        yyCh = getChar();
-    }
-    yyCh = getChar();
-    for (; ptr != (ushort *)yyWord.unicode() && isspace(*(ptr - 1)); --ptr) ;
-    yyWord.resize(ptr - (ushort *)yyWord.unicode());
-    return true;
-}
-
 STRING(Q_OBJECT);
 STRING(class);
 STRING(friend);
@@ -1764,12 +1736,27 @@ void CppParser::handleTrId()
 
 void CppParser::handleDeclareTrFunctions()
 {
-    if (getMacroArgs()) {
-        Namespace *ns = modifyNamespace(&namespaces);
-        ns->hasTrFunctions = true;
-        ns->trQualification = yyWord;
-        ns->trQualification.detach();
+    QString name;
+    yyTok = getToken();
+    if (yyTok != Tok_LeftParen)
+        return;
+    forever {
+        yyTok = getToken();
+        if (yyTok != Tok_Ident)
+            return;
+        name += yyWord;
+        name.detach();
+        yyTok = getToken();
+        if (yyTok == Tok_RightParen)
+            break;
+        if (yyTok != Tok_ColonColon)
+            return;
+        name += QLatin1String("::");
     }
+    Namespace *ns = modifyNamespace(&namespaces);
+    ns->hasTrFunctions = true;
+    ns->trQualification = name;
+    ns->trQualification.detach();
 }
 
 void CppParser::parse(ConversionData &cd, const QStringList &includeStack,