]> Git trees. - libqmvoc.git/commitdiff
* Add null-check to the parser
authorCarsten Niehaus <cniehaus@gmx.de>
Tue, 3 Jan 2006 12:36:35 +0000 (12:36 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Tue, 3 Jan 2006 12:36:35 +0000 (12:36 +0000)
* Remove no longer needed code and include
* Indent getNextChar()

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

libscience/moleculeparser.cpp
libscience/parser.cpp

index 398c6018d538c0b90b0dda1e718ed27357f95a71..db686d15af808f40e0d732ed386fad3dbff9816f 100644 (file)
 
 #include <kdebug.h>
 
-/* PORTING
- * #include "kalziumdataobject.h"
- */
-
 #include "moleculeparser.h"
 
 
@@ -42,16 +38,6 @@ ElementCountMap::~ElementCountMap()
 ElementCount *
 ElementCountMap::search(Element *_element)
 {
-       //not yet tested but the commented code should be the same as
-       //the foreach... so lets use Qt4 power
-//X    QList<ElementCount *>::ConstIterator       it    = m_map.constBegin();
-//X    const QList<ElementCount *>::ConstIterator itEnd = m_map.constEnd();
-//X 
-//X    for (; it != itEnd; ++it) {
-//X            if ((*it)->element() == _element)
-//X                    return *it;
-//X    }
-
        foreach( ElementCount* c, m_map ){
                if ( c->element() == _element )
                        return c;
@@ -64,16 +50,6 @@ ElementCountMap::search(Element *_element)
 void
 ElementCountMap::add(ElementCountMap &_map)
 {
-       //not yet tested but the commented code should be the same as
-       //the foreach... so lets use Qt4 power
-//X    QList<ElementCount *>::ConstIterator       it    = _map.m_map.constBegin();
-//X    const QList<ElementCount *>::ConstIterator itEnd = _map.m_map.constEnd();
-//X 
-//X    // Step throught _map and for each element, add it to the current one.
-//X    for (; it != itEnd; ++it) {
-//X            add((*it)->m_element, (*it)->m_count);
-//X    }
-
        foreach( ElementCount* c, _map.m_map ){
                add( c->m_element, c->m_count );
        }
@@ -141,6 +117,9 @@ MoleculeParser::weight(QString         _moleculeString,
                                           double          *_resultMass,
                                           ElementCountMap *_resultMap)
 {
+       if ( _moleculeString == QString() )
+               return false;
+       
        // Clear the result variables and set m_error to false
        _resultMap->clear();
        m_error = false;
@@ -295,13 +274,8 @@ MoleculeParser::getNextToken()
 Element *
 MoleculeParser::lookupElement( const QString& _name )
 {
-//X     QList<Element*> elementList = KalziumDataObject::instance()->ElementList;
-
     kdDebug() << "looking up " << _name << endl;
 
-//X     QList<Element*>::ConstIterator        it  = elementList.constBegin();
-//X     const QList<Element*>::ConstIterator  end = elementList.constEnd();
-
        foreach( Element* e, m_elementList ){
                if ( e->dataAsVariant(ChemicalDataObject::symbol) == _name ) {
                        kdDebug() << "Found element " << _name << endl;
@@ -309,13 +283,6 @@ MoleculeParser::lookupElement( const QString& _name )
                }
        }
 
-//X    for (; it != end; ++it) {
-//X            if ( (*it)->dataAsVariant(ChemicalDataObject::symbol) == _name ) {
-//X                    kdDebug() << "Found element " << _name << endl;
-//X                    return *it;
-//X            }
-//X    }
-
        //if there is an error make m_error true.
        m_error = true;
 
index 68acab5b3142088dfe461116b710cab673c2906c..42eb2887305b7abc701114488fac980f3a987dc4 100644 (file)
@@ -139,26 +139,29 @@ Parser::parseSimpleFloat(double *_result)
 int
 Parser::getNextChar()
 {
-    if (m_index == -1)
-       return -1;
-
-    // If end of string, then reset the parser.
-    if (m_index == (int) m_str.length()) {
-       m_index    = -1;
-       m_nextChar = -1;
-    }
-    else 
-       m_nextChar = m_str.at(++m_index).toLatin1();
+//     kdDebug() << "Parser::getNextChar(): char = " << m_nextChar << endl;
+//     kdDebug() << "m_str.size() " << m_str.size()  << " with m_str: " << m_str  << " and m_index: " << m_index << endl;
+       
+       m_index++;
+       
+       if (m_index == -1)
+               return -1;
 
-    // Take care of null-terminated strings.
-    if (m_nextChar == 0) {
-       m_index    = -1;
-       m_nextChar = -1;
-    }
+       // If end of string, then reset the parser.
+       if (m_index == m_str.size()) {
+               m_index    = -1;
+               m_nextChar = -1;
+       }
+       else 
+               m_nextChar = m_str.at(m_index).toLatin1();
 
-    //kdDebug() << "Parser::getNextChar(): char = " << m_nextChar << endl;
+       // Take care of null-terminated strings.
+       if (m_nextChar == 0) {
+               m_index    = -1;
+               m_nextChar = -1;
+       }
 
-    return m_nextChar;
+       return m_nextChar;
 }