int UpdateChecker::CompareVersions(const string& verA, const string& verB) { const vector<string> partsA = SplitVersionString(verA); const vector<string> partsB = SplitVersionString(verB); // Compare common length of both version strings. const size_t n = min(partsA.size(), partsB.size()); for ( size_t i = 0; i < n; i++ ) { const string& a = partsA[i]; const string& b = partsB[i]; const CharType typeA = ClassifyChar(a[0]); const CharType typeB = ClassifyChar(b[0]); if ( typeA == typeB ) { if ( typeA == Type_String ) { int result = a.compare(b); if ( result != 0 ) return result; } else if ( typeA == Type_Number ) { const int intA = atoi(a.c_str()); const int intB = atoi(b.c_str()); if ( intA > intB ) return 1; else if ( intA < intB ) return -1; } } else // components of different types { if ( typeA != Type_String && typeB == Type_String ) { // 1.2.0 > 1.2rc1 return 1; } else if ( typeA == Type_String && typeB != Type_String ) { // 1.2rc1 < 1.2.0 return -1; } else { // One is a number and the other is a period. The period // is invalid. return (typeA == Type_Number) ? 1 : -1; } } } // The versions are equal up to the point where they both still have // parts. Lets check to see if one is larger than the other. if ( partsA.size() == partsB.size() ) return 0; // the two strings are identical // Lets get the next part of the larger version string // Note that 'n' already holds the index of the part we want. int shorterResult, longerResult; CharType missingPartType; // ('missing' as in "missing in shorter version") if ( partsA.size() > partsB.size() ) { missingPartType = ClassifyChar(partsA[n][0]); shorterResult = -1; longerResult = 1; } else { missingPartType = ClassifyChar(partsB[n][0]); shorterResult = 1; longerResult = -1; } if ( missingPartType == Type_String ) { // 1.5 > 1.5b3 return shorterResult; } else { // 1.5.1 > 1.5 return longerResult; } }
bool FunctionTab::AnalyzeNumChar(QChar c) { int type = ClassifyChar(c); //MainWindow::Debug(QString("type: ").arg()) if(type == ERROR) { NumeratorInvalid(c); return false; } int transition = TransitionNum(type); MainWindow::Debug(QString("%1 -> %2").arg(StateName(numerator_state),StateName(transition))); if(transition == ERROR) { NumeratorInvalid(c); return false; } switch(numerator_state) { case IDLE: switch(transition) { case POLY: current_poly = new CPoly(); sign = 1; break; default: NumeratorInvalid(c); return false; break; } break; case POLY: switch(transition) { case TOKEN_INT: current_token = new CToken; cst_string = c; current_token->SetSign(sign); break; case TOKEN_DEC: current_token = new CToken; cst_string = c; break; case IDLE: m_numerator.push_back(current_poly); break; case VAR: current_token = new CToken; current_token->m_c = 1; current_token->SetSign(sign); break; default: NumeratorInvalid(c); return false; break; } break; case TOKEN_INT: switch(transition) { case TOKEN_INT: cst_string.append(c); break; case POLY: current_token->m_c = cst_string.toDouble(); current_poly->Add(current_token); break; case TOKEN_DEC: cst_string.append(c); break; case IDLE: current_token->m_c = cst_string.toDouble(); current_poly->Add(current_token); m_numerator.push_back(current_poly); break; case VAR: current_token->m_c = cst_string.toDouble(); if(cst_string[0]== '-' || cst_string[0]=='+') current_token->m_c = 1; break; default: NumeratorInvalid(c); return false; break; } break; case TOKEN_DEC: switch(transition) { case TOKEN_DEC: cst_string.append(c); break; case POLY: current_token->m_c = cst_string.toDouble(); current_poly->Add(current_token); break; case IDLE: current_token->m_c = cst_string.toDouble(); current_poly->Add(current_token); m_numerator.push_back(current_poly); break; case VAR: current_token->m_c = cst_string.toDouble(); break; default: NumeratorInvalid(c); return false; break; } break; case VAR: switch(transition) { case POLY: current_token->m_p = 1; current_poly->Add(current_token); break; case EXP: pwr_string = c; break; case IDLE: current_token->m_p = 1; current_poly->Add(current_token); m_numerator.push_back(current_poly); break; default: NumeratorInvalid(c); return false; break; } break; case EXP: switch(transition) { case EXP: pwr_string.append(c); break; case POLY: current_token->m_p = pwr_string.toInt(); current_poly->Add(current_token); break; case IDLE: current_token->m_p = pwr_string.toInt(); current_poly->Add(current_token); m_numerator.push_back(current_poly); break; default: NumeratorInvalid(c); return false; break; } break; default: MainWindow::Debug("Unknow state"); break; } numerator_state = transition; // MainWindow::Debug("OK"); return true; }