Check if current element is the last element @input: - str - string with data - startPos - start position of the current element in the string - separator - string or character that separate elements - textDelimiter - string that is used as text delimiter @output: - bool - True if the current element is the last element of the string, False otherwise
| 373 | // - bool - True if the current element is the last element of the string, |
| 374 | // False otherwise |
| 375 | bool ReaderPrivate::isElementLast( |
| 376 | const QString& str, |
| 377 | const qsizetype startPos, |
| 378 | const QString& separator, |
| 379 | const QString& txtDelim) |
| 380 | { |
| 381 | if (str.isEmpty() || |
| 382 | startPos < 0 || |
| 383 | separator.isEmpty() || |
| 384 | txtDelim.isEmpty()) |
| 385 | { |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | // Check if string ends with text delimiter. If not, then this element |
| 390 | // do not ends on this line |
| 391 | if (!str.endsWith(txtDelim)) { return false; } |
| 392 | |
| 393 | // Check that this is really the end symbols of the |
| 394 | // element and we don't mix up it with double delimiter. |
| 395 | // Calc number of delimiter symbols from end |
| 396 | // to startPos that stands together. |
| 397 | qsizetype numOfDelimiters = 0; |
| 398 | for (auto pos = str.size() - 1; startPos <= pos; --pos, ++numOfDelimiters) { |
| 399 | const auto strRef = str.mid(pos, txtDelim.size()); |
| 400 | if (QString::compare(strRef, txtDelim) != 0) { break; } |
| 401 | } |
| 402 | |
| 403 | // If we have odd number of delimiter symbols that stand together, |
| 404 | // then this is the even number of double delimiter symbols + last |
| 405 | // delimiter symbol. That means that this element is the last on the line. |
| 406 | return numOfDelimiters % 2 == 1; |
| 407 | } |
| 408 | |
| 409 | // Remove extra symbols (spaces, text delimeters...) |
| 410 | // @input: |