TAKEN FROM Qt, because it doesn't expose it intelligently
| 8 | |
| 9 | /// TAKEN FROM Qt, because it doesn't expose it intelligently |
| 10 | int Strings::naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs) |
| 11 | { |
| 12 | for (int l1 = 0, l2 = 0; l1 <= s1.count() && l2 <= s2.count(); ++l1, ++l2) |
| 13 | { |
| 14 | // skip spaces, tabs and 0's |
| 15 | QChar c1 = getNextChar(s1, l1); |
| 16 | while (c1.isSpace()) |
| 17 | c1 = getNextChar(s1, ++l1); |
| 18 | QChar c2 = getNextChar(s2, l2); |
| 19 | while (c2.isSpace()) |
| 20 | c2 = getNextChar(s2, ++l2); |
| 21 | |
| 22 | if (c1.isDigit() && c2.isDigit()) |
| 23 | { |
| 24 | while (c1.digitValue() == 0) |
| 25 | c1 = getNextChar(s1, ++l1); |
| 26 | while (c2.digitValue() == 0) |
| 27 | c2 = getNextChar(s2, ++l2); |
| 28 | |
| 29 | int lookAheadLocation1 = l1; |
| 30 | int lookAheadLocation2 = l2; |
| 31 | int currentReturnValue = 0; |
| 32 | // find the last digit, setting currentReturnValue as we go if it isn't equal |
| 33 | for (QChar lookAhead1 = c1, lookAhead2 = c2; |
| 34 | (lookAheadLocation1 <= s1.length() && lookAheadLocation2 <= s2.length()); |
| 35 | lookAhead1 = getNextChar(s1, ++lookAheadLocation1), |
| 36 | lookAhead2 = getNextChar(s2, ++lookAheadLocation2)) |
| 37 | { |
| 38 | bool is1ADigit = !lookAhead1.isNull() && lookAhead1.isDigit(); |
| 39 | bool is2ADigit = !lookAhead2.isNull() && lookAhead2.isDigit(); |
| 40 | if (!is1ADigit && !is2ADigit) |
| 41 | break; |
| 42 | if (!is1ADigit) |
| 43 | return -1; |
| 44 | if (!is2ADigit) |
| 45 | return 1; |
| 46 | if (currentReturnValue == 0) |
| 47 | { |
| 48 | if (lookAhead1 < lookAhead2) |
| 49 | { |
| 50 | currentReturnValue = -1; |
| 51 | } |
| 52 | else if (lookAhead1 > lookAhead2) |
| 53 | { |
| 54 | currentReturnValue = 1; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | if (currentReturnValue != 0) |
| 59 | return currentReturnValue; |
| 60 | } |
| 61 | if (cs == Qt::CaseInsensitive) |
| 62 | { |
| 63 | if (!c1.isLower()) |
| 64 | c1 = c1.toLower(); |
| 65 | if (!c2.isLower()) |
| 66 | c2 = c2.toLower(); |
| 67 | } |
nothing calls this directly
no test coverage detected