[Uml-devel] [Bug 132472] java import : spaces in strings cause next member var to be ignored

Oliver Kellogg okellogg at users.sourceforge.net
Wed Aug 23 04:59:16 UTC 2006


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=132472         
okellogg users sourceforge net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From okellogg users sourceforge net  2006-08-23 06:59 -------
SVN commit 576104 by okellogg:

NativeImportBase::split(): New function to deal with string and char constants.
The fillSource() of other importers needs updating too (will be done shortly.)
BUG:132472


 M  +2 -2      ChangeLog  
 M  +6 -12     umbrello/codeimport/javaimport.cpp  
 M  +53 -6     umbrello/codeimport/nativeimportbase.cpp  
 M  +7 -0      umbrello/codeimport/nativeimportbase.h  


--- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #576103:576104
 @ -8,8 +8,8  @
 * Java import: unable to import AzareusCore (131961)
 * Java import: error on multidimensional arrays (132017)
 * Java import - array types not resolved correctly (132035)
-* Java import - "final" and comments in method declaration
-  not parsed correctly (132174)
+* Java import - "final" and comments in method declaration not parsed correctly (132174)
+* Java import: spaces in strings cause next member var to be ignored (132472)
 * Java import - static member vars ignored in interfaces (132657)
 
 Version 1.5.4
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codeimport/javaimport.cpp #576103:576104
 @ -63,23 +63,17  @
 }
 
 void JavaImport::fillSource(QString word) {
+    if (word[0] == '"' || word[0] == '\'') {
+        // string constants are handled by NativeImportBase::split()
+        m_source.append(word);
+        return;
+    }
     QString lexeme;
     const uint len = word.length();
-    bool inString = false;
     for (uint i = 0; i < len; i++) {
         const QChar& c = word[i];
-        if (c == '"') {
+        if (c.isLetterOrNumber() || c == '_' || c == '.') {
             lexeme += c;
-            if (i == 0 || word[i - 1] != '\\') {
-                if (inString) {
-                    m_source.append(lexeme);
-                    lexeme = QString::null;
-                }
-                inString = !inString;
-            }
-        } else if (inString ||
-                   c.isLetterOrNumber() || c == '_' || c == '.') {
-            lexeme += c;
         } else {
             if (!lexeme.isEmpty()) {
                 m_source.append(lexeme);
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codeimport/nativeimportbase.cpp #576103:576104
 @ -188,6 +188,56  @
     return false;  // The input was not completely consumed by preprocessing.
 }
 
+/// Split the line so that a string is returned as a single element of the list,
+/// when not in a string then split at white space.
+QStringList NativeImportBase::split(QString line) {
+    QStringList list;
+    QString listElement;
+    bool inString = false, inCharConst = false;
+    bool seenSpace = false;
+    line = line.stripWhiteSpace();
+    for (uint i = 0; i < line.length(); i++) {
+        const QChar& c = line[i];
+        if (c == '"') {
+            listElement += c;
+            if (i > 0 && line[i - 1] == '\\')
+                continue;
+            if (inString) {
+                list.append(listElement);
+                listElement = QString::null;
+            }
+            inString = !inString;
+            seenSpace = false;
+        } else if (c == '\'') {
+            listElement += c;
+            if (i > 0 && line[i - 1] == '\\')
+                continue;
+            if (inCharConst) {
+                list.append(listElement);
+                listElement = QString::null;
+            }
+            inCharConst = !inCharConst;
+            seenSpace = false;
+        } else if (inString || inCharConst) {
+            listElement += c;
+        } else if (c == ' ' || c == '\t') {
+            if (seenSpace)
+                continue;
+            seenSpace = true;
+            if (!listElement.isEmpty()) {
+                list.append(listElement);
+                listElement = QString::null;
+            }
+        } else {
+            listElement += c;
+            seenSpace = false;
+        }
+    }
+    if (!listElement.isEmpty())
+        list.append(listElement);
+    return list;
+}
+
 /// The lexer. Tokenizes the given string and fills `m_source'.
 /// Stores possible comments in `m_comment'.
 void NativeImportBase::scan(QString line) {
 @ -202,14 +252,11  @
             return;
         line = line.left(pos);
     }
-    line = line.simplifyWhiteSpace();
-    if (line.isEmpty())
+    if (line.contains(QRegExp("^\\s*$")))
         return;
-    QStringList words = QStringList::split( QRegExp("\\s+"), line );
+    QStringList words = split(line);
     for (QStringList::Iterator it = words.begin(); it != words.end(); ++it) {
-        QString word = (*it).stripWhiteSpace();
-        if (word.isEmpty())
-            continue;
+        QString word = *it;
         fillSource(word);
     }
 }
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codeimport/nativeimportbase.h #576103:576104
 @ -111,6 +111,13  @
     virtual bool preprocess(QString& line);
 
     /**
+     * Split the line so that a string is returned as a single element of the list.
+     * When not in a string then split at white space.
+     * The default implementation is suitable for C style strings and char constants.
+     */
+    virtual QStringList split(QString line);
+
+    /**
      * Analyze the given word and fill `m_source'.
      * A "word" is a whitespace delimited item from the input line.
      * To be provided by the specific importer class.




More information about the umbrello-devel mailing list