123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- /*
- * 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>
- //! Gets number from a string which is located between aFirstStr and aSecondStr
- /*!
- * \param[in] aString pointer to the source string containing the number we need
- * \param[in] aFirstStr a string which is located to the left side of the number
- * \param[in] aSecondStr a string which is located to the right side of the number
- * \param[in,out] anOkFlag a pointer to the bool flag indicating the conversation errors
- *
- * example: aString contains "0: Poly #0; LabelID: 1; points:..."
- * aFirstStr "LabelID: "
- * aSecondStr ";"
- * function returns 1
- */
- 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
- /*
- * example: /home/user/file.dot -> /home/user/file_altered.dot
- */
- 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);
- return newFileName;
- }
- //! Removes the path from filename
- /*!
- * example: /home/user/file -> file
- */
- QString
- removePath(const QString &aFilename)
- {
- QString newFileName = aFilename;
- int slashPos = newFileName.lastIndexOf('/');
- newFileName.remove(0, slashPos + 1);
- return newFileName;
- }
- //! Gets path from filename
- /*!
- * example: /home/user/file.dot -> /home/user
- */
- QString
- getPathFromFilename(const QString &aFilename)
- {
- QString path = aFilename;
- int slashPos = path.lastIndexOf('/');
- path = path.mid(0, slashPos + 1);
- return path;
- }
- /*
- *
- */
|