1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- /*
- * functions.cpp
- *
- * Created on: Oct 6, 2011
- * Author: Gapchich Vladislav
- */
- #include "functions.h"
- #include <QString>
- #include <QChar>
- #include <QDomDocument>
- #include <QDomNode>
- #include <QDomText>
- #include <QDebug>
- int
- getNumFromString(
- QString *aString,
- const QString &aFirstStr,
- const QString &aSecondStr,
- bool *anOkFlag
- )
- {
- int numPos = aString->indexOf(aFirstStr) + aFirstStr.size();
- if (numPos < 0) {
- *anOkFlag = 0;
- return -1;
- /* NOTREACHED */
- }
- int numLength = -1;
- for (int i = numPos; i < aString->size(); i++) {
- if (aSecondStr == aString->at(i)) {
- numLength = i - numPos;
- break;
- }
- }
- if (numLength <= 0) {
- *anOkFlag = 0;
- return -1;
- /* NOTREACHED */
- }
- QString numString = aString->mid(numPos, numLength);
- if (numString.isEmpty()) {
- *anOkFlag = 0;
- return -1;
- /* NOTREACHED */
- }
- bool ok = 0;
- int num = numString.toInt(&ok, 10);
- if (!ok) {
- *anOkFlag = 0;
- return -1;
- /* NOTREACHED */
- }
- *anOkFlag = 1;
- return num;
- }
- /*
- * adds given suffix to the file name and removes path from it
- */
- QString alterFileName(const QString &aFilename, const QString &aSuffix)
- {
- /* altering the name of a new file */
- QString newFileName = aFilename;
- int dotPos = newFileName.lastIndexOf('.');
- if (-1 == dotPos)
- dotPos = newFileName.size();
- else
- newFileName.remove(dotPos, newFileName.size() - dotPos);
- newFileName.insert(dotPos, aSuffix);
- qDebug() << newFileName;
- int slashPos = newFileName.lastIndexOf('/');
- newFileName.remove(0, slashPos);
- return newFileName;
- }
- /*
- *
- */
|