functions.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * functions.cpp
  3. *
  4. * Created on: Oct 6, 2011
  5. * Author: Gapchich Vladislav
  6. */
  7. #include "functions.h"
  8. #include <QString>
  9. #include <QChar>
  10. #include <QDomDocument>
  11. #include <QDomNode>
  12. #include <QDomText>
  13. #include <QDebug>
  14. int
  15. getNumFromString(
  16. QString *aString,
  17. const QString &aFirstStr,
  18. const QString &aSecondStr,
  19. bool *anOkFlag
  20. )
  21. {
  22. int numPos = aString->indexOf(aFirstStr) + aFirstStr.size();
  23. if (numPos < 0) {
  24. *anOkFlag = 0;
  25. return -1;
  26. /* NOTREACHED */
  27. }
  28. int numLength = -1;
  29. for (int i = numPos; i < aString->size(); i++) {
  30. if (aSecondStr == aString->at(i)) {
  31. numLength = i - numPos;
  32. break;
  33. }
  34. }
  35. if (numLength <= 0) {
  36. *anOkFlag = 0;
  37. return -1;
  38. /* NOTREACHED */
  39. }
  40. QString numString = aString->mid(numPos, numLength);
  41. if (numString.isEmpty()) {
  42. *anOkFlag = 0;
  43. return -1;
  44. /* NOTREACHED */
  45. }
  46. bool ok = 0;
  47. int num = numString.toInt(&ok, 10);
  48. if (!ok) {
  49. *anOkFlag = 0;
  50. return -1;
  51. /* NOTREACHED */
  52. }
  53. *anOkFlag = 1;
  54. return num;
  55. }
  56. /*
  57. * adds given suffix to the file name and removes path from it
  58. */
  59. QString alterFileName(const QString &aFilename, const QString &aSuffix)
  60. {
  61. /* altering the name of a new file */
  62. QString newFileName = aFilename;
  63. int dotPos = newFileName.lastIndexOf('.');
  64. if (-1 == dotPos)
  65. dotPos = newFileName.size();
  66. else
  67. newFileName.remove(dotPos, newFileName.size() - dotPos);
  68. newFileName.insert(dotPos, aSuffix);
  69. qDebug() << newFileName;
  70. int slashPos = newFileName.lastIndexOf('/');
  71. newFileName.remove(0, slashPos);
  72. return newFileName;
  73. }
  74. /*
  75. *
  76. */