]> Git trees. - libqmvoc.git/commitdiff
Making changes to molecular parser, now there is no leakage, some KDE conventions... v4.3.80 v4.3.85
authorKashyap Ramesh Puranik <kashthealien@gmail.com>
Fri, 3 Jul 2009 10:48:57 +0000 (10:48 +0000)
committerKashyap Ramesh Puranik <kashthealien@gmail.com>
Fri, 3 Jul 2009 10:48:57 +0000 (10:48 +0000)
Here EDTA will be expanded because its between # and #. and Et will be expanded because it consists of a long letter followed by short.

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=990793

libscience/moleculeparser.cpp
libscience/moleculeparser.h

index e1ec0cae6dcee6a6effd06e52ea835a30c68147a..9f623465688c6e33dcda643d6de79e63bc426d4e 100644 (file)
@@ -101,14 +101,14 @@ MoleculeParser::MoleculeParser( const QList<Element*>& list)
     : Parser()
 {
        m_elementList = list;
-       m_aliasList = new (QSet<QString>);
+       m_aliasList = new QSet<QString>;
 }
 
 
 MoleculeParser::MoleculeParser(const QString& _str)
     : Parser(_str)
 {
-       m_aliasList = new (QSet<QString>);
+       m_aliasList = new QSet<QString>;
 }
 
 
@@ -161,10 +161,10 @@ MoleculeParser::weight(const QString&         _shortMoleculeString,
        return true;
 }
 
-QSet<QString>*
-MoleculeParser::getAliasList(void)
+QSet<QString>
+MoleculeParser::aliasList()
 {
-       return m_aliasList;
+       return *m_aliasList;
 }
 // ----------------------------------------------------------------
 //            helper methods for the public methods
@@ -321,14 +321,13 @@ MoleculeParser::lookupElement( const QString& _name )
 QString
 MoleculeParser::expandFormula( const QString& _shortString)
 {
-       QString _fullString = "";               // The expanded string that will be returned
-       QString::iterator i;            // iterator
-       QString temp;                   // A temporary string that will contain a single element/group
-       QString expandedTerm;   // expansion of a particular term.
+       QString _fullString;            // The expanded string that will be returned
+       QString::const_iterator i;              // iterator
+       QString temp;                           // A temporary string that will contain a single element/group
+       QString expandedTerm;           // expansion of a particular term.
        
        // Go through all letters in the string.
-       for(i = (const QString::iterator) _shortString.begin();
-                                        i != _shortString.end(); )
+       for(i = _shortString.constBegin(); i != _shortString.constEnd(); )
        {
                temp = "";
                
@@ -349,7 +348,7 @@ MoleculeParser::expandFormula( const QString& _shortString)
                        }
                        
                        // If an expansion was made, return the expansion
-                       else if ((expandedTerm = expandTerm(temp)) != "") {
+                       else if (!((expandedTerm = expandTerm(temp)).isEmpty())) {
                                kDebug() << "expanded" << temp << "to" << expandedTerm;
                                _fullString += "("+expandedTerm+")";
                        }
@@ -369,6 +368,33 @@ MoleculeParser::expandFormula( const QString& _shortString)
                        _fullString += ')';
                        i++;
                }
+               
+               // If # is found, we have a short-form eg #EDTA#
+               else if (*i == '#') {
+                       i ++;           // go to the next character
+                       // Get the term between # and #
+                       while (*i != '#' && i != _shortString.constEnd() )
+                       {
+                               temp += *i;
+                               i ++;
+                       }
+                       // If the string ended, just add the part that comes after #
+                       if ( i == _shortString.constEnd()) {
+                               _fullString += temp;
+                               break;
+                       }
+                       // else expand the term between # and #
+                       else if (!temp.isEmpty())
+                       {
+                               // if alias is not found, just add without expanding the term
+                               if((expandedTerm = expandTerm(temp)).isEmpty())
+                                       _fullString += temp;
+                               // else add the expanded term
+                               else
+                                       _fullString += expandedTerm;
+                       }
+                       i ++;
+               }
                // If number was found, return it
                else if ((*i).category() == QChar::Number_DecimalDigit) {
                        _fullString += *i;
index 6e8afbfe26a80ac1677887abd20f00c76f3d2b38..705154f6d3a9bde559924ec5280a1f82d137160a 100644 (file)
@@ -215,7 +215,7 @@ public:
                                 double          *_resultMass,
                                 ElementCountMap *_resultMap);
                                 
-       QSet<QString>* getAliasList(void);
+       QSet<QString> aliasList();
  private:
     // Helper functions
     bool      parseSubmolecule(double          *_resultMass,