| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qdatetimeparser.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include "qplatformdefs.h" | - | ||||||||||||||||||
| 35 | #include "private/qdatetimeparser_p.h" | - | ||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | #include "qdatastream.h" | - | ||||||||||||||||||
| 38 | #include "qset.h" | - | ||||||||||||||||||
| 39 | #include "qlocale.h" | - | ||||||||||||||||||
| 40 | #include "qdatetime.h" | - | ||||||||||||||||||
| 41 | #include "qregexp.h" | - | ||||||||||||||||||
| 42 | #include "qdebug.h" | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | //#define QDATETIMEPARSER_DEBUG | - | ||||||||||||||||||
| 45 | #if defined (QDATETIMEPARSER_DEBUG) && !defined(QT_NO_DEBUG_STREAM) | - | ||||||||||||||||||
| 46 | # define QDTPDEBUG qDebug() | - | ||||||||||||||||||
| 47 | # define QDTPDEBUGN qDebug | - | ||||||||||||||||||
| 48 | #else | - | ||||||||||||||||||
| 49 | # define QDTPDEBUG if (false) qDebug() | - | ||||||||||||||||||
| 50 | # define QDTPDEBUGN if (false) qDebug | - | ||||||||||||||||||
| 51 | #endif | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | /*! | - | ||||||||||||||||||
| 58 | \internal | - | ||||||||||||||||||
| 59 | Gets the digit from a datetime. E.g. | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | QDateTime var(QDate(2004, 02, 02)); | - | ||||||||||||||||||
| 62 | int digit = getDigit(var, Year); | - | ||||||||||||||||||
| 63 | // digit = 2004 | - | ||||||||||||||||||
| 64 | */ | - | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | int QDateTimeParser::getDigit(const QDateTime &t, int index) const | - | ||||||||||||||||||
| 67 | { | - | ||||||||||||||||||
| 68 | if (index < 0 || index >= sectionNodes.size()) {
| 0-3487 | ||||||||||||||||||
| 69 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||
| 70 | qWarning("QDateTimeParser::getDigit() Internal error (%s %d)", | - | ||||||||||||||||||
| 71 | qPrintable(t.toString()), index); | - | ||||||||||||||||||
| 72 | #else | - | ||||||||||||||||||
| 73 | qWarning("QDateTimeParser::getDigit() Internal error (%d)", index); | - | ||||||||||||||||||
| 74 | #endif | - | ||||||||||||||||||
| 75 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 76 | } | - | ||||||||||||||||||
| 77 | const SectionNode &node = sectionNodes.at(index); | - | ||||||||||||||||||
| 78 | switch (node.type) { | - | ||||||||||||||||||
| 79 | case Hour24Section: case Hour12Section: return t.time().hour(); executed 724 times by 2 tests: return t.time().hour();Executed by:
executed 419 times by 1 test: case Hour24Section:Executed by:
executed 305 times by 2 tests: case Hour12Section:Executed by:
| 305-724 | ||||||||||||||||||
| 80 | case MinuteSection: return t.time().minute(); executed 316 times by 1 test: return t.time().minute();Executed by:
executed 316 times by 1 test: case MinuteSection:Executed by:
| 316 | ||||||||||||||||||
| 81 | case SecondSection: return t.time().second(); executed 299 times by 1 test: return t.time().second();Executed by:
executed 299 times by 1 test: case SecondSection:Executed by:
| 299 | ||||||||||||||||||
| 82 | case MSecSection: return t.time().msec(); never executed: return t.time().msec();never executed: case MSecSection: | 0 | ||||||||||||||||||
| 83 | case YearSection2Digits: executed 566 times by 2 tests: case YearSection2Digits:Executed by:
| 566 | ||||||||||||||||||
| 84 | case YearSection: return t.date().year(); executed 749 times by 2 tests: return t.date().year();Executed by:
executed 183 times by 1 test: case YearSection:Executed by:
| 183-749 | ||||||||||||||||||
| 85 | case MonthSection: return t.date().month(); executed 159 times by 4 tests: return t.date().month();Executed by:
executed 159 times by 4 tests: case MonthSection:Executed by:
| 159 | ||||||||||||||||||
| 86 | case DaySection: return t.date().day(); executed 131 times by 1 test: return t.date().day();Executed by:
executed 131 times by 1 test: case DaySection:Executed by:
| 131 | ||||||||||||||||||
| 87 | case DayOfWeekSectionShort: executed 90 times by 1 test: case DayOfWeekSectionShort:Executed by:
| 90 | ||||||||||||||||||
| 88 | case DayOfWeekSectionLong: return t.date().day(); executed 1103 times by 1 test: return t.date().day();Executed by:
executed 1013 times by 1 test: case DayOfWeekSectionLong:Executed by:
| 1013-1103 | ||||||||||||||||||
| 89 | case AmPmSection: return t.time().hour() > 11 ? 1 : 0; executed 6 times by 1 test: return t.time().hour() > 11 ? 1 : 0;Executed by:
executed 6 times by 1 test: case AmPmSection:Executed by:
| 2-6 | ||||||||||||||||||
| 90 | - | |||||||||||||||||||
| 91 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 92 | } | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||
| 95 | qWarning("QDateTimeParser::getDigit() Internal error 2 (%s %d)", | - | ||||||||||||||||||
| 96 | qPrintable(t.toString()), index); | - | ||||||||||||||||||
| 97 | #else | - | ||||||||||||||||||
| 98 | qWarning("QDateTimeParser::getDigit() Internal error 2 (%d)", index); | - | ||||||||||||||||||
| 99 | #endif | - | ||||||||||||||||||
| 100 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 101 | } | - | ||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | /*! | - | ||||||||||||||||||
| 104 | \internal | - | ||||||||||||||||||
| 105 | Sets a digit in a datetime. E.g. | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | QDateTime var(QDate(2004, 02, 02)); | - | ||||||||||||||||||
| 108 | int digit = getDigit(var, Year); | - | ||||||||||||||||||
| 109 | // digit = 2004 | - | ||||||||||||||||||
| 110 | setDigit(&var, Year, 2005); | - | ||||||||||||||||||
| 111 | digit = getDigit(var, Year); | - | ||||||||||||||||||
| 112 | // digit = 2005 | - | ||||||||||||||||||
| 113 | */ | - | ||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const | - | ||||||||||||||||||
| 116 | { | - | ||||||||||||||||||
| 117 | if (index < 0 || index >= sectionNodes.size()) {
| 0-4310 | ||||||||||||||||||
| 118 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||
| 119 | qWarning("QDateTimeParser::setDigit() Internal error (%s %d %d)", | - | ||||||||||||||||||
| 120 | qPrintable(v.toString()), index, newVal); | - | ||||||||||||||||||
| 121 | #else | - | ||||||||||||||||||
| 122 | qWarning("QDateTimeParser::setDigit() Internal error (%d %d)", index, newVal); | - | ||||||||||||||||||
| 123 | #endif | - | ||||||||||||||||||
| 124 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 125 | } | - | ||||||||||||||||||
| 126 | const SectionNode &node = sectionNodes.at(index); | - | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | int year = v.date().year(); | - | ||||||||||||||||||
| 129 | int month = v.date().month(); | - | ||||||||||||||||||
| 130 | int day = v.date().day(); | - | ||||||||||||||||||
| 131 | int hour = v.time().hour(); | - | ||||||||||||||||||
| 132 | int minute = v.time().minute(); | - | ||||||||||||||||||
| 133 | int second = v.time().second(); | - | ||||||||||||||||||
| 134 | int msec = v.time().msec(); | - | ||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | switch (node.type) { | - | ||||||||||||||||||
| 137 | case Hour24Section: case Hour12Section: hour = newVal; break; executed 856 times by 3 tests: break;Executed by:
executed 478 times by 2 tests: case Hour24Section:Executed by:
executed 378 times by 2 tests: case Hour12Section:Executed by:
| 378-856 | ||||||||||||||||||
| 138 | case MinuteSection: minute = newVal; break; executed 470 times by 1 test: break;Executed by:
executed 470 times by 1 test: case MinuteSection:Executed by:
| 470 | ||||||||||||||||||
| 139 | case SecondSection: second = newVal; break; executed 434 times by 1 test: break;Executed by:
executed 434 times by 1 test: case SecondSection:Executed by:
| 434 | ||||||||||||||||||
| 140 | case MSecSection: msec = newVal; break; executed 36 times by 1 test: break;Executed by:
executed 36 times by 1 test: case MSecSection:Executed by:
| 36 | ||||||||||||||||||
| 141 | case YearSection2Digits: executed 565 times by 2 tests: case YearSection2Digits:Executed by:
| 565 | ||||||||||||||||||
| 142 | case YearSection: year = newVal; break; executed 719 times by 2 tests: break;Executed by:
executed 154 times by 1 test: case YearSection:Executed by:
| 154-719 | ||||||||||||||||||
| 143 | case MonthSection: month = newVal; break; executed 241 times by 4 tests: break;Executed by:
executed 241 times by 4 tests: case MonthSection:Executed by:
| 241 | ||||||||||||||||||
| 144 | case DaySection: executed 445 times by 2 tests: case DaySection:Executed by:
| 445 | ||||||||||||||||||
| 145 | case DayOfWeekSectionShort: executed 90 times by 1 test: case DayOfWeekSectionShort:Executed by:
| 90 | ||||||||||||||||||
| 146 | case DayOfWeekSectionLong: executed 1013 times by 1 test: case DayOfWeekSectionLong:Executed by:
| 1013 | ||||||||||||||||||
| 147 | if (newVal > 31) {
| 0-1548 | ||||||||||||||||||
| 148 | // have to keep legacy behavior. setting the | - | ||||||||||||||||||
| 149 | // date to 32 should return false. Setting it | - | ||||||||||||||||||
| 150 | // to 31 for february should return true | - | ||||||||||||||||||
| 151 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 152 | } | - | ||||||||||||||||||
| 153 | day = newVal; | - | ||||||||||||||||||
| 154 | break; executed 1548 times by 2 tests: break;Executed by:
| 1548 | ||||||||||||||||||
| 155 | case AmPmSection: hour = (newVal == 0 ? hour % 12 : (hour % 12) + 12); break; executed 6 times by 1 test: break;Executed by:
executed 6 times by 1 test: case AmPmSection:Executed by:
| 2-6 | ||||||||||||||||||
| 156 | default: never executed: default: | 0 | ||||||||||||||||||
| 157 | qWarning("QDateTimeParser::setDigit() Internal error (%s)", | - | ||||||||||||||||||
| 158 | qPrintable(node.name())); | - | ||||||||||||||||||
| 159 | break; never executed: break; | 0 | ||||||||||||||||||
| 160 | } | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | if (!(node.type & DaySectionMask)) {
| 1548-2762 | ||||||||||||||||||
| 163 | if (day < cachedDay)
| 21-2741 | ||||||||||||||||||
| 164 | day = cachedDay; executed 21 times by 1 test: day = cachedDay;Executed by:
| 21 | ||||||||||||||||||
| 165 | const int max = QDate(year, month, 1).daysInMonth(); | - | ||||||||||||||||||
| 166 | if (day > max) {
| 76-2686 | ||||||||||||||||||
| 167 | day = max; | - | ||||||||||||||||||
| 168 | } executed 76 times by 3 tests: end of blockExecuted by:
| 76 | ||||||||||||||||||
| 169 | } executed 2762 times by 6 tests: end of blockExecuted by:
| 2762 | ||||||||||||||||||
| 170 | if (QDate::isValid(year, month, day) && QTime::isValid(hour, minute, second, msec)) {
| 0-4271 | ||||||||||||||||||
| 171 | v = QDateTime(QDate(year, month, day), QTime(hour, minute, second, msec), spec); | - | ||||||||||||||||||
| 172 | return true; executed 4271 times by 7 tests: return true;Executed by:
| 4271 | ||||||||||||||||||
| 173 | } | - | ||||||||||||||||||
| 174 | return false; executed 39 times by 2 tests: return false;Executed by:
| 39 | ||||||||||||||||||
| 175 | } | - | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | /*! | - | ||||||||||||||||||
| 180 | \ | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | Returns the absolute maximum for a section | - | ||||||||||||||||||
| 183 | */ | - | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | int QDateTimeParser::absoluteMax(int s, const QDateTime &cur) const | - | ||||||||||||||||||
| 186 | { | - | ||||||||||||||||||
| 187 | const SectionNode &sn = sectionNode(s); | - | ||||||||||||||||||
| 188 | switch (sn.type) { | - | ||||||||||||||||||
| 189 | case Hour24Section: executed 1695 times by 6 tests: case Hour24Section:Executed by:
| 1695 | ||||||||||||||||||
| 190 | case Hour12Section: return 23; // this is special-cased in executed 2852 times by 8 tests: return 23;Executed by:
executed 1157 times by 5 tests: case Hour12Section:Executed by:
| 1157-2852 | ||||||||||||||||||
| 191 | // parseSection. We want it to be | - | ||||||||||||||||||
| 192 | // 23 for the stepBy case. | - | ||||||||||||||||||
| 193 | case MinuteSection: executed 2298 times by 8 tests: case MinuteSection:Executed by:
| 2298 | ||||||||||||||||||
| 194 | case SecondSection: return 59; executed 4384 times by 8 tests: return 59;Executed by:
executed 2086 times by 4 tests: case SecondSection:Executed by:
| 2086-4384 | ||||||||||||||||||
| 195 | case MSecSection: return 999; executed 237 times by 2 tests: return 999;Executed by:
executed 237 times by 2 tests: case MSecSection:Executed by:
| 237 | ||||||||||||||||||
| 196 | case YearSection2Digits: executed 1439 times by 7 tests: case YearSection2Digits:Executed by:
| 1439 | ||||||||||||||||||
| 197 | case YearSection: return 9999; // sectionMaxSize will prevent executed 3454 times by 10 tests: return 9999;Executed by:
executed 2015 times by 6 tests: case YearSection:Executed by:
| 2015-3454 | ||||||||||||||||||
| 198 | // people from typing in a larger | - | ||||||||||||||||||
| 199 | // number in count == 2 sections. | - | ||||||||||||||||||
| 200 | // stepBy() will work on real years anyway | - | ||||||||||||||||||
| 201 | case MonthSection: return 12; executed 1934 times by 7 tests: return 12;Executed by:
executed 1934 times by 7 tests: case MonthSection:Executed by:
| 1934 | ||||||||||||||||||
| 202 | case DaySection: executed 2960 times by 10 tests: case DaySection:Executed by:
| 2960 | ||||||||||||||||||
| 203 | case DayOfWeekSectionShort: executed 90 times by 1 test: case DayOfWeekSectionShort:Executed by:
| 90 | ||||||||||||||||||
| 204 | case DayOfWeekSectionLong: return cur.isValid() ? cur.date().daysInMonth() : 31; executed 4063 times by 10 tests: return cur.isValid() ? cur.date().daysInMonth() : 31;Executed by:
executed 1013 times by 1 test: case DayOfWeekSectionLong:Executed by:
| 1013-4063 | ||||||||||||||||||
| 205 | case AmPmSection: return 1; executed 6 times by 1 test: return 1;Executed by:
executed 6 times by 1 test: case AmPmSection:Executed by:
| 6 | ||||||||||||||||||
| 206 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 207 | } | - | ||||||||||||||||||
| 208 | qWarning("QDateTimeParser::absoluteMax() Internal error (%s)", | - | ||||||||||||||||||
| 209 | qPrintable(sn.name())); | - | ||||||||||||||||||
| 210 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 211 | } | - | ||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | /*! | - | ||||||||||||||||||
| 214 | \internal | - | ||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | Returns the absolute minimum for a section | - | ||||||||||||||||||
| 217 | */ | - | ||||||||||||||||||
| 218 | - | |||||||||||||||||||
| 219 | int QDateTimeParser::absoluteMin(int s) const | - | ||||||||||||||||||
| 220 | { | - | ||||||||||||||||||
| 221 | const SectionNode &sn = sectionNode(s); | - | ||||||||||||||||||
| 222 | switch (sn.type) { | - | ||||||||||||||||||
| 223 | case Hour24Section: executed 1695 times by 6 tests: case Hour24Section:Executed by:
| 1695 | ||||||||||||||||||
| 224 | case Hour12Section: executed 1157 times by 5 tests: case Hour12Section:Executed by:
| 1157 | ||||||||||||||||||
| 225 | case MinuteSection: executed 2287 times by 8 tests: case MinuteSection:Executed by:
| 2287 | ||||||||||||||||||
| 226 | case SecondSection: executed 2074 times by 4 tests: case SecondSection:Executed by:
| 2074 | ||||||||||||||||||
| 227 | case MSecSection: executed 237 times by 2 tests: case MSecSection:Executed by:
| 237 | ||||||||||||||||||
| 228 | case YearSection2Digits: executed 1436 times by 7 tests: case YearSection2Digits:Executed by:
| 1436 | ||||||||||||||||||
| 229 | case YearSection: return 0; executed 10901 times by 11 tests: return 0;Executed by:
executed 2015 times by 6 tests: case YearSection:Executed by:
| 2015-10901 | ||||||||||||||||||
| 230 | case MonthSection: executed 1922 times by 7 tests: case MonthSection:Executed by:
| 1922 | ||||||||||||||||||
| 231 | case DaySection: executed 2936 times by 10 tests: case DaySection:Executed by:
| 2936 | ||||||||||||||||||
| 232 | case DayOfWeekSectionShort: executed 90 times by 1 test: case DayOfWeekSectionShort:Executed by:
| 90 | ||||||||||||||||||
| 233 | case DayOfWeekSectionLong: return 1; executed 5961 times by 10 tests: return 1;Executed by:
executed 1013 times by 1 test: case DayOfWeekSectionLong:Executed by:
| 1013-5961 | ||||||||||||||||||
| 234 | case AmPmSection: return 0; executed 6 times by 1 test: return 0;Executed by:
executed 6 times by 1 test: case AmPmSection:Executed by:
| 6 | ||||||||||||||||||
| 235 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 236 | } | - | ||||||||||||||||||
| 237 | qWarning("QDateTimeParser::absoluteMin() Internal error (%s, %0x)", | - | ||||||||||||||||||
| 238 | qPrintable(sn.name()), sn.type); | - | ||||||||||||||||||
| 239 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 240 | } | - | ||||||||||||||||||
| 241 | - | |||||||||||||||||||
| 242 | /*! | - | ||||||||||||||||||
| 243 | \internal | - | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | Returns the sectionNode for the Section \a s. | - | ||||||||||||||||||
| 246 | */ | - | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | const QDateTimeParser::SectionNode &QDateTimeParser::sectionNode(int sectionIndex) const | - | ||||||||||||||||||
| 249 | { | - | ||||||||||||||||||
| 250 | if (sectionIndex < 0) {
| 739-148325 | ||||||||||||||||||
| 251 | switch (sectionIndex) { | - | ||||||||||||||||||
| 252 | case FirstSectionIndex: executed 229 times by 4 tests: case FirstSectionIndex:Executed by:
| 229 | ||||||||||||||||||
| 253 | return first; executed 229 times by 4 tests: return first;Executed by:
| 229 | ||||||||||||||||||
| 254 | case LastSectionIndex: executed 7 times by 1 test: case LastSectionIndex:Executed by:
| 7 | ||||||||||||||||||
| 255 | return last; executed 7 times by 1 test: return last;Executed by:
| 7 | ||||||||||||||||||
| 256 | case NoSectionIndex: executed 503 times by 7 tests: case NoSectionIndex:Executed by:
| 503 | ||||||||||||||||||
| 257 | return none; executed 503 times by 7 tests: return none;Executed by:
| 503 | ||||||||||||||||||
| 258 | } | - | ||||||||||||||||||
| 259 | } else if (sectionIndex < sectionNodes.size()) { never executed: end of block
| 0-148325 | ||||||||||||||||||
| 260 | return sectionNodes.at(sectionIndex); executed 148325 times by 11 tests: return sectionNodes.at(sectionIndex);Executed by:
| 148325 | ||||||||||||||||||
| 261 | } | - | ||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | qWarning("QDateTimeParser::sectionNode() Internal error (%d)", | - | ||||||||||||||||||
| 264 | sectionIndex); | - | ||||||||||||||||||
| 265 | return none; never executed: return none; | 0 | ||||||||||||||||||
| 266 | } | - | ||||||||||||||||||
| 267 | - | |||||||||||||||||||
| 268 | QDateTimeParser::Section QDateTimeParser::sectionType(int sectionIndex) const | - | ||||||||||||||||||
| 269 | { | - | ||||||||||||||||||
| 270 | return sectionNode(sectionIndex).type; executed 6721 times by 10 tests: return sectionNode(sectionIndex).type;Executed by:
| 6721 | ||||||||||||||||||
| 271 | } | - | ||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | /*! | - | ||||||||||||||||||
| 275 | \internal | - | ||||||||||||||||||
| 276 | - | |||||||||||||||||||
| 277 | Returns the starting position for section \a s. | - | ||||||||||||||||||
| 278 | */ | - | ||||||||||||||||||
| 279 | - | |||||||||||||||||||
| 280 | int QDateTimeParser::sectionPos(int sectionIndex) const | - | ||||||||||||||||||
| 281 | { | - | ||||||||||||||||||
| 282 | return sectionPos(sectionNode(sectionIndex)); executed 49308 times by 4 tests: return sectionPos(sectionNode(sectionIndex));Executed by:
| 49308 | ||||||||||||||||||
| 283 | } | - | ||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | int QDateTimeParser::sectionPos(const SectionNode &sn) const | - | ||||||||||||||||||
| 286 | { | - | ||||||||||||||||||
| 287 | switch (sn.type) { | - | ||||||||||||||||||
| 288 | case FirstSection: return 0; executed 117 times by 4 tests: return 0;Executed by:
executed 117 times by 4 tests: case FirstSection:Executed by:
| 117 | ||||||||||||||||||
| 289 | case LastSection: return displayText().size() - 1; never executed: return displayText().size() - 1;never executed: case LastSection: | 0 | ||||||||||||||||||
| 290 | default: break; executed 51851 times by 4 tests: break;Executed by:
executed 51851 times by 4 tests: default:Executed by:
| 51851 | ||||||||||||||||||
| 291 | } | - | ||||||||||||||||||
| 292 | if (sn.pos == -1) {
| 0-51851 | ||||||||||||||||||
| 293 | qWarning("QDateTimeParser::sectionPos Internal error (%s)", qPrintable(sn.name())); | - | ||||||||||||||||||
| 294 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 295 | } | - | ||||||||||||||||||
| 296 | return sn.pos; executed 51851 times by 4 tests: return sn.pos;Executed by:
| 51851 | ||||||||||||||||||
| 297 | } | - | ||||||||||||||||||
| 298 | - | |||||||||||||||||||
| 299 | - | |||||||||||||||||||
| 300 | /*! | - | ||||||||||||||||||
| 301 | \internal | - | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | helper function for parseFormat. removes quotes that are | - | ||||||||||||||||||
| 304 | not escaped and removes the escaping on those that are escaped | - | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | */ | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | static QString unquote(const QString &str) | - | ||||||||||||||||||
| 309 | { | - | ||||||||||||||||||
| 310 | const QChar quote(QLatin1Char('\'')); | - | ||||||||||||||||||
| 311 | const QChar slash(QLatin1Char('\\')); | - | ||||||||||||||||||
| 312 | const QChar zero(QLatin1Char('0')); | - | ||||||||||||||||||
| 313 | QString ret; | - | ||||||||||||||||||
| 314 | QChar status(zero); | - | ||||||||||||||||||
| 315 | const int max = str.size(); | - | ||||||||||||||||||
| 316 | for (int i=0; i<max; ++i) {
| 506-1021 | ||||||||||||||||||
| 317 | if (str.at(i) == quote) {
| 21-485 | ||||||||||||||||||
| 318 | if (status != quote) {
| 10-11 | ||||||||||||||||||
| 319 | status = quote; | - | ||||||||||||||||||
| 320 | } else if (!ret.isEmpty() && str.at(i - 1) == slash) { executed 11 times by 4 tests: end of blockExecuted by:
| 0-11 | ||||||||||||||||||
| 321 | ret[ret.size() - 1] = quote; | - | ||||||||||||||||||
| 322 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 323 | status = zero; | - | ||||||||||||||||||
| 324 | } executed 10 times by 4 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 325 | } else { | - | ||||||||||||||||||
| 326 | ret += str.at(i); | - | ||||||||||||||||||
| 327 | } executed 485 times by 5 tests: end of blockExecuted by:
| 485 | ||||||||||||||||||
| 328 | } | - | ||||||||||||||||||
| 329 | return ret; executed 1021 times by 10 tests: return ret;Executed by:
| 1021 | ||||||||||||||||||
| 330 | } | - | ||||||||||||||||||
| 331 | /*! | - | ||||||||||||||||||
| 332 | \internal | - | ||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | Parses the format \a newFormat. If successful, returns \c true and | - | ||||||||||||||||||
| 335 | sets up the format. Else keeps the old format and returns \c false. | - | ||||||||||||||||||
| 336 | - | |||||||||||||||||||
| 337 | */ | - | ||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | static inline int countRepeat(const QString &str, int index, int maxCount) | - | ||||||||||||||||||
| 340 | { | - | ||||||||||||||||||
| 341 | int count = 1; | - | ||||||||||||||||||
| 342 | const QChar ch(str.at(index)); | - | ||||||||||||||||||
| 343 | const int max = qMin(index + maxCount, str.size()); | - | ||||||||||||||||||
| 344 | while (index + count < max && str.at(index + count) == ch) {
| 1990-8271 | ||||||||||||||||||
| 345 | ++count; | - | ||||||||||||||||||
| 346 | } executed 6281 times by 11 tests: end of blockExecuted by:
| 6281 | ||||||||||||||||||
| 347 | return count; executed 4090 times by 11 tests: return count;Executed by:
| 4090 | ||||||||||||||||||
| 348 | } | - | ||||||||||||||||||
| 349 | - | |||||||||||||||||||
| 350 | static inline void appendSeparator(QStringList *list, const QString &string, int from, int size, int lastQuote) | - | ||||||||||||||||||
| 351 | { | - | ||||||||||||||||||
| 352 | QString str(string.mid(from, size)); | - | ||||||||||||||||||
| 353 | if (lastQuote >= from)
| 10-3177 | ||||||||||||||||||
| 354 | str = unquote(str); executed 10 times by 4 tests: str = unquote(str);Executed by:
| 10 | ||||||||||||||||||
| 355 | list->append(str); | - | ||||||||||||||||||
| 356 | } executed 3187 times by 11 tests: end of blockExecuted by:
| 3187 | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | bool QDateTimeParser::parseFormat(const QString &newFormat) | - | ||||||||||||||||||
| 360 | { | - | ||||||||||||||||||
| 361 | const QLatin1Char quote('\''); | - | ||||||||||||||||||
| 362 | const QLatin1Char slash('\\'); | - | ||||||||||||||||||
| 363 | const QLatin1Char zero('0'); | - | ||||||||||||||||||
| 364 | if (newFormat == displayFormat && !newFormat.isEmpty()) {
| 2-1179 | ||||||||||||||||||
| 365 | return true; executed 173 times by 1 test: return true;Executed by:
| 173 | ||||||||||||||||||
| 366 | } | - | ||||||||||||||||||
| 367 | - | |||||||||||||||||||
| 368 | QDTPDEBUGN("parseFormat: %s", newFormat.toLatin1().constData()); dead code: QMessageLogger(__FILE__, 368, __PRETTY_FUNCTION__).debug("parseFormat: %s", newFormat.toLatin1().constData()); | - | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | QVector<SectionNode> newSectionNodes; | - | ||||||||||||||||||
| 371 | Sections newDisplay = 0; | - | ||||||||||||||||||
| 372 | QStringList newSeparators; | - | ||||||||||||||||||
| 373 | int i, index = 0; | - | ||||||||||||||||||
| 374 | int add = 0; | - | ||||||||||||||||||
| 375 | QChar status(zero); | - | ||||||||||||||||||
| 376 | const int max = newFormat.size(); | - | ||||||||||||||||||
| 377 | int lastQuote = -1; | - | ||||||||||||||||||
| 378 | for (i = 0; i<max; ++i) {
| 1181-7522 | ||||||||||||||||||
| 379 | if (newFormat.at(i) == quote) {
| 21-7501 | ||||||||||||||||||
| 380 | lastQuote = i; | - | ||||||||||||||||||
| 381 | ++add; | - | ||||||||||||||||||
| 382 | if (status != quote) {
| 10-11 | ||||||||||||||||||
| 383 | status = quote; | - | ||||||||||||||||||
| 384 | } else if (i > 0 && newFormat.at(i - 1) != slash) { executed 11 times by 4 tests: end of blockExecuted by:
| 0-11 | ||||||||||||||||||
| 385 | status = zero; | - | ||||||||||||||||||
| 386 | } executed 10 times by 4 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 387 | } else if (status != quote) { executed 21 times by 4 tests: end of blockExecuted by:
| 21-7462 | ||||||||||||||||||
| 388 | const char sect = newFormat.at(i).toLatin1(); | - | ||||||||||||||||||
| 389 | switch (sect) { | - | ||||||||||||||||||
| 390 | case 'H': executed 111 times by 4 tests: case 'H':Executed by:
| 111 | ||||||||||||||||||
| 391 | case 'h': executed 319 times by 8 tests: case 'h':Executed by:
| 319 | ||||||||||||||||||
| 392 | if (parserType != QVariant::Date) {
| 3-427 | ||||||||||||||||||
| 393 | const Section hour = (sect == 'h') ? Hour12Section : Hour24Section;
| 111-316 | ||||||||||||||||||
| 394 | const SectionNode sn = { hour, i - add, countRepeat(newFormat, i, 2), 0 }; | - | ||||||||||||||||||
| 395 | newSectionNodes.append(sn); | - | ||||||||||||||||||
| 396 | appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); | - | ||||||||||||||||||
| 397 | i += sn.count - 1; | - | ||||||||||||||||||
| 398 | index = i + 1; | - | ||||||||||||||||||
| 399 | newDisplay |= hour; | - | ||||||||||||||||||
| 400 | } executed 427 times by 8 tests: end of blockExecuted by:
| 427 | ||||||||||||||||||
| 401 | break; executed 430 times by 9 tests: break;Executed by:
| 430 | ||||||||||||||||||
| 402 | case 'm': executed 409 times by 8 tests: case 'm':Executed by:
| 409 | ||||||||||||||||||
| 403 | if (parserType != QVariant::Date) {
| 0-409 | ||||||||||||||||||
| 404 | const SectionNode sn = { MinuteSection, i - add, countRepeat(newFormat, i, 2), 0 }; | - | ||||||||||||||||||
| 405 | newSectionNodes.append(sn); | - | ||||||||||||||||||
| 406 | appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); | - | ||||||||||||||||||
| 407 | i += sn.count - 1; | - | ||||||||||||||||||
| 408 | index = i + 1; | - | ||||||||||||||||||
| 409 | newDisplay |= MinuteSection; | - | ||||||||||||||||||
| 410 | } executed 409 times by 8 tests: end of blockExecuted by:
| 409 | ||||||||||||||||||
| 411 | break; executed 409 times by 8 tests: break;Executed by:
| 409 | ||||||||||||||||||
| 412 | case 's': executed 260 times by 4 tests: case 's':Executed by:
| 260 | ||||||||||||||||||
| 413 | if (parserType != QVariant::Date) {
| 0-260 | ||||||||||||||||||
| 414 | const SectionNode sn = { SecondSection, i - add, countRepeat(newFormat, i, 2), 0 }; | - | ||||||||||||||||||
| 415 | newSectionNodes.append(sn); | - | ||||||||||||||||||
| 416 | appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); | - | ||||||||||||||||||
| 417 | i += sn.count - 1; | - | ||||||||||||||||||
| 418 | index = i + 1; | - | ||||||||||||||||||
| 419 | newDisplay |= SecondSection; | - | ||||||||||||||||||
| 420 | } executed 260 times by 4 tests: end of blockExecuted by:
| 260 | ||||||||||||||||||
| 421 | break; executed 260 times by 4 tests: break;Executed by:
| 260 | ||||||||||||||||||
| 422 | - | |||||||||||||||||||
| 423 | case 'z': executed 47 times by 2 tests: case 'z':Executed by:
| 47 | ||||||||||||||||||
| 424 | if (parserType != QVariant::Date) {
| 0-47 | ||||||||||||||||||
| 425 | const SectionNode sn = { MSecSection, i - add, countRepeat(newFormat, i, 3) < 3 ? 1 : 3, 0 }; | - | ||||||||||||||||||
| 426 | newSectionNodes.append(sn); | - | ||||||||||||||||||
| 427 | appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); | - | ||||||||||||||||||
| 428 | i += sn.count - 1; | - | ||||||||||||||||||
| 429 | index = i + 1; | - | ||||||||||||||||||
| 430 | newDisplay |= MSecSection; | - | ||||||||||||||||||
| 431 | } executed 47 times by 2 tests: end of blockExecuted by:
| 47 | ||||||||||||||||||
| 432 | break; executed 47 times by 2 tests: break;Executed by:
| 47 | ||||||||||||||||||
| 433 | case 'A': executed 16 times by 5 tests: case 'A':Executed by:
| 16 | ||||||||||||||||||
| 434 | case 'a': executed 79 times by 4 tests: case 'a':Executed by:
| 79 | ||||||||||||||||||
| 435 | if (parserType != QVariant::Date) {
| 2-93 | ||||||||||||||||||
| 436 | const bool cap = (sect == 'A'); | - | ||||||||||||||||||
| 437 | const SectionNode sn = { AmPmSection, i - add, (cap ? 1 : 0), 0 }; | - | ||||||||||||||||||
| 438 | newSectionNodes.append(sn); | - | ||||||||||||||||||
| 439 | appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); | - | ||||||||||||||||||
| 440 | newDisplay |= AmPmSection; | - | ||||||||||||||||||
| 441 | if (i + 1 < newFormat.size()
| 1-92 | ||||||||||||||||||
| 442 | && newFormat.at(i+1) == (cap ? QLatin1Char('P') : QLatin1Char('p'))) {
| 0-92 | ||||||||||||||||||
| 443 | ++i; | - | ||||||||||||||||||
| 444 | } executed 92 times by 5 tests: end of blockExecuted by:
| 92 | ||||||||||||||||||
| 445 | index = i + 1; | - | ||||||||||||||||||
| 446 | } executed 93 times by 5 tests: end of blockExecuted by:
| 93 | ||||||||||||||||||
| 447 | break; executed 95 times by 6 tests: break;Executed by:
| 95 | ||||||||||||||||||
| 448 | case 'y': executed 893 times by 10 tests: case 'y':Executed by:
| 893 | ||||||||||||||||||
| 449 | if (parserType != QVariant::Time) {
| 4-889 | ||||||||||||||||||
| 450 | const int repeat = countRepeat(newFormat, i, 4); | - | ||||||||||||||||||
| 451 | if (repeat >= 2) {
| 1-888 | ||||||||||||||||||
| 452 | const SectionNode sn = { repeat == 4 ? YearSection : YearSection2Digits, | - | ||||||||||||||||||
| 453 | i - add, repeat == 4 ? 4 : 2, 0 }; | - | ||||||||||||||||||
| 454 | newSectionNodes.append(sn); | - | ||||||||||||||||||
| 455 | appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); | - | ||||||||||||||||||
| 456 | i += sn.count - 1; | - | ||||||||||||||||||
| 457 | index = i + 1; | - | ||||||||||||||||||
| 458 | newDisplay |= sn.type; | - | ||||||||||||||||||
| 459 | } executed 888 times by 10 tests: end of blockExecuted by:
| 888 | ||||||||||||||||||
| 460 | } executed 889 times by 10 tests: end of blockExecuted by:
| 889 | ||||||||||||||||||
| 461 | break; executed 893 times by 10 tests: break;Executed by:
| 893 | ||||||||||||||||||
| 462 | case 'M': executed 1011 times by 10 tests: case 'M':Executed by:
| 1011 | ||||||||||||||||||
| 463 | if (parserType != QVariant::Time) {
| 0-1011 | ||||||||||||||||||
| 464 | const SectionNode sn = { MonthSection, i - add, countRepeat(newFormat, i, 4), 0 }; | - | ||||||||||||||||||
| 465 | newSectionNodes.append(sn); | - | ||||||||||||||||||
| 466 | newSeparators.append(unquote(newFormat.mid(index, i - index))); | - | ||||||||||||||||||
| 467 | i += sn.count - 1; | - | ||||||||||||||||||
| 468 | index = i + 1; | - | ||||||||||||||||||
| 469 | newDisplay |= MonthSection; | - | ||||||||||||||||||
| 470 | } executed 1011 times by 10 tests: end of blockExecuted by:
| 1011 | ||||||||||||||||||
| 471 | break; executed 1011 times by 10 tests: break;Executed by:
| 1011 | ||||||||||||||||||
| 472 | case 'd': executed 1047 times by 10 tests: case 'd':Executed by:
| 1047 | ||||||||||||||||||
| 473 | if (parserType != QVariant::Time) {
| 0-1047 | ||||||||||||||||||
| 474 | const int repeat = countRepeat(newFormat, i, 4); | - | ||||||||||||||||||
| 475 | const Section sectionType = (repeat == 4 ? DayOfWeekSectionLong
| 49-998 | ||||||||||||||||||
| 476 | : (repeat == 3 ? DayOfWeekSectionShort : DaySection));
| 6-992 | ||||||||||||||||||
| 477 | const SectionNode sn = { sectionType, i - add, repeat, 0 }; | - | ||||||||||||||||||
| 478 | newSectionNodes.append(sn); | - | ||||||||||||||||||
| 479 | appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); | - | ||||||||||||||||||
| 480 | i += sn.count - 1; | - | ||||||||||||||||||
| 481 | index = i + 1; | - | ||||||||||||||||||
| 482 | newDisplay |= sn.type; | - | ||||||||||||||||||
| 483 | } executed 1047 times by 10 tests: end of blockExecuted by:
| 1047 | ||||||||||||||||||
| 484 | break; executed 1047 times by 10 tests: break;Executed by:
| 1047 | ||||||||||||||||||
| 485 | - | |||||||||||||||||||
| 486 | default: executed 3270 times by 10 tests: default:Executed by:
| 3270 | ||||||||||||||||||
| 487 | break; executed 3270 times by 10 tests: break;Executed by:
| 3270 | ||||||||||||||||||
| 488 | } | - | ||||||||||||||||||
| 489 | } | - | ||||||||||||||||||
| 490 | } executed 7522 times by 11 tests: end of blockExecuted by:
| 7522 | ||||||||||||||||||
| 491 | if (newSectionNodes.isEmpty() && context == DateTimeEdit) {
| 2-1170 | ||||||||||||||||||
| 492 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 493 | } | - | ||||||||||||||||||
| 494 | - | |||||||||||||||||||
| 495 | if ((newDisplay & (AmPmSection|Hour12Section)) == Hour12Section) {
| 218-961 | ||||||||||||||||||
| 496 | const int count = newSectionNodes.size(); | - | ||||||||||||||||||
| 497 | for (int i = 0; i < count; ++i) {
| 218-878 | ||||||||||||||||||
| 498 | SectionNode &node = newSectionNodes[i]; | - | ||||||||||||||||||
| 499 | if (node.type == Hour12Section)
| 229-649 | ||||||||||||||||||
| 500 | node.type = Hour24Section; executed 229 times by 5 tests: node.type = Hour24Section;Executed by:
| 229 | ||||||||||||||||||
| 501 | } executed 878 times by 5 tests: end of blockExecuted by:
| 878 | ||||||||||||||||||
| 502 | } executed 218 times by 5 tests: end of blockExecuted by:
| 218 | ||||||||||||||||||
| 503 | - | |||||||||||||||||||
| 504 | if (index < max) {
| 16-1163 | ||||||||||||||||||
| 505 | appendSeparator(&newSeparators, newFormat, index, index - max, lastQuote); | - | ||||||||||||||||||
| 506 | } else { executed 16 times by 4 tests: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 507 | newSeparators.append(QString()); | - | ||||||||||||||||||
| 508 | } executed 1163 times by 10 tests: end of blockExecuted by:
| 1163 | ||||||||||||||||||
| 509 | - | |||||||||||||||||||
| 510 | displayFormat = newFormat; | - | ||||||||||||||||||
| 511 | separators = newSeparators; | - | ||||||||||||||||||
| 512 | sectionNodes = newSectionNodes; | - | ||||||||||||||||||
| 513 | display = newDisplay; | - | ||||||||||||||||||
| 514 | last.pos = -1; | - | ||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | // for (int i=0; i<sectionNodes.size(); ++i) { | - | ||||||||||||||||||
| 517 | // QDTPDEBUG << sectionNodes.at(i).name() << sectionNodes.at(i).count; | - | ||||||||||||||||||
| 518 | // } | - | ||||||||||||||||||
| 519 | - | |||||||||||||||||||
| 520 | QDTPDEBUG << newFormat << displayFormat; dead code: QMessageLogger(__FILE__, 520, __PRETTY_FUNCTION__).debug() << newFormat << displayFormat; | - | ||||||||||||||||||
| 521 | QDTPDEBUGN("separators:\n'%s'", separators.join(QLatin1String("\n")).toLatin1().constData()); dead code: QMessageLogger(__FILE__, 521, __PRETTY_FUNCTION__).debug("separators:\n'%s'", separators.join(QLatin1String("\n")).toLatin1().constData()); | - | ||||||||||||||||||
| 522 | - | |||||||||||||||||||
| 523 | return true; executed 1179 times by 11 tests: return true;Executed by:
| 1179 | ||||||||||||||||||
| 524 | } | - | ||||||||||||||||||
| 525 | - | |||||||||||||||||||
| 526 | /*! | - | ||||||||||||||||||
| 527 | \internal | - | ||||||||||||||||||
| 528 | - | |||||||||||||||||||
| 529 | Returns the size of section \a s. | - | ||||||||||||||||||
| 530 | */ | - | ||||||||||||||||||
| 531 | - | |||||||||||||||||||
| 532 | int QDateTimeParser::sectionSize(int sectionIndex) const | - | ||||||||||||||||||
| 533 | { | - | ||||||||||||||||||
| 534 | if (sectionIndex < 0)
| 0-18759 | ||||||||||||||||||
| 535 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 536 | - | |||||||||||||||||||
| 537 | if (sectionIndex >= sectionNodes.size()) {
| 0-18759 | ||||||||||||||||||
| 538 | qWarning("QDateTimeParser::sectionSize Internal error (%d)", sectionIndex); | - | ||||||||||||||||||
| 539 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 540 | } | - | ||||||||||||||||||
| 541 | - | |||||||||||||||||||
| 542 | if (sectionIndex == sectionNodes.size() - 1) {
| 4554-14205 | ||||||||||||||||||
| 543 | // In some cases there is a difference between displayText() and text. | - | ||||||||||||||||||
| 544 | // e.g. when text is 2000/01/31 and displayText() is "2000/2/31" - text | - | ||||||||||||||||||
| 545 | // is the previous value and displayText() is the new value. | - | ||||||||||||||||||
| 546 | // The size difference is always due to leading zeroes. | - | ||||||||||||||||||
| 547 | int sizeAdjustment = 0; | - | ||||||||||||||||||
| 548 | if (displayText().size() != text.size()) {
| 23-4531 | ||||||||||||||||||
| 549 | // Any zeroes added before this section will affect our size. | - | ||||||||||||||||||
| 550 | int preceedingZeroesAdded = 0; | - | ||||||||||||||||||
| 551 | if (sectionNodes.size() > 1 && context == DateTimeEdit) {
| 0-23 | ||||||||||||||||||
| 552 | for (QVector<SectionNode>::ConstIterator sectionIt = sectionNodes.constBegin(); | - | ||||||||||||||||||
| 553 | sectionIt != sectionNodes.constBegin() + sectionIndex; ++sectionIt) {
| 23-40 | ||||||||||||||||||
| 554 | preceedingZeroesAdded += sectionIt->zeroesAdded; | - | ||||||||||||||||||
| 555 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 556 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 557 | sizeAdjustment = preceedingZeroesAdded; | - | ||||||||||||||||||
| 558 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 559 | - | |||||||||||||||||||
| 560 | return displayText().size() + sizeAdjustment - sectionPos(sectionIndex) - separators.last().size(); executed 4554 times by 1 test: return displayText().size() + sizeAdjustment - sectionPos(sectionIndex) - separators.last().size();Executed by:
| 4554 | ||||||||||||||||||
| 561 | } else { | - | ||||||||||||||||||
| 562 | return sectionPos(sectionIndex + 1) - sectionPos(sectionIndex) executed 14205 times by 4 tests: return sectionPos(sectionIndex + 1) - sectionPos(sectionIndex) - separators.at(sectionIndex + 1).size();Executed by:
| 14205 | ||||||||||||||||||
| 563 | - separators.at(sectionIndex + 1).size(); executed 14205 times by 4 tests: return sectionPos(sectionIndex + 1) - sectionPos(sectionIndex) - separators.at(sectionIndex + 1).size();Executed by:
| 14205 | ||||||||||||||||||
| 564 | } | - | ||||||||||||||||||
| 565 | } | - | ||||||||||||||||||
| 566 | - | |||||||||||||||||||
| 567 | - | |||||||||||||||||||
| 568 | int QDateTimeParser::sectionMaxSize(Section s, int count) const | - | ||||||||||||||||||
| 569 | { | - | ||||||||||||||||||
| 570 | #ifndef QT_NO_TEXTDATE | - | ||||||||||||||||||
| 571 | int mcount = 12; | - | ||||||||||||||||||
| 572 | #endif | - | ||||||||||||||||||
| 573 | - | |||||||||||||||||||
| 574 | switch (s) { | - | ||||||||||||||||||
| 575 | case FirstSection: never executed: case FirstSection: | 0 | ||||||||||||||||||
| 576 | case NoSection: never executed: case NoSection: | 0 | ||||||||||||||||||
| 577 | case LastSection: return 0; never executed: return 0;never executed: case LastSection: | 0 | ||||||||||||||||||
| 578 | - | |||||||||||||||||||
| 579 | case AmPmSection: { executed 1726 times by 5 tests: case AmPmSection:Executed by:
| 1726 | ||||||||||||||||||
| 580 | const int lowerMax = qMin(getAmPmText(AmText, LowerCase).size(), | - | ||||||||||||||||||
| 581 | getAmPmText(PmText, LowerCase).size()); | - | ||||||||||||||||||
| 582 | const int upperMax = qMin(getAmPmText(AmText, UpperCase).size(), | - | ||||||||||||||||||
| 583 | getAmPmText(PmText, UpperCase).size()); | - | ||||||||||||||||||
| 584 | return qMin(4, qMin(lowerMax, upperMax)); executed 1726 times by 5 tests: return qMin(4, qMin(lowerMax, upperMax));Executed by:
| 1726 | ||||||||||||||||||
| 585 | } | - | ||||||||||||||||||
| 586 | - | |||||||||||||||||||
| 587 | case Hour24Section: executed 1513 times by 6 tests: case Hour24Section:Executed by:
| 1513 | ||||||||||||||||||
| 588 | case Hour12Section: executed 943 times by 5 tests: case Hour12Section:Executed by:
| 943 | ||||||||||||||||||
| 589 | case MinuteSection: executed 2262 times by 8 tests: case MinuteSection:Executed by:
| 2262 | ||||||||||||||||||
| 590 | case SecondSection: executed 1955 times by 4 tests: case SecondSection:Executed by:
| 1955 | ||||||||||||||||||
| 591 | case DaySection: return 2; executed 9876 times by 11 tests: return 2;Executed by:
executed 3203 times by 10 tests: case DaySection:Executed by:
| 3203-9876 | ||||||||||||||||||
| 592 | case DayOfWeekSectionShort: executed 40 times by 3 tests: case DayOfWeekSectionShort:Executed by:
| 40 | ||||||||||||||||||
| 593 | case DayOfWeekSectionLong: executed 442 times by 3 tests: case DayOfWeekSectionLong:Executed by:
| 442 | ||||||||||||||||||
| 594 | #ifdef QT_NO_TEXTDATE | - | ||||||||||||||||||
| 595 | return 2; | - | ||||||||||||||||||
| 596 | #else | - | ||||||||||||||||||
| 597 | mcount = 7; | - | ||||||||||||||||||
| 598 | // fall through | - | ||||||||||||||||||
| 599 | #endif | - | ||||||||||||||||||
| 600 | case MonthSection: code before this statement executed 482 times by 3 tests: case MonthSection:Executed by:
executed 3657 times by 10 tests: case MonthSection:Executed by:
| 482-3657 | ||||||||||||||||||
| 601 | #ifdef QT_NO_TEXTDATE | - | ||||||||||||||||||
| 602 | return 2; | - | ||||||||||||||||||
| 603 | #else | - | ||||||||||||||||||
| 604 | if (count <= 2)
| 1922-2217 | ||||||||||||||||||
| 605 | return 2; executed 2217 times by 7 tests: return 2;Executed by:
| 2217 | ||||||||||||||||||
| 606 | - | |||||||||||||||||||
| 607 | { | - | ||||||||||||||||||
| 608 | int ret = 0; | - | ||||||||||||||||||
| 609 | const QLocale l = locale(); | - | ||||||||||||||||||
| 610 | const QLocale::FormatType format = count == 4 ? QLocale::LongFormat : QLocale::ShortFormat;
| 655-1267 | ||||||||||||||||||
| 611 | for (int i=1; i<=mcount; ++i) {
| 1922-20654 | ||||||||||||||||||
| 612 | const QString str = (s == MonthSection
| 3374-17280 | ||||||||||||||||||
| 613 | ? l.monthName(i, format) | - | ||||||||||||||||||
| 614 | : l.dayName(i, format)); | - | ||||||||||||||||||
| 615 | ret = qMax(str.size(), ret); | - | ||||||||||||||||||
| 616 | } executed 20654 times by 6 tests: end of blockExecuted by:
| 20654 | ||||||||||||||||||
| 617 | return ret; executed 1922 times by 6 tests: return ret;Executed by:
| 1922 | ||||||||||||||||||
| 618 | } | - | ||||||||||||||||||
| 619 | #endif | - | ||||||||||||||||||
| 620 | case MSecSection: return 3; executed 283 times by 2 tests: return 3;Executed by:
executed 283 times by 2 tests: case MSecSection:Executed by:
| 283 | ||||||||||||||||||
| 621 | case YearSection: return 4; executed 2142 times by 6 tests: return 4;Executed by:
executed 2142 times by 6 tests: case YearSection:Executed by:
| 2142 | ||||||||||||||||||
| 622 | case YearSection2Digits: return 2; executed 907 times by 7 tests: return 2;Executed by:
executed 907 times by 7 tests: case YearSection2Digits:Executed by:
| 907 | ||||||||||||||||||
| 623 | - | |||||||||||||||||||
| 624 | case CalendarPopupSection: never executed: case CalendarPopupSection: | 0 | ||||||||||||||||||
| 625 | case Internal: never executed: case Internal: | 0 | ||||||||||||||||||
| 626 | case TimeSectionMask: never executed: case TimeSectionMask: | 0 | ||||||||||||||||||
| 627 | case DateSectionMask: never executed: case DateSectionMask: | 0 | ||||||||||||||||||
| 628 | case HourSectionMask: never executed: case HourSectionMask: | 0 | ||||||||||||||||||
| 629 | case YearSectionMask: never executed: case YearSectionMask: | 0 | ||||||||||||||||||
| 630 | case DayOfWeekSectionMask: never executed: case DayOfWeekSectionMask: | 0 | ||||||||||||||||||
| 631 | case DaySectionMask: never executed: case DaySectionMask: | 0 | ||||||||||||||||||
| 632 | qWarning("QDateTimeParser::sectionMaxSize: Invalid section %s", | - | ||||||||||||||||||
| 633 | SectionNode::name(s).toLatin1().constData()); | - | ||||||||||||||||||
| 634 | - | |||||||||||||||||||
| 635 | case NoSectionIndex: code before this statement never executed: case NoSectionIndex:never executed: case NoSectionIndex: | 0 | ||||||||||||||||||
| 636 | case FirstSectionIndex: never executed: case FirstSectionIndex: | 0 | ||||||||||||||||||
| 637 | case LastSectionIndex: never executed: case LastSectionIndex: | 0 | ||||||||||||||||||
| 638 | case CalendarPopupIndex: never executed: case CalendarPopupIndex: | 0 | ||||||||||||||||||
| 639 | // these cases can't happen | - | ||||||||||||||||||
| 640 | break; never executed: break; | 0 | ||||||||||||||||||
| 641 | } | - | ||||||||||||||||||
| 642 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 643 | } | - | ||||||||||||||||||
| 644 | - | |||||||||||||||||||
| 645 | - | |||||||||||||||||||
| 646 | int QDateTimeParser::sectionMaxSize(int index) const | - | ||||||||||||||||||
| 647 | { | - | ||||||||||||||||||
| 648 | const SectionNode &sn = sectionNode(index); | - | ||||||||||||||||||
| 649 | return sectionMaxSize(sn.type, sn.count); executed 19073 times by 11 tests: return sectionMaxSize(sn.type, sn.count);Executed by:
| 19073 | ||||||||||||||||||
| 650 | } | - | ||||||||||||||||||
| 651 | - | |||||||||||||||||||
| 652 | /*! | - | ||||||||||||||||||
| 653 | \internal | - | ||||||||||||||||||
| 654 | - | |||||||||||||||||||
| 655 | Returns the text of section \a s. This function operates on the | - | ||||||||||||||||||
| 656 | arg text rather than edit->text(). | - | ||||||||||||||||||
| 657 | */ | - | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | - | |||||||||||||||||||
| 660 | QString QDateTimeParser::sectionText(const QString &text, int sectionIndex, int index) const | - | ||||||||||||||||||
| 661 | { | - | ||||||||||||||||||
| 662 | const SectionNode &sn = sectionNode(sectionIndex); | - | ||||||||||||||||||
| 663 | switch (sn.type) { | - | ||||||||||||||||||
| 664 | case NoSectionIndex: never executed: case NoSectionIndex: | 0 | ||||||||||||||||||
| 665 | case FirstSectionIndex: never executed: case FirstSectionIndex: | 0 | ||||||||||||||||||
| 666 | case LastSectionIndex: never executed: case LastSectionIndex: | 0 | ||||||||||||||||||
| 667 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 668 | default: break; executed 175 times by 1 test: break;Executed by:
executed 175 times by 1 test: default:Executed by:
| 175 | ||||||||||||||||||
| 669 | } | - | ||||||||||||||||||
| 670 | - | |||||||||||||||||||
| 671 | return text.mid(index, sectionSize(sectionIndex)); executed 175 times by 1 test: return text.mid(index, sectionSize(sectionIndex));Executed by:
| 175 | ||||||||||||||||||
| 672 | } | - | ||||||||||||||||||
| 673 | - | |||||||||||||||||||
| 674 | QString QDateTimeParser::sectionText(int sectionIndex) const | - | ||||||||||||||||||
| 675 | { | - | ||||||||||||||||||
| 676 | const SectionNode &sn = sectionNode(sectionIndex); | - | ||||||||||||||||||
| 677 | return sectionText(displayText(), sectionIndex, sn.pos); executed 46 times by 1 test: return sectionText(displayText(), sectionIndex, sn.pos);Executed by:
| 46 | ||||||||||||||||||
| 678 | } | - | ||||||||||||||||||
| 679 | - | |||||||||||||||||||
| 680 | - | |||||||||||||||||||
| 681 | #ifndef QT_NO_TEXTDATE | - | ||||||||||||||||||
| 682 | /*! | - | ||||||||||||||||||
| 683 | \internal:skipToNextSection | - | ||||||||||||||||||
| 684 | - | |||||||||||||||||||
| 685 | Parses the part of \a text that corresponds to \a s and returns | - | ||||||||||||||||||
| 686 | the value of that field. Sets *stateptr to the right state if | - | ||||||||||||||||||
| 687 | stateptr != 0. | - | ||||||||||||||||||
| 688 | */ | - | ||||||||||||||||||
| 689 | - | |||||||||||||||||||
| 690 | int QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, | - | ||||||||||||||||||
| 691 | QString &text, int &cursorPosition, int index, | - | ||||||||||||||||||
| 692 | State &state, int *usedptr) const | - | ||||||||||||||||||
| 693 | { | - | ||||||||||||||||||
| 694 | state = Invalid; | - | ||||||||||||||||||
| 695 | int num = 0; | - | ||||||||||||||||||
| 696 | const SectionNode &sn = sectionNode(sectionIndex); | - | ||||||||||||||||||
| 697 | if ((sn.type & Internal) == Internal) {
| 0-15944 | ||||||||||||||||||
| 698 | qWarning("QDateTimeParser::parseSection Internal error (%s %d)", | - | ||||||||||||||||||
| 699 | qPrintable(sn.name()), sectionIndex); | - | ||||||||||||||||||
| 700 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 701 | } | - | ||||||||||||||||||
| 702 | - | |||||||||||||||||||
| 703 | const int sectionmaxsize = sectionMaxSize(sectionIndex); | - | ||||||||||||||||||
| 704 | QString sectiontext = text.mid(index, sectionmaxsize); | - | ||||||||||||||||||
| 705 | int sectiontextSize = sectiontext.size(); | - | ||||||||||||||||||
| 706 | - | |||||||||||||||||||
| 707 | QDTPDEBUG << "sectionValue for" << sn.name() dead code: QMessageLogger(__FILE__, 707, __PRETTY_FUNCTION__).debug() << "sectionValue for" << sn.name() << "with text" << text << "and st" << sectiontext << text.mid(index, sectionmaxsize) << index; | - | ||||||||||||||||||
| 708 | << "with text" << text << "and st" << sectiontext dead code: QMessageLogger(__FILE__, 707, __PRETTY_FUNCTION__).debug() << "sectionValue for" << sn.name() << "with text" << text << "and st" << sectiontext << text.mid(index, sectionmaxsize) << index; | - | ||||||||||||||||||
| 709 | << text.mid(index, sectionmaxsize) dead code: QMessageLogger(__FILE__, 707, __PRETTY_FUNCTION__).debug() << "sectionValue for" << sn.name() << "with text" << text << "and st" << sectiontext << text.mid(index, sectionmaxsize) << index; | - | ||||||||||||||||||
| 710 | << index; dead code: QMessageLogger(__FILE__, 707, __PRETTY_FUNCTION__).debug() << "sectionValue for" << sn.name() << "with text" << text << "and st" << sectiontext << text.mid(index, sectionmaxsize) << index; | - | ||||||||||||||||||
| 711 | - | |||||||||||||||||||
| 712 | int used = 0; | - | ||||||||||||||||||
| 713 | switch (sn.type) { | - | ||||||||||||||||||
| 714 | case AmPmSection: { executed 863 times by 5 tests: case AmPmSection:Executed by:
| 863 | ||||||||||||||||||
| 715 | const int ampm = findAmPm(sectiontext, sectionIndex, &used); | - | ||||||||||||||||||
| 716 | switch (ampm) { | - | ||||||||||||||||||
| 717 | case AM: // sectiontext == AM executed 758 times by 5 tests: case AM:Executed by:
| 758 | ||||||||||||||||||
| 718 | case PM: // sectiontext == PM executed 103 times by 3 tests: case PM:Executed by:
| 103 | ||||||||||||||||||
| 719 | num = ampm; | - | ||||||||||||||||||
| 720 | state = Acceptable; | - | ||||||||||||||||||
| 721 | break; executed 861 times by 5 tests: break;Executed by:
| 861 | ||||||||||||||||||
| 722 | case PossibleAM: // sectiontext => AM never executed: case PossibleAM: | 0 | ||||||||||||||||||
| 723 | case PossiblePM: // sectiontext => PM never executed: case PossiblePM: | 0 | ||||||||||||||||||
| 724 | num = ampm - 2; | - | ||||||||||||||||||
| 725 | state = Intermediate; | - | ||||||||||||||||||
| 726 | break; never executed: break; | 0 | ||||||||||||||||||
| 727 | case PossibleBoth: // sectiontext => AM|PM never executed: case PossibleBoth: | 0 | ||||||||||||||||||
| 728 | num = 0; | - | ||||||||||||||||||
| 729 | state = Intermediate; | - | ||||||||||||||||||
| 730 | break; never executed: break; | 0 | ||||||||||||||||||
| 731 | case Neither: executed 2 times by 2 tests: case Neither:Executed by:
| 2 | ||||||||||||||||||
| 732 | state = Invalid; | - | ||||||||||||||||||
| 733 | QDTPDEBUG << "invalid because findAmPm(" << sectiontext << ") returned -1"; dead code: QMessageLogger(__FILE__, 733, __PRETTY_FUNCTION__).debug() << "invalid because findAmPm(" << sectiontext << ") returned -1"; | - | ||||||||||||||||||
| 734 | break; executed 2 times by 2 tests: break;Executed by:
| 2 | ||||||||||||||||||
| 735 | default: never executed: default: | 0 | ||||||||||||||||||
| 736 | QDTPDEBUGN("This should never happen (findAmPm returned %d)", ampm); dead code: QMessageLogger(__FILE__, 736, __PRETTY_FUNCTION__).debug("This should never happen (findAmPm returned %d)", ampm); | - | ||||||||||||||||||
| 737 | break; never executed: break; | 0 | ||||||||||||||||||
| 738 | } | - | ||||||||||||||||||
| 739 | if (state != Invalid) {
| 2-861 | ||||||||||||||||||
| 740 | text.replace(index, used, sectiontext.left(used)); | - | ||||||||||||||||||
| 741 | } executed 861 times by 5 tests: end of blockExecuted by:
| 861 | ||||||||||||||||||
| 742 | break; } executed 863 times by 5 tests: break;Executed by:
| 863 | ||||||||||||||||||
| 743 | case MonthSection: executed 3176 times by 10 tests: case MonthSection:Executed by:
| 3176 | ||||||||||||||||||
| 744 | case DayOfWeekSectionShort: executed 40 times by 3 tests: case DayOfWeekSectionShort:Executed by:
| 40 | ||||||||||||||||||
| 745 | case DayOfWeekSectionLong: executed 442 times by 3 tests: case DayOfWeekSectionLong:Executed by:
| 442 | ||||||||||||||||||
| 746 | if (sn.count >= 3) {
| 1739-1919 | ||||||||||||||||||
| 747 | if (sn.type == MonthSection) {
| 482-1437 | ||||||||||||||||||
| 748 | int min = 1; | - | ||||||||||||||||||
| 749 | const QDate minDate = getMinimum().date(); | - | ||||||||||||||||||
| 750 | if (currentValue.date().year() == minDate.year()) {
| 17-1420 | ||||||||||||||||||
| 751 | min = minDate.month(); | - | ||||||||||||||||||
| 752 | } executed 17 times by 1 test: end of blockExecuted by:
| 17 | ||||||||||||||||||
| 753 | num = findMonth(sectiontext.toLower(), min, sectionIndex, §iontext, &used); | - | ||||||||||||||||||
| 754 | } else { executed 1437 times by 6 tests: end of blockExecuted by:
| 1437 | ||||||||||||||||||
| 755 | num = findDay(sectiontext.toLower(), 1, sectionIndex, §iontext, &used); | - | ||||||||||||||||||
| 756 | } executed 482 times by 3 tests: end of blockExecuted by:
| 482 | ||||||||||||||||||
| 757 | - | |||||||||||||||||||
| 758 | if (num != -1) {
| 5-1914 | ||||||||||||||||||
| 759 | state = (used == sectiontext.size() ? Acceptable : Intermediate);
| 107-1807 | ||||||||||||||||||
| 760 | text.replace(index, used, sectiontext.left(used)); | - | ||||||||||||||||||
| 761 | } else { executed 1914 times by 6 tests: end of blockExecuted by:
| 1914 | ||||||||||||||||||
| 762 | state = Intermediate; | - | ||||||||||||||||||
| 763 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 764 | break; executed 1919 times by 6 tests: break;Executed by:
| 1919 | ||||||||||||||||||
| 765 | } // else: fall through | - | ||||||||||||||||||
| 766 | case DaySection: code before this statement executed 1739 times by 7 tests: case DaySection:Executed by:
executed 2672 times by 10 tests: case DaySection:Executed by:
| 1739-2672 | ||||||||||||||||||
| 767 | case YearSection: executed 1913 times by 6 tests: case YearSection:Executed by:
| 1913 | ||||||||||||||||||
| 768 | case YearSection2Digits: executed 880 times by 7 tests: case YearSection2Digits:Executed by:
| 880 | ||||||||||||||||||
| 769 | case Hour12Section: executed 820 times by 5 tests: case Hour12Section:Executed by:
| 820 | ||||||||||||||||||
| 770 | case Hour24Section: executed 1276 times by 6 tests: case Hour24Section:Executed by:
| 1276 | ||||||||||||||||||
| 771 | case MinuteSection: executed 1916 times by 8 tests: case MinuteSection:Executed by:
| 1916 | ||||||||||||||||||
| 772 | case SecondSection: executed 1727 times by 4 tests: case SecondSection:Executed by:
| 1727 | ||||||||||||||||||
| 773 | case MSecSection: { executed 219 times by 2 tests: case MSecSection:Executed by:
| 219 | ||||||||||||||||||
| 774 | if (sectiontextSize == 0) {
| 17-13145 | ||||||||||||||||||
| 775 | num = 0; | - | ||||||||||||||||||
| 776 | used = 0; | - | ||||||||||||||||||
| 777 | state = Intermediate; | - | ||||||||||||||||||
| 778 | } else { executed 17 times by 2 tests: end of blockExecuted by:
| 17 | ||||||||||||||||||
| 779 | const int absMax = absoluteMax(sectionIndex); | - | ||||||||||||||||||
| 780 | QLocale loc; | - | ||||||||||||||||||
| 781 | bool ok = true; | - | ||||||||||||||||||
| 782 | int last = -1; | - | ||||||||||||||||||
| 783 | used = -1; | - | ||||||||||||||||||
| 784 | - | |||||||||||||||||||
| 785 | QString digitsStr(sectiontext); | - | ||||||||||||||||||
| 786 | for (int i = 0; i < sectiontextSize; ++i) {
| 12948-29874 | ||||||||||||||||||
| 787 | if (digitsStr.at(i).isSpace()) {
| 197-29677 | ||||||||||||||||||
| 788 | sectiontextSize = i; | - | ||||||||||||||||||
| 789 | break; executed 197 times by 4 tests: break;Executed by:
| 197 | ||||||||||||||||||
| 790 | } | - | ||||||||||||||||||
| 791 | } executed 29677 times by 11 tests: end of blockExecuted by:
| 29677 | ||||||||||||||||||
| 792 | - | |||||||||||||||||||
| 793 | const int max = qMin(sectionmaxsize, sectiontextSize); | - | ||||||||||||||||||
| 794 | for (int digits = max; digits >= 1; --digits) {
| 48-14117 | ||||||||||||||||||
| 795 | digitsStr.truncate(digits); | - | ||||||||||||||||||
| 796 | int tmp = (int)loc.toUInt(digitsStr, &ok); | - | ||||||||||||||||||
| 797 | if (ok && sn.type == Hour12Section) {
| 822-13105 | ||||||||||||||||||
| 798 | if (tmp > 12) {
| 2-820 | ||||||||||||||||||
| 799 | tmp = -1; | - | ||||||||||||||||||
| 800 | ok = false; | - | ||||||||||||||||||
| 801 | } else if (tmp == 12) { executed 2 times by 1 test: end of blockExecuted by:
| 2-720 | ||||||||||||||||||
| 802 | tmp = 0; | - | ||||||||||||||||||
| 803 | } executed 100 times by 3 tests: end of blockExecuted by:
| 100 | ||||||||||||||||||
| 804 | } executed 822 times by 5 tests: end of blockExecuted by:
| 822 | ||||||||||||||||||
| 805 | if (ok && tmp <= absMax) {
| 6-13103 | ||||||||||||||||||
| 806 | QDTPDEBUG << sectiontext.left(digits) << tmp << digits; dead code: QMessageLogger(__FILE__, 806, __PRETTY_FUNCTION__).debug() << sectiontext.left(digits) << tmp << digits; | - | ||||||||||||||||||
| 807 | last = tmp; | - | ||||||||||||||||||
| 808 | used = digits; | - | ||||||||||||||||||
| 809 | break; executed 13097 times by 11 tests: break;Executed by:
| 13097 | ||||||||||||||||||
| 810 | } | - | ||||||||||||||||||
| 811 | } executed 1020 times by 7 tests: end of blockExecuted by:
| 1020 | ||||||||||||||||||
| 812 | - | |||||||||||||||||||
| 813 | if (last == -1) {
| 48-13097 | ||||||||||||||||||
| 814 | QChar first(sectiontext.at(0)); | - | ||||||||||||||||||
| 815 | if (separators.at(sectionIndex + 1).startsWith(first)) {
| 2-46 | ||||||||||||||||||
| 816 | used = 0; | - | ||||||||||||||||||
| 817 | state = Intermediate; | - | ||||||||||||||||||
| 818 | } else { executed 46 times by 2 tests: end of blockExecuted by:
| 46 | ||||||||||||||||||
| 819 | state = Invalid; | - | ||||||||||||||||||
| 820 | QDTPDEBUG << "invalid because" << sectiontext << "can't become a uint" << last << ok; dead code: QMessageLogger(__FILE__, 820, __PRETTY_FUNCTION__).debug() << "invalid because" << sectiontext << "can't become a uint" << last << ok; | - | ||||||||||||||||||
| 821 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 822 | } else { | - | ||||||||||||||||||
| 823 | num += last; | - | ||||||||||||||||||
| 824 | const FieldInfo fi = fieldInfo(sectionIndex); | - | ||||||||||||||||||
| 825 | const bool done = (used == sectionmaxsize); | - | ||||||||||||||||||
| 826 | if (!done && fi & Fraction) { // typing 2 in a zzz field should be .200, not .002
| 1466-11631 | ||||||||||||||||||
| 827 | for (int i=used; i<sectionmaxsize; ++i) {
| 78-148 | ||||||||||||||||||
| 828 | num *= 10; | - | ||||||||||||||||||
| 829 | } executed 148 times by 1 test: end of blockExecuted by:
| 148 | ||||||||||||||||||
| 830 | } executed 78 times by 1 test: end of blockExecuted by:
| 78 | ||||||||||||||||||
| 831 | const int absMin = absoluteMin(sectionIndex); | - | ||||||||||||||||||
| 832 | if (num < absMin) {
| 25-13072 | ||||||||||||||||||
| 833 | state = done ? Invalid : Intermediate;
| 3-22 | ||||||||||||||||||
| 834 | if (done)
| 3-22 | ||||||||||||||||||
| 835 | QDTPDEBUG << "invalid because" << num << "is less than absoluteMin" << absMin; dead code: QMessageLogger(__FILE__, 835, __PRETTY_FUNCTION__).debug() << "invalid because" << num << "is less than absoluteMin" << absMin; | - | ||||||||||||||||||
| 836 | } else if (num > absMax) { executed 25 times by 1 test: end of blockExecuted by:
| 0-13072 | ||||||||||||||||||
| 837 | state = Intermediate; | - | ||||||||||||||||||
| 838 | } else if (!done && (fi & (FixedWidth|Numeric)) == (FixedWidth|Numeric)) { never executed: end of block
| 0-11628 | ||||||||||||||||||
| 839 | if (skipToNextSection(sectionIndex, currentValue, digitsStr)) {
| 27-438 | ||||||||||||||||||
| 840 | state = Acceptable; | - | ||||||||||||||||||
| 841 | const int missingZeroes = sectionmaxsize - digitsStr.size(); | - | ||||||||||||||||||
| 842 | text.insert(index, QString().fill(QLatin1Char('0'), missingZeroes)); | - | ||||||||||||||||||
| 843 | used = sectionmaxsize; | - | ||||||||||||||||||
| 844 | cursorPosition += missingZeroes; | - | ||||||||||||||||||
| 845 | ++(const_cast<QDateTimeParser*>(this)->sectionNodes[sectionIndex].zeroesAdded); | - | ||||||||||||||||||
| 846 | } else { executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||||||||||||||
| 847 | state = Intermediate;; | - | ||||||||||||||||||
| 848 | } executed 438 times by 4 tests: end of blockExecuted by:
| 438 | ||||||||||||||||||
| 849 | } else { | - | ||||||||||||||||||
| 850 | state = Acceptable; | - | ||||||||||||||||||
| 851 | } executed 12607 times by 11 tests: end of blockExecuted by:
| 12607 | ||||||||||||||||||
| 852 | } | - | ||||||||||||||||||
| 853 | } | - | ||||||||||||||||||
| 854 | break; } executed 13162 times by 11 tests: break;Executed by:
| 13162 | ||||||||||||||||||
| 855 | default: never executed: default: | 0 | ||||||||||||||||||
| 856 | qWarning("QDateTimeParser::parseSection Internal error (%s %d)", | - | ||||||||||||||||||
| 857 | qPrintable(sn.name()), sectionIndex); | - | ||||||||||||||||||
| 858 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 859 | } | - | ||||||||||||||||||
| 860 | - | |||||||||||||||||||
| 861 | if (usedptr)
| 0-15944 | ||||||||||||||||||
| 862 | *usedptr = used; executed 15944 times by 11 tests: *usedptr = used;Executed by:
| 15944 | ||||||||||||||||||
| 863 | - | |||||||||||||||||||
| 864 | return (state != Invalid ? num : -1); executed 15944 times by 11 tests: return (state != Invalid ? num : -1);Executed by:
| 7-15944 | ||||||||||||||||||
| 865 | } | - | ||||||||||||||||||
| 866 | #endif // QT_NO_TEXTDATE | - | ||||||||||||||||||
| 867 | - | |||||||||||||||||||
| 868 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||
| 869 | /*! | - | ||||||||||||||||||
| 870 | \internal | - | ||||||||||||||||||
| 871 | */ | - | ||||||||||||||||||
| 872 | - | |||||||||||||||||||
| 873 | QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPosition, | - | ||||||||||||||||||
| 874 | const QDateTime ¤tValue, bool fixup) const | - | ||||||||||||||||||
| 875 | { | - | ||||||||||||||||||
| 876 | const QDateTime minimum = getMinimum(); | - | ||||||||||||||||||
| 877 | const QDateTime maximum = getMaximum(); | - | ||||||||||||||||||
| 878 | - | |||||||||||||||||||
| 879 | State state = Acceptable; | - | ||||||||||||||||||
| 880 | - | |||||||||||||||||||
| 881 | QDateTime newCurrentValue; | - | ||||||||||||||||||
| 882 | bool conflicts = false; | - | ||||||||||||||||||
| 883 | const int sectionNodesCount = sectionNodes.size(); | - | ||||||||||||||||||
| 884 | - | |||||||||||||||||||
| 885 | QDTPDEBUG << "parse" << input; dead code: QMessageLogger(__FILE__, 885, __PRETTY_FUNCTION__).debug() << "parse" << input; | - | ||||||||||||||||||
| 886 | { | - | ||||||||||||||||||
| 887 | int pos = 0; | - | ||||||||||||||||||
| 888 | int year, month, day; | - | ||||||||||||||||||
| 889 | currentValue.date().getDate(&year, &month, &day); | - | ||||||||||||||||||
| 890 | int year2digits = year % 100; | - | ||||||||||||||||||
| 891 | int hour = currentValue.time().hour(); | - | ||||||||||||||||||
| 892 | int hour12 = -1; | - | ||||||||||||||||||
| 893 | int minute = currentValue.time().minute(); | - | ||||||||||||||||||
| 894 | int second = currentValue.time().second(); | - | ||||||||||||||||||
| 895 | int msec = currentValue.time().msec(); | - | ||||||||||||||||||
| 896 | int dayofweek = currentValue.date().dayOfWeek(); | - | ||||||||||||||||||
| 897 | - | |||||||||||||||||||
| 898 | int ampm = -1; | - | ||||||||||||||||||
| 899 | Sections isSet = NoSection; | - | ||||||||||||||||||
| 900 | int num; | - | ||||||||||||||||||
| 901 | State tmpstate; | - | ||||||||||||||||||
| 902 | - | |||||||||||||||||||
| 903 | for (int index=0; state != Invalid && index<sectionNodesCount; ++index) {
| 7-20663 | ||||||||||||||||||
| 904 | if (QStringRef(&input, pos, separators.at(index).size()) != separators.at(index)) {
| 122-15944 | ||||||||||||||||||
| 905 | QDTPDEBUG << "invalid because" << input.mid(pos, separators.at(index).size()) dead code: QMessageLogger(__FILE__, 905, __PRETTY_FUNCTION__).debug() << "invalid because" << input.mid(pos, separators.at(index).size()) << "!=" << separators.at(index) << index << pos << currentSectionIndex; | - | ||||||||||||||||||
| 906 | << "!=" << separators.at(index) dead code: QMessageLogger(__FILE__, 905, __PRETTY_FUNCTION__).debug() << "invalid because" << input.mid(pos, separators.at(index).size()) << "!=" << separators.at(index) << index << pos << currentSectionIndex; | - | ||||||||||||||||||
| 907 | << index << pos << currentSectionIndex; dead code: QMessageLogger(__FILE__, 905, __PRETTY_FUNCTION__).debug() << "invalid because" << input.mid(pos, separators.at(index).size()) << "!=" << separators.at(index) << index << pos << currentSectionIndex; | - | ||||||||||||||||||
| 908 | state = Invalid; | - | ||||||||||||||||||
| 909 | goto end; executed 122 times by 2 tests: goto end;Executed by:
| 122 | ||||||||||||||||||
| 910 | } | - | ||||||||||||||||||
| 911 | pos += separators.at(index).size(); | - | ||||||||||||||||||
| 912 | sectionNodes[index].pos = pos; | - | ||||||||||||||||||
| 913 | int *current = 0; | - | ||||||||||||||||||
| 914 | const SectionNode sn = sectionNodes.at(index); | - | ||||||||||||||||||
| 915 | int used; | - | ||||||||||||||||||
| 916 | - | |||||||||||||||||||
| 917 | num = parseSection(currentValue, index, input, cursorPosition, pos, tmpstate, &used); | - | ||||||||||||||||||
| 918 | QDTPDEBUG << "sectionValue" << sn.name() << input dead code: QMessageLogger(__FILE__, 918, __PRETTY_FUNCTION__).debug() << "sectionValue" << sn.name() << input << "pos" << pos << "used" << used << stateName(tmpstate); | - | ||||||||||||||||||
| 919 | << "pos" << pos << "used" << used << stateName(tmpstate); dead code: QMessageLogger(__FILE__, 918, __PRETTY_FUNCTION__).debug() << "sectionValue" << sn.name() << input << "pos" << pos << "used" << used << stateName(tmpstate); | - | ||||||||||||||||||
| 920 | if (fixup && tmpstate == Intermediate && used < sn.count) {
| 1-15871 | ||||||||||||||||||
| 921 | const FieldInfo fi = fieldInfo(index); | - | ||||||||||||||||||
| 922 | if ((fi & (Numeric|FixedWidth)) == (Numeric|FixedWidth)) {
| 3-17 | ||||||||||||||||||
| 923 | const QString newText = QString::fromLatin1("%1").arg(num, sn.count, 10, QLatin1Char('0')); | - | ||||||||||||||||||
| 924 | input.replace(pos, used, newText); | - | ||||||||||||||||||
| 925 | used = sn.count; | - | ||||||||||||||||||
| 926 | } executed 17 times by 1 test: end of blockExecuted by:
| 17 | ||||||||||||||||||
| 927 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 928 | pos += qMax(0, used); | - | ||||||||||||||||||
| 929 | - | |||||||||||||||||||
| 930 | state = qMin<State>(state, tmpstate); | - | ||||||||||||||||||
| 931 | if (state == Intermediate && context == FromString) {
| 12-14591 | ||||||||||||||||||
| 932 | state = Invalid; | - | ||||||||||||||||||
| 933 | break; executed 12 times by 4 tests: break;Executed by:
| 12 | ||||||||||||||||||
| 934 | } | - | ||||||||||||||||||
| 935 | - | |||||||||||||||||||
| 936 | QDTPDEBUG << index << sn.name() << "is set to" dead code: QMessageLogger(__FILE__, 936, __PRETTY_FUNCTION__).debug() << index << sn.name() << "is set to" << pos << "state is" << stateName(state); | - | ||||||||||||||||||
| 937 | << pos << "state is" << stateName(state); dead code: QMessageLogger(__FILE__, 936, __PRETTY_FUNCTION__).debug() << index << sn.name() << "is set to" << pos << "state is" << stateName(state); | - | ||||||||||||||||||
| 938 | - | |||||||||||||||||||
| 939 | - | |||||||||||||||||||
| 940 | if (state != Invalid) {
| 7-15925 | ||||||||||||||||||
| 941 | switch (sn.type) { | - | ||||||||||||||||||
| 942 | case Hour24Section: current = &hour; break; executed 1275 times by 6 tests: break;Executed by:
executed 1275 times by 6 tests: case Hour24Section:Executed by:
| 1275 | ||||||||||||||||||
| 943 | case Hour12Section: current = &hour12; break; executed 820 times by 5 tests: break;Executed by:
executed 820 times by 5 tests: case Hour12Section:Executed by:
| 820 | ||||||||||||||||||
| 944 | case MinuteSection: current = &minute; break; executed 1915 times by 8 tests: break;Executed by:
executed 1915 times by 8 tests: case MinuteSection:Executed by:
| 1915 | ||||||||||||||||||
| 945 | case SecondSection: current = &second; break; executed 1727 times by 4 tests: break;Executed by:
executed 1727 times by 4 tests: case SecondSection:Executed by:
| 1727 | ||||||||||||||||||
| 946 | case MSecSection: current = &msec; break; executed 219 times by 2 tests: break;Executed by:
executed 219 times by 2 tests: case MSecSection:Executed by:
| 219 | ||||||||||||||||||
| 947 | case YearSection: current = &year; break; executed 1913 times by 6 tests: break;Executed by:
executed 1913 times by 6 tests: case YearSection:Executed by:
| 1913 | ||||||||||||||||||
| 948 | case YearSection2Digits: current = &year2digits; break; executed 879 times by 7 tests: break;Executed by:
executed 879 times by 7 tests: case YearSection2Digits:Executed by:
| 879 | ||||||||||||||||||
| 949 | case MonthSection: current = &month; break; executed 3173 times by 10 tests: break;Executed by:
executed 3173 times by 10 tests: case MonthSection:Executed by:
| 3173 | ||||||||||||||||||
| 950 | case DayOfWeekSectionShort: executed 40 times by 3 tests: case DayOfWeekSectionShort:Executed by:
| 40 | ||||||||||||||||||
| 951 | case DayOfWeekSectionLong: current = &dayofweek; break; executed 482 times by 3 tests: break;Executed by:
executed 442 times by 3 tests: case DayOfWeekSectionLong:Executed by:
| 442-482 | ||||||||||||||||||
| 952 | case DaySection: current = &day; num = qMax<int>(1, num); break; executed 2661 times by 10 tests: break;Executed by:
executed 2661 times by 10 tests: case DaySection:Executed by:
| 2661 | ||||||||||||||||||
| 953 | case AmPmSection: current = &m; break; executed 861 times by 5 tests: break;Executed by:
executed 861 times by 5 tests: case AmPmSection:Executed by:
| 861 | ||||||||||||||||||
| 954 | default: never executed: default: | 0 | ||||||||||||||||||
| 955 | qWarning("QDateTimeParser::parse Internal error (%s)", | - | ||||||||||||||||||
| 956 | qPrintable(sn.name())); | - | ||||||||||||||||||
| 957 | break; never executed: break; | 0 | ||||||||||||||||||
| 958 | } | - | ||||||||||||||||||
| 959 | if (!current) {
| 0-15925 | ||||||||||||||||||
| 960 | qWarning("QDateTimeParser::parse Internal error 2"); | - | ||||||||||||||||||
| 961 | return StateNode(); never executed: return StateNode(); | 0 | ||||||||||||||||||
| 962 | } | - | ||||||||||||||||||
| 963 | if (isSet & sn.type && *current != num) {
| 101-416 | ||||||||||||||||||
| 964 | QDTPDEBUG << "CONFLICT " << sn.name() << *current << num; dead code: QMessageLogger(__FILE__, 964, __PRETTY_FUNCTION__).debug() << "CONFLICT " << sn.name() << *current << num; | - | ||||||||||||||||||
| 965 | conflicts = true; | - | ||||||||||||||||||
| 966 | if (index != currentSectionIndex || num == -1) {
| 0-96 | ||||||||||||||||||
| 967 | continue; executed 96 times by 3 tests: continue;Executed by:
| 96 | ||||||||||||||||||
| 968 | } | - | ||||||||||||||||||
| 969 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 970 | if (num != -1)
| 5-15824 | ||||||||||||||||||
| 971 | *current = num; executed 15824 times by 11 tests: *current = num;Executed by:
| 15824 | ||||||||||||||||||
| 972 | isSet |= sn.type; | - | ||||||||||||||||||
| 973 | } executed 15829 times by 11 tests: end of blockExecuted by:
| 15829 | ||||||||||||||||||
| 974 | } executed 15836 times by 11 tests: end of blockExecuted by:
| 15836 | ||||||||||||||||||
| 975 | - | |||||||||||||||||||
| 976 | if (state != Invalid && QStringRef(&input, pos, input.size() - pos) != separators.last()) {
| 15-4597 | ||||||||||||||||||
| 977 | QDTPDEBUG << "invalid because" << input.mid(pos) dead code: QMessageLogger(__FILE__, 977, __PRETTY_FUNCTION__).debug() << "invalid because" << input.mid(pos) << "!=" << separators.last() << pos; | - | ||||||||||||||||||
| 978 | << "!=" << separators.last() << pos; dead code: QMessageLogger(__FILE__, 977, __PRETTY_FUNCTION__).debug() << "invalid because" << input.mid(pos) << "!=" << separators.last() << pos; | - | ||||||||||||||||||
| 979 | state = Invalid; | - | ||||||||||||||||||
| 980 | } executed 15 times by 4 tests: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 981 | - | |||||||||||||||||||
| 982 | if (state != Invalid) {
| 34-4582 | ||||||||||||||||||
| 983 | if (parserType != QVariant::Time) {
| 23-4559 | ||||||||||||||||||
| 984 | if (year % 100 != year2digits && (isSet & YearSection2Digits)) {
| 389-4170 | ||||||||||||||||||
| 985 | if (!(isSet & YearSection)) {
| 1-16 | ||||||||||||||||||
| 986 | year = (year / 100) * 100; | - | ||||||||||||||||||
| 987 | year += year2digits; | - | ||||||||||||||||||
| 988 | } else { executed 16 times by 4 tests: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 989 | conflicts = true; | - | ||||||||||||||||||
| 990 | const SectionNode &sn = sectionNode(currentSectionIndex); | - | ||||||||||||||||||
| 991 | if (sn.type == YearSection2Digits) {
| 0-1 | ||||||||||||||||||
| 992 | year = (year / 100) * 100; | - | ||||||||||||||||||
| 993 | year += year2digits; | - | ||||||||||||||||||
| 994 | } never executed: end of block | 0 | ||||||||||||||||||
| 995 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 996 | } | - | ||||||||||||||||||
| 997 | - | |||||||||||||||||||
| 998 | const QDate date(year, month, day); | - | ||||||||||||||||||
| 999 | const int diff = dayofweek - date.dayOfWeek(); | - | ||||||||||||||||||
| 1000 | if (diff != 0 && state == Acceptable && isSet & DayOfWeekSectionMask) {
| 209-4023 | ||||||||||||||||||
| 1001 | if (isSet & DaySection)
| 2-26 | ||||||||||||||||||
| 1002 | conflicts = true; executed 2 times by 1 test: conflicts = true;Executed by:
| 2 | ||||||||||||||||||
| 1003 | const SectionNode &sn = sectionNode(currentSectionIndex); | - | ||||||||||||||||||
| 1004 | if (sn.type & DayOfWeekSectionMask || currentSectionIndex == -1) {
| 0-28 | ||||||||||||||||||
| 1005 | // dayofweek should be preferred | - | ||||||||||||||||||
| 1006 | day += diff; | - | ||||||||||||||||||
| 1007 | if (day <= 0) {
| 6-8 | ||||||||||||||||||
| 1008 | day += 7; | - | ||||||||||||||||||
| 1009 | } else if (day > date.daysInMonth()) { executed 8 times by 2 tests: end of blockExecuted by:
| 0-8 | ||||||||||||||||||
| 1010 | day -= 7; | - | ||||||||||||||||||
| 1011 | } never executed: end of block | 0 | ||||||||||||||||||
| 1012 | QDTPDEBUG << year << month << day << dayofweek dead code: QMessageLogger(__FILE__, 1012, __PRETTY_FUNCTION__).debug() << year << month << day << dayofweek << diff << QDate(year, month, day).dayOfWeek(); | - | ||||||||||||||||||
| 1013 | << diff << QDate(year, month, day).dayOfWeek(); dead code: QMessageLogger(__FILE__, 1012, __PRETTY_FUNCTION__).debug() << year << month << day << dayofweek << diff << QDate(year, month, day).dayOfWeek(); | - | ||||||||||||||||||
| 1014 | } executed 14 times by 2 tests: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 1015 | } executed 28 times by 3 tests: end of blockExecuted by:
| 28 | ||||||||||||||||||
| 1016 | - | |||||||||||||||||||
| 1017 | bool needfixday = false; | - | ||||||||||||||||||
| 1018 | if (sectionType(currentSectionIndex) & DaySectionMask) {
| 1208-3351 | ||||||||||||||||||
| 1019 | cachedDay = day; | - | ||||||||||||||||||
| 1020 | } else if (cachedDay > day) { executed 1208 times by 1 test: end of blockExecuted by:
| 12-3339 | ||||||||||||||||||
| 1021 | day = cachedDay; | - | ||||||||||||||||||
| 1022 | needfixday = true; | - | ||||||||||||||||||
| 1023 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1024 | - | |||||||||||||||||||
| 1025 | if (!QDate::isValid(year, month, day)) {
| 88-4471 | ||||||||||||||||||
| 1026 | if (day < 32) {
| 0-88 | ||||||||||||||||||
| 1027 | cachedDay = day; | - | ||||||||||||||||||
| 1028 | } executed 88 times by 2 tests: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 1029 | if (day > 28 && QDate::isValid(year, month, 1)) {
| 0-51 | ||||||||||||||||||
| 1030 | needfixday = true; | - | ||||||||||||||||||
| 1031 | } executed 51 times by 2 tests: end of blockExecuted by:
| 51 | ||||||||||||||||||
| 1032 | } executed 88 times by 2 tests: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 1033 | if (needfixday) {
| 51-4508 | ||||||||||||||||||
| 1034 | if (context == FromString) {
| 1-50 | ||||||||||||||||||
| 1035 | state = Invalid; | - | ||||||||||||||||||
| 1036 | goto end; executed 1 time by 1 test: goto end;Executed by:
| 1 | ||||||||||||||||||
| 1037 | } | - | ||||||||||||||||||
| 1038 | if (state == Acceptable && fixday) {
| 0-50 | ||||||||||||||||||
| 1039 | day = qMin<int>(day, QDate(year, month, 1).daysInMonth()); | - | ||||||||||||||||||
| 1040 | - | |||||||||||||||||||
| 1041 | const QLocale loc = locale(); | - | ||||||||||||||||||
| 1042 | for (int i=0; i<sectionNodesCount; ++i) {
| 50-149 | ||||||||||||||||||
| 1043 | const SectionNode sn = sectionNode(i); | - | ||||||||||||||||||
| 1044 | if (sn.type & DaySection) {
| 38-111 | ||||||||||||||||||
| 1045 | input.replace(sectionPos(sn), sectionSize(i), loc.toString(day)); | - | ||||||||||||||||||
| 1046 | } else if (sn.type & DayOfWeekSectionMask) { executed 38 times by 1 test: end of blockExecuted by:
| 14-97 | ||||||||||||||||||
| 1047 | const int dayOfWeek = QDate(year, month, day).dayOfWeek(); | - | ||||||||||||||||||
| 1048 | const QLocale::FormatType dayFormat = | - | ||||||||||||||||||
| 1049 | (sn.type == DayOfWeekSectionShort
| 1-13 | ||||||||||||||||||
| 1050 | ? QLocale::ShortFormat : QLocale::LongFormat); | - | ||||||||||||||||||
| 1051 | const QString dayName(loc.dayName(dayOfWeek, dayFormat)); | - | ||||||||||||||||||
| 1052 | input.replace(sectionPos(sn), sectionSize(i), dayName); | - | ||||||||||||||||||
| 1053 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 1054 | } executed 149 times by 1 test: end of blockExecuted by:
| 149 | ||||||||||||||||||
| 1055 | } else { executed 50 times by 1 test: end of blockExecuted by:
| 50 | ||||||||||||||||||
| 1056 | state = qMin(Intermediate, state); | - | ||||||||||||||||||
| 1057 | } never executed: end of block | 0 | ||||||||||||||||||
| 1058 | } | - | ||||||||||||||||||
| 1059 | } executed 4558 times by 10 tests: end of blockExecuted by:
| 4558 | ||||||||||||||||||
| 1060 | - | |||||||||||||||||||
| 1061 | if (parserType != QVariant::Date) {
| 870-3711 | ||||||||||||||||||
| 1062 | if (isSet & Hour12Section) {
| 808-2903 | ||||||||||||||||||
| 1063 | const bool hasHour = isSet & Hour24Section; | - | ||||||||||||||||||
| 1064 | if (ampm == -1) {
| 0-808 | ||||||||||||||||||
| 1065 | if (hasHour) {
| 0 | ||||||||||||||||||
| 1066 | ampm = (hour < 12 ? 0 : 1);
| 0 | ||||||||||||||||||
| 1067 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1068 | ampm = 0; // no way to tell if this is am or pm so I assume am | - | ||||||||||||||||||
| 1069 | } never executed: end of block | 0 | ||||||||||||||||||
| 1070 | } | - | ||||||||||||||||||
| 1071 | hour12 = (ampm == 0 ? hour12 % 12 : (hour12 % 12) + 12);
| 78-730 | ||||||||||||||||||
| 1072 | if (!hasHour) {
| 2-806 | ||||||||||||||||||
| 1073 | hour = hour12; | - | ||||||||||||||||||
| 1074 | } else if (hour != hour12) { executed 806 times by 5 tests: end of blockExecuted by:
| 0-806 | ||||||||||||||||||
| 1075 | conflicts = true; | - | ||||||||||||||||||
| 1076 | } never executed: end of block | 0 | ||||||||||||||||||
| 1077 | } else if (ampm != -1) { executed 808 times by 5 tests: end of blockExecuted by:
| 51-2852 | ||||||||||||||||||
| 1078 | if (!(isSet & (Hour24Section))) {
| 3-48 | ||||||||||||||||||
| 1079 | hour = (12 * ampm); // special case. Only ap section | - | ||||||||||||||||||
| 1080 | } else if ((ampm == 0) != (hour < 12)) { executed 3 times by 2 tests: end of blockExecuted by:
| 0-48 | ||||||||||||||||||
| 1081 | conflicts = true; | - | ||||||||||||||||||
| 1082 | } never executed: end of block | 0 | ||||||||||||||||||
| 1083 | } executed 51 times by 3 tests: end of blockExecuted by:
| 51 | ||||||||||||||||||
| 1084 | - | |||||||||||||||||||
| 1085 | } executed 3711 times by 9 tests: end of blockExecuted by:
| 3711 | ||||||||||||||||||
| 1086 | - | |||||||||||||||||||
| 1087 | newCurrentValue = QDateTime(QDate(year, month, day), QTime(hour, minute, second, msec), spec); | - | ||||||||||||||||||
| 1088 | QDTPDEBUG << year << month << day << hour << minute << second << msec; dead code: QMessageLogger(__FILE__, 1088, __PRETTY_FUNCTION__).debug() << year << month << day << hour << minute << second << msec; | - | ||||||||||||||||||
| 1089 | } executed 4581 times by 11 tests: end of blockExecuted by:
| 4581 | ||||||||||||||||||
| 1090 | QDTPDEBUGN("'%s' => '%s'(%s)", input.toLatin1().constData(), dead code: QMessageLogger(__FILE__, 1090, __PRETTY_FUNCTION__).debug("'%s' => '%s'(%s)", input.toLatin1().constData(), newCurrentValue.toString(QLatin1String("yyyy/MM/dd hh:mm:ss.zzz")).toLatin1().constData(), stateName(state).toLatin1().constData()); | - | ||||||||||||||||||
| 1091 | newCurrentValue.toString(QLatin1String("yyyy/MM/dd hh:mm:ss.zzz")).toLatin1().constData(), dead code: QMessageLogger(__FILE__, 1090, __PRETTY_FUNCTION__).debug("'%s' => '%s'(%s)", input.toLatin1().constData(), newCurrentValue.toString(QLatin1String("yyyy/MM/dd hh:mm:ss.zzz")).toLatin1().constData(), stateName(state).toLatin1().constData()); | - | ||||||||||||||||||
| 1092 | stateName(state).toLatin1().constData()); dead code: QMessageLogger(__FILE__, 1090, __PRETTY_FUNCTION__).debug("'%s' => '%s'(%s)", input.toLatin1().constData(), newCurrentValue.toString(QLatin1String("yyyy/MM/dd hh:mm:ss.zzz")).toLatin1().constData(), stateName(state).toLatin1().constData()); | - | ||||||||||||||||||
| 1093 | } | - | ||||||||||||||||||
| 1094 | end: code before this statement executed 4615 times by 11 tests: end:Executed by:
| 4615 | ||||||||||||||||||
| 1095 | if (newCurrentValue.isValid()) {
| 194-4544 | ||||||||||||||||||
| 1096 | if (context != FromString && state != Invalid && newCurrentValue < minimum) {
| 0-4049 | ||||||||||||||||||
| 1097 | const QLatin1Char space(' '); | - | ||||||||||||||||||
| 1098 | if (newCurrentValue >= minimum)
| 0-53 | ||||||||||||||||||
| 1099 | qWarning("QDateTimeParser::parse Internal error 3 (%s %s)", never executed: QMessageLogger(__FILE__, 1099, __PRETTY_FUNCTION__).warning("QDateTimeParser::parse Internal error 3 (%s %s)", QString(newCurrentValue.toString()).toLocal8Bit().constData(), QString(minimum.toString()).toLocal8Bit().constData()); | 0 | ||||||||||||||||||
| 1100 | qPrintable(newCurrentValue.toString()), qPrintable(minimum.toString())); never executed: QMessageLogger(__FILE__, 1099, __PRETTY_FUNCTION__).warning("QDateTimeParser::parse Internal error 3 (%s %s)", QString(newCurrentValue.toString()).toLocal8Bit().constData(), QString(minimum.toString()).toLocal8Bit().constData()); | 0 | ||||||||||||||||||
| 1101 | - | |||||||||||||||||||
| 1102 | bool done = false; | - | ||||||||||||||||||
| 1103 | state = Invalid; | - | ||||||||||||||||||
| 1104 | for (int i=0; i<sectionNodesCount && !done; ++i) {
| 9-138 | ||||||||||||||||||
| 1105 | const SectionNode &sn = sectionNodes.at(i); | - | ||||||||||||||||||
| 1106 | QString t = sectionText(input, i, sn.pos).toLower(); | - | ||||||||||||||||||
| 1107 | if ((t.size() < sectionMaxSize(i) && (((int)fieldInfo(i) & (FixedWidth|Numeric)) != Numeric))
| 0-74 | ||||||||||||||||||
| 1108 | || t.contains(space)) {
| 0-74 | ||||||||||||||||||
| 1109 | switch (sn.type) { | - | ||||||||||||||||||
| 1110 | case AmPmSection: never executed: case AmPmSection: | 0 | ||||||||||||||||||
| 1111 | switch (findAmPm(t, i)) { | - | ||||||||||||||||||
| 1112 | case AM: never executed: case AM: | 0 | ||||||||||||||||||
| 1113 | case PM: never executed: case PM: | 0 | ||||||||||||||||||
| 1114 | state = Acceptable; | - | ||||||||||||||||||
| 1115 | done = true; | - | ||||||||||||||||||
| 1116 | break; never executed: break; | 0 | ||||||||||||||||||
| 1117 | case Neither: never executed: case Neither: | 0 | ||||||||||||||||||
| 1118 | state = Invalid; | - | ||||||||||||||||||
| 1119 | done = true; | - | ||||||||||||||||||
| 1120 | break; never executed: break; | 0 | ||||||||||||||||||
| 1121 | case PossibleAM: never executed: case PossibleAM: | 0 | ||||||||||||||||||
| 1122 | case PossiblePM: never executed: case PossiblePM: | 0 | ||||||||||||||||||
| 1123 | case PossibleBoth: { never executed: case PossibleBoth: | 0 | ||||||||||||||||||
| 1124 | const QDateTime copy(newCurrentValue.addSecs(12 * 60 * 60)); | - | ||||||||||||||||||
| 1125 | if (copy >= minimum && copy <= maximum) {
| 0 | ||||||||||||||||||
| 1126 | state = Intermediate; | - | ||||||||||||||||||
| 1127 | done = true; | - | ||||||||||||||||||
| 1128 | } never executed: end of block | 0 | ||||||||||||||||||
| 1129 | break; } never executed: break; | 0 | ||||||||||||||||||
| 1130 | } | - | ||||||||||||||||||
| 1131 | case MonthSection: code before this statement never executed: case MonthSection:executed 3 times by 1 test: case MonthSection:Executed by:
| 0-3 | ||||||||||||||||||
| 1132 | if (sn.count >= 3) {
| 0-3 | ||||||||||||||||||
| 1133 | int tmp = newCurrentValue.date().month(); | - | ||||||||||||||||||
| 1134 | // I know the first possible month makes the date too early | - | ||||||||||||||||||
| 1135 | while ((tmp = findMonth(t, tmp + 1, i)) != -1) {
| 3-6 | ||||||||||||||||||
| 1136 | const QDateTime copy(newCurrentValue.addMonths(tmp - newCurrentValue.date().month())); | - | ||||||||||||||||||
| 1137 | if (copy >= minimum && copy <= maximum)
| 0-6 | ||||||||||||||||||
| 1138 | break; // break out of while never executed: break; | 0 | ||||||||||||||||||
| 1139 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 1140 | if (tmp == -1) {
| 0-3 | ||||||||||||||||||
| 1141 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 1142 | } | - | ||||||||||||||||||
| 1143 | state = Intermediate; | - | ||||||||||||||||||
| 1144 | done = true; | - | ||||||||||||||||||
| 1145 | break; never executed: break; | 0 | ||||||||||||||||||
| 1146 | } | - | ||||||||||||||||||
| 1147 | // fallthrough | - | ||||||||||||||||||
| 1148 | default: { code before this statement never executed: default:executed 52 times by 1 test: default:Executed by:
| 0-52 | ||||||||||||||||||
| 1149 | int toMin; | - | ||||||||||||||||||
| 1150 | int toMax; | - | ||||||||||||||||||
| 1151 | - | |||||||||||||||||||
| 1152 | if (sn.type & TimeSectionMask) {
| 20-32 | ||||||||||||||||||
| 1153 | if (newCurrentValue.daysTo(minimum) != 0) {
| 0-20 | ||||||||||||||||||
| 1154 | break; never executed: break; | 0 | ||||||||||||||||||
| 1155 | } | - | ||||||||||||||||||
| 1156 | toMin = newCurrentValue.time().msecsTo(minimum.time()); | - | ||||||||||||||||||
| 1157 | if (newCurrentValue.daysTo(maximum) > 0) {
| 0-20 | ||||||||||||||||||
| 1158 | toMax = -1; // can't get to max | - | ||||||||||||||||||
| 1159 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1160 | toMax = newCurrentValue.time().msecsTo(maximum.time()); | - | ||||||||||||||||||
| 1161 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 1162 | } else { | - | ||||||||||||||||||
| 1163 | toMin = newCurrentValue.daysTo(minimum); | - | ||||||||||||||||||
| 1164 | toMax = newCurrentValue.daysTo(maximum); | - | ||||||||||||||||||
| 1165 | } executed 32 times by 1 test: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 1166 | const int maxChange = sn.maxChange(); | - | ||||||||||||||||||
| 1167 | if (toMin > maxChange) {
| 0-52 | ||||||||||||||||||
| 1168 | QDTPDEBUG << "invalid because toMin > maxChange" << toMin dead code: QMessageLogger(__FILE__, 1168, __PRETTY_FUNCTION__).debug() << "invalid because toMin > maxChange" << toMin << maxChange << t << newCurrentValue << minimum; | - | ||||||||||||||||||
| 1169 | << maxChange << t << newCurrentValue << minimum; dead code: QMessageLogger(__FILE__, 1168, __PRETTY_FUNCTION__).debug() << "invalid because toMin > maxChange" << toMin << maxChange << t << newCurrentValue << minimum; | - | ||||||||||||||||||
| 1170 | state = Invalid; | - | ||||||||||||||||||
| 1171 | done = true; | - | ||||||||||||||||||
| 1172 | break; never executed: break; | 0 | ||||||||||||||||||
| 1173 | } else if (toMax > maxChange) {
| 14-38 | ||||||||||||||||||
| 1174 | toMax = -1; // can't get to max | - | ||||||||||||||||||
| 1175 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 1176 | - | |||||||||||||||||||
| 1177 | const int min = getDigit(minimum, i); | - | ||||||||||||||||||
| 1178 | if (min == -1) {
| 0-52 | ||||||||||||||||||
| 1179 | qWarning("QDateTimeParser::parse Internal error 4 (%s)", | - | ||||||||||||||||||
| 1180 | qPrintable(sn.name())); | - | ||||||||||||||||||
| 1181 | state = Invalid; | - | ||||||||||||||||||
| 1182 | done = true; | - | ||||||||||||||||||
| 1183 | break; never executed: break; | 0 | ||||||||||||||||||
| 1184 | } | - | ||||||||||||||||||
| 1185 | - | |||||||||||||||||||
| 1186 | int max = toMax != -1 ? getDigit(maximum, i) : absoluteMax(i, newCurrentValue);
| 14-38 | ||||||||||||||||||
| 1187 | int pos = cursorPosition - sn.pos; | - | ||||||||||||||||||
| 1188 | if (pos < 0 || pos >= t.size())
| 4-48 | ||||||||||||||||||
| 1189 | pos = -1; executed 45 times by 1 test: pos = -1;Executed by:
| 45 | ||||||||||||||||||
| 1190 | if (!potentialValue(t.simplified(), min, max, i, newCurrentValue, pos)) {
| 2-50 | ||||||||||||||||||
| 1191 | QDTPDEBUG << "invalid because potentialValue(" << t.simplified() << min << max dead code: QMessageLogger(__FILE__, 1191, __PRETTY_FUNCTION__).debug() << "invalid because potentialValue(" << t.simplified() << min << max << sn.name() << "returned" << toMax << toMin << pos; | - | ||||||||||||||||||
| 1192 | << sn.name() << "returned" << toMax << toMin << pos; dead code: QMessageLogger(__FILE__, 1191, __PRETTY_FUNCTION__).debug() << "invalid because potentialValue(" << t.simplified() << min << max << sn.name() << "returned" << toMax << toMin << pos; | - | ||||||||||||||||||
| 1193 | state = Invalid; | - | ||||||||||||||||||
| 1194 | done = true; | - | ||||||||||||||||||
| 1195 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||
| 1196 | } | - | ||||||||||||||||||
| 1197 | state = Intermediate; | - | ||||||||||||||||||
| 1198 | done = true; | - | ||||||||||||||||||
| 1199 | break; } executed 50 times by 1 test: break;Executed by:
| 50 | ||||||||||||||||||
| 1200 | } | - | ||||||||||||||||||
| 1201 | } | - | ||||||||||||||||||
| 1202 | } executed 129 times by 1 test: end of blockExecuted by:
| 129 | ||||||||||||||||||
| 1203 | } else { executed 53 times by 1 test: end of blockExecuted by:
| 53 | ||||||||||||||||||
| 1204 | if (context == FromString) {
| 495-3996 | ||||||||||||||||||
| 1205 | // optimization | - | ||||||||||||||||||
| 1206 | Q_ASSERT(getMaximum().date().toJulianDay() == 4642999); | - | ||||||||||||||||||
| 1207 | if (newCurrentValue.date().toJulianDay() > 4642999)
| 0-495 | ||||||||||||||||||
| 1208 | state = Invalid; never executed: state = Invalid; | 0 | ||||||||||||||||||
| 1209 | } else { executed 495 times by 8 tests: end of blockExecuted by:
| 495 | ||||||||||||||||||
| 1210 | if (newCurrentValue > getMaximum())
| 1-3995 | ||||||||||||||||||
| 1211 | state = Invalid; executed 1 time by 1 test: state = Invalid;Executed by:
| 1 | ||||||||||||||||||
| 1212 | } executed 3996 times by 4 tests: end of blockExecuted by:
| 3996 | ||||||||||||||||||
| 1213 | - | |||||||||||||||||||
| 1214 | QDTPDEBUG << "not checking intermediate because newCurrentValue is" << newCurrentValue << getMinimum() << getMaximum(); dead code: QMessageLogger(__FILE__, 1214, __PRETTY_FUNCTION__).debug() << "not checking intermediate because newCurrentValue is" << newCurrentValue << getMinimum() << getMaximum(); | - | ||||||||||||||||||
| 1215 | } executed 4491 times by 11 tests: end of blockExecuted by:
| 4491 | ||||||||||||||||||
| 1216 | } | - | ||||||||||||||||||
| 1217 | StateNode node; | - | ||||||||||||||||||
| 1218 | node.input = input; | - | ||||||||||||||||||
| 1219 | node.state = state; | - | ||||||||||||||||||
| 1220 | node.conflicts = conflicts; | - | ||||||||||||||||||
| 1221 | node.value = newCurrentValue.toTimeSpec(spec); | - | ||||||||||||||||||
| 1222 | text = input; | - | ||||||||||||||||||
| 1223 | return node; executed 4738 times by 11 tests: return node;Executed by:
| 4738 | ||||||||||||||||||
| 1224 | } | - | ||||||||||||||||||
| 1225 | #endif // QT_NO_DATESTRING | - | ||||||||||||||||||
| 1226 | - | |||||||||||||||||||
| 1227 | #ifndef QT_NO_TEXTDATE | - | ||||||||||||||||||
| 1228 | /*! | - | ||||||||||||||||||
| 1229 | \internal | - | ||||||||||||||||||
| 1230 | finds the first possible monthname that \a str1 can | - | ||||||||||||||||||
| 1231 | match. Starting from \a index; str should already by lowered | - | ||||||||||||||||||
| 1232 | */ | - | ||||||||||||||||||
| 1233 | - | |||||||||||||||||||
| 1234 | int QDateTimeParser::findMonth(const QString &str1, int startMonth, int sectionIndex, | - | ||||||||||||||||||
| 1235 | QString *usedMonth, int *used) const | - | ||||||||||||||||||
| 1236 | { | - | ||||||||||||||||||
| 1237 | int bestMatch = -1; | - | ||||||||||||||||||
| 1238 | int bestCount = 0; | - | ||||||||||||||||||
| 1239 | if (!str1.isEmpty()) {
| 0-1446 | ||||||||||||||||||
| 1240 | const SectionNode &sn = sectionNode(sectionIndex); | - | ||||||||||||||||||
| 1241 | if (sn.type != MonthSection) {
| 0-1446 | ||||||||||||||||||
| 1242 | qWarning("QDateTimeParser::findMonth Internal error"); | - | ||||||||||||||||||
| 1243 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 1244 | } | - | ||||||||||||||||||
| 1245 | - | |||||||||||||||||||
| 1246 | QLocale::FormatType type = sn.count == 3 ? QLocale::ShortFormat : QLocale::LongFormat;
| 219-1227 | ||||||||||||||||||
| 1247 | QLocale l = locale(); | - | ||||||||||||||||||
| 1248 | - | |||||||||||||||||||
| 1249 | for (int month=startMonth; month<=12; ++month) {
| 118-6730 | ||||||||||||||||||
| 1250 | QString str2 = l.monthName(month, type).toLower(); | - | ||||||||||||||||||
| 1251 | - | |||||||||||||||||||
| 1252 | if (str1.startsWith(str2)) {
| 1325-5405 | ||||||||||||||||||
| 1253 | if (used) {
| 0-1325 | ||||||||||||||||||
| 1254 | QDTPDEBUG << "used is set to" << str2.size(); dead code: QMessageLogger(__FILE__, 1254, __PRETTY_FUNCTION__).debug() << "used is set to" << str2.size(); | - | ||||||||||||||||||
| 1255 | *used = str2.size(); | - | ||||||||||||||||||
| 1256 | } executed 1325 times by 6 tests: end of blockExecuted by:
| 1325 | ||||||||||||||||||
| 1257 | if (usedMonth)
| 0-1325 | ||||||||||||||||||
| 1258 | *usedMonth = l.monthName(month, type); executed 1325 times by 6 tests: *usedMonth = l.monthName(month, type);Executed by:
| 1325 | ||||||||||||||||||
| 1259 | - | |||||||||||||||||||
| 1260 | return month; executed 1325 times by 6 tests: return month;Executed by:
| 1325 | ||||||||||||||||||
| 1261 | } | - | ||||||||||||||||||
| 1262 | if (context == FromString)
| 1599-3806 | ||||||||||||||||||
| 1263 | continue; executed 3806 times by 5 tests: continue;Executed by:
| 3806 | ||||||||||||||||||
| 1264 | - | |||||||||||||||||||
| 1265 | const int limit = qMin(str1.size(), str2.size()); | - | ||||||||||||||||||
| 1266 | - | |||||||||||||||||||
| 1267 | QDTPDEBUG << "limit is" << limit << str1 << str2; dead code: QMessageLogger(__FILE__, 1267, __PRETTY_FUNCTION__).debug() << "limit is" << limit << str1 << str2; | - | ||||||||||||||||||
| 1268 | bool equal = true; | - | ||||||||||||||||||
| 1269 | for (int i=0; i<limit; ++i) {
| 3-2263 | ||||||||||||||||||
| 1270 | if (str1.at(i) != str2.at(i)) {
| 667-1596 | ||||||||||||||||||
| 1271 | equal = false; | - | ||||||||||||||||||
| 1272 | if (i > bestCount) {
| 177-1419 | ||||||||||||||||||
| 1273 | bestCount = i; | - | ||||||||||||||||||
| 1274 | bestMatch = month; | - | ||||||||||||||||||
| 1275 | } executed 177 times by 1 test: end of blockExecuted by:
| 177 | ||||||||||||||||||
| 1276 | break; executed 1596 times by 1 test: break;Executed by:
| 1596 | ||||||||||||||||||
| 1277 | } | - | ||||||||||||||||||
| 1278 | } executed 667 times by 1 test: end of blockExecuted by:
| 667 | ||||||||||||||||||
| 1279 | if (equal) {
| 3-1596 | ||||||||||||||||||
| 1280 | if (used)
| 0-3 | ||||||||||||||||||
| 1281 | *used = limit; executed 3 times by 1 test: *used = limit;Executed by:
| 3 | ||||||||||||||||||
| 1282 | if (usedMonth)
| 0-3 | ||||||||||||||||||
| 1283 | *usedMonth = l.monthName(month, type); executed 3 times by 1 test: *usedMonth = l.monthName(month, type);Executed by:
| 3 | ||||||||||||||||||
| 1284 | return month; executed 3 times by 1 test: return month;Executed by:
| 3 | ||||||||||||||||||
| 1285 | } | - | ||||||||||||||||||
| 1286 | } executed 1596 times by 1 test: end of blockExecuted by:
| 1596 | ||||||||||||||||||
| 1287 | if (usedMonth && bestMatch != -1)
| 5-109 | ||||||||||||||||||
| 1288 | *usedMonth = l.monthName(bestMatch, type); executed 104 times by 1 test: *usedMonth = l.monthName(bestMatch, type);Executed by:
| 104 | ||||||||||||||||||
| 1289 | } executed 118 times by 1 test: end of blockExecuted by:
| 118 | ||||||||||||||||||
| 1290 | if (used) {
| 9-109 | ||||||||||||||||||
| 1291 | QDTPDEBUG << "used is set to" << bestCount; dead code: QMessageLogger(__FILE__, 1291, __PRETTY_FUNCTION__).debug() << "used is set to" << bestCount; | - | ||||||||||||||||||
| 1292 | *used = bestCount; | - | ||||||||||||||||||
| 1293 | } executed 109 times by 1 test: end of blockExecuted by:
| 109 | ||||||||||||||||||
| 1294 | return bestMatch; executed 118 times by 1 test: return bestMatch;Executed by:
| 118 | ||||||||||||||||||
| 1295 | } | - | ||||||||||||||||||
| 1296 | - | |||||||||||||||||||
| 1297 | int QDateTimeParser::findDay(const QString &str1, int startDay, int sectionIndex, QString *usedDay, int *used) const | - | ||||||||||||||||||
| 1298 | { | - | ||||||||||||||||||
| 1299 | int bestMatch = -1; | - | ||||||||||||||||||
| 1300 | int bestCount = 0; | - | ||||||||||||||||||
| 1301 | if (!str1.isEmpty()) {
| 0-482 | ||||||||||||||||||
| 1302 | const SectionNode &sn = sectionNode(sectionIndex); | - | ||||||||||||||||||
| 1303 | if (!(sn.type & DaySectionMask)) {
| 0-482 | ||||||||||||||||||
| 1304 | qWarning("QDateTimeParser::findDay Internal error"); | - | ||||||||||||||||||
| 1305 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 1306 | } | - | ||||||||||||||||||
| 1307 | const QLocale l = locale(); | - | ||||||||||||||||||
| 1308 | for (int day=startDay; day<=7; ++day) {
| 482-3374 | ||||||||||||||||||
| 1309 | const QString dayName = l.dayName(day, sn.count == 4 ? QLocale::LongFormat : QLocale::ShortFormat); | - | ||||||||||||||||||
| 1310 | const QString str2 = dayName.toLower(); | - | ||||||||||||||||||
| 1311 | - | |||||||||||||||||||
| 1312 | const int limit = qMin(str1.size(), str2.size()); | - | ||||||||||||||||||
| 1313 | int i = 0; | - | ||||||||||||||||||
| 1314 | while (i < limit && str1.at(i) == str2.at(i))
| 488-6442 | ||||||||||||||||||
| 1315 | ++i; executed 3556 times by 3 tests: ++i;Executed by:
| 3556 | ||||||||||||||||||
| 1316 | if (i > bestCount) {
| 602-2772 | ||||||||||||||||||
| 1317 | bestCount = i; | - | ||||||||||||||||||
| 1318 | bestMatch = day; | - | ||||||||||||||||||
| 1319 | } executed 602 times by 3 tests: end of blockExecuted by:
| 602 | ||||||||||||||||||
| 1320 | } executed 3374 times by 3 tests: end of blockExecuted by:
| 3374 | ||||||||||||||||||
| 1321 | if (usedDay && bestMatch != -1) {
| 0-482 | ||||||||||||||||||
| 1322 | *usedDay = l.dayName(bestMatch, sn.count == 4 ? QLocale::LongFormat : QLocale::ShortFormat); | - | ||||||||||||||||||
| 1323 | } executed 482 times by 3 tests: end of blockExecuted by:
| 482 | ||||||||||||||||||
| 1324 | } executed 482 times by 3 tests: end of blockExecuted by:
| 482 | ||||||||||||||||||
| 1325 | if (used)
| 0-482 | ||||||||||||||||||
| 1326 | *used = bestCount; executed 482 times by 3 tests: *used = bestCount;Executed by:
| 482 | ||||||||||||||||||
| 1327 | - | |||||||||||||||||||
| 1328 | return bestMatch; executed 482 times by 3 tests: return bestMatch;Executed by:
| 482 | ||||||||||||||||||
| 1329 | } | - | ||||||||||||||||||
| 1330 | #endif // QT_NO_TEXTDATE | - | ||||||||||||||||||
| 1331 | - | |||||||||||||||||||
| 1332 | /*! | - | ||||||||||||||||||
| 1333 | \internal | - | ||||||||||||||||||
| 1334 | - | |||||||||||||||||||
| 1335 | Returns | - | ||||||||||||||||||
| 1336 | AM if str == tr("AM") | - | ||||||||||||||||||
| 1337 | PM if str == tr("PM") | - | ||||||||||||||||||
| 1338 | PossibleAM if str can become tr("AM") | - | ||||||||||||||||||
| 1339 | PossiblePM if str can become tr("PM") | - | ||||||||||||||||||
| 1340 | PossibleBoth if str can become tr("PM") and can become tr("AM") | - | ||||||||||||||||||
| 1341 | Neither if str can't become anything sensible | - | ||||||||||||||||||
| 1342 | */ | - | ||||||||||||||||||
| 1343 | QDateTimeParser::AmPmFinder QDateTimeParser::findAmPm(QString &str, int sectionIndex, int *used) const | - | ||||||||||||||||||
| 1344 | { | - | ||||||||||||||||||
| 1345 | const SectionNode &s = sectionNode(sectionIndex); | - | ||||||||||||||||||
| 1346 | if (s.type != AmPmSection) {
| 0-863 | ||||||||||||||||||
| 1347 | qWarning("QDateTimeParser::findAmPm Internal error"); | - | ||||||||||||||||||
| 1348 | return Neither; never executed: return Neither; | 0 | ||||||||||||||||||
| 1349 | } | - | ||||||||||||||||||
| 1350 | if (used)
| 0-863 | ||||||||||||||||||
| 1351 | *used = str.size(); executed 863 times by 5 tests: *used = str.size();Executed by:
| 863 | ||||||||||||||||||
| 1352 | if (str.trimmed().isEmpty()) {
| 0-863 | ||||||||||||||||||
| 1353 | return PossibleBoth; never executed: return PossibleBoth; | 0 | ||||||||||||||||||
| 1354 | } | - | ||||||||||||||||||
| 1355 | const QLatin1Char space(' '); | - | ||||||||||||||||||
| 1356 | int size = sectionMaxSize(sectionIndex); | - | ||||||||||||||||||
| 1357 | - | |||||||||||||||||||
| 1358 | enum { | - | ||||||||||||||||||
| 1359 | amindex = 0, | - | ||||||||||||||||||
| 1360 | pmindex = 1 | - | ||||||||||||||||||
| 1361 | }; | - | ||||||||||||||||||
| 1362 | QString ampm[2]; | - | ||||||||||||||||||
| 1363 | ampm[amindex] = getAmPmText(AmText, s.count == 1 ? UpperCase : LowerCase); | - | ||||||||||||||||||
| 1364 | ampm[pmindex] = getAmPmText(PmText, s.count == 1 ? UpperCase : LowerCase); | - | ||||||||||||||||||
| 1365 | for (int i=0; i<2; ++i)
| 863-1726 | ||||||||||||||||||
| 1366 | ampm[i].truncate(size); executed 1726 times by 5 tests: ampm[i].truncate(size);Executed by:
| 1726 | ||||||||||||||||||
| 1367 | - | |||||||||||||||||||
| 1368 | QDTPDEBUG << "findAmPm" << str << ampm[0] << ampm[1]; dead code: QMessageLogger(__FILE__, 1368, __PRETTY_FUNCTION__).debug() << "findAmPm" << str << ampm[0] << ampm[1]; | - | ||||||||||||||||||
| 1369 | - | |||||||||||||||||||
| 1370 | if (str.indexOf(ampm[amindex], 0, Qt::CaseInsensitive) == 0) {
| 105-758 | ||||||||||||||||||
| 1371 | str = ampm[amindex]; | - | ||||||||||||||||||
| 1372 | return AM; executed 758 times by 5 tests: return AM;Executed by:
| 758 | ||||||||||||||||||
| 1373 | } else if (str.indexOf(ampm[pmindex], 0, Qt::CaseInsensitive) == 0) {
| 2-103 | ||||||||||||||||||
| 1374 | str = ampm[pmindex]; | - | ||||||||||||||||||
| 1375 | return PM; executed 103 times by 3 tests: return PM;Executed by:
| 103 | ||||||||||||||||||
| 1376 | } else if (context == FromString || (str.count(space) == 0 && str.size() >= size)) {
| 0-1 | ||||||||||||||||||
| 1377 | return Neither; executed 1 time by 1 test: return Neither;Executed by:
| 1 | ||||||||||||||||||
| 1378 | } | - | ||||||||||||||||||
| 1379 | size = qMin(size, str.size()); | - | ||||||||||||||||||
| 1380 | - | |||||||||||||||||||
| 1381 | bool broken[2] = {false, false}; | - | ||||||||||||||||||
| 1382 | for (int i=0; i<size; ++i) {
| 0-1 | ||||||||||||||||||
| 1383 | if (str.at(i) != space) {
| 0-1 | ||||||||||||||||||
| 1384 | for (int j=0; j<2; ++j) {
| 0-2 | ||||||||||||||||||
| 1385 | if (!broken[j]) {
| 0-2 | ||||||||||||||||||
| 1386 | int index = ampm[j].indexOf(str.at(i)); | - | ||||||||||||||||||
| 1387 | QDTPDEBUG << "looking for" << str.at(i) dead code: QMessageLogger(__FILE__, 1387, __PRETTY_FUNCTION__).debug() << "looking for" << str.at(i) << "in" << ampm[j] << "and got" << index; | - | ||||||||||||||||||
| 1388 | << "in" << ampm[j] << "and got" << index; dead code: QMessageLogger(__FILE__, 1387, __PRETTY_FUNCTION__).debug() << "looking for" << str.at(i) << "in" << ampm[j] << "and got" << index; | - | ||||||||||||||||||
| 1389 | if (index == -1) {
| 0-2 | ||||||||||||||||||
| 1390 | if (str.at(i).category() == QChar::Letter_Uppercase) {
| 0-2 | ||||||||||||||||||
| 1391 | index = ampm[j].indexOf(str.at(i).toLower()); | - | ||||||||||||||||||
| 1392 | QDTPDEBUG << "trying with" << str.at(i).toLower() dead code: QMessageLogger(__FILE__, 1392, __PRETTY_FUNCTION__).debug() << "trying with" << str.at(i).toLower() << "in" << ampm[j] << "and got" << index; | - | ||||||||||||||||||
| 1393 | << "in" << ampm[j] << "and got" << index; dead code: QMessageLogger(__FILE__, 1392, __PRETTY_FUNCTION__).debug() << "trying with" << str.at(i).toLower() << "in" << ampm[j] << "and got" << index; | - | ||||||||||||||||||
| 1394 | } else if (str.at(i).category() == QChar::Letter_Lowercase) { never executed: end of block
| 0-2 | ||||||||||||||||||
| 1395 | index = ampm[j].indexOf(str.at(i).toUpper()); | - | ||||||||||||||||||
| 1396 | QDTPDEBUG << "trying with" << str.at(i).toUpper() dead code: QMessageLogger(__FILE__, 1396, __PRETTY_FUNCTION__).debug() << "trying with" << str.at(i).toUpper() << "in" << ampm[j] << "and got" << index; | - | ||||||||||||||||||
| 1397 | << "in" << ampm[j] << "and got" << index; dead code: QMessageLogger(__FILE__, 1396, __PRETTY_FUNCTION__).debug() << "trying with" << str.at(i).toUpper() << "in" << ampm[j] << "and got" << index; | - | ||||||||||||||||||
| 1398 | } never executed: end of block | 0 | ||||||||||||||||||
| 1399 | if (index == -1) {
| 0-2 | ||||||||||||||||||
| 1400 | broken[j] = true; | - | ||||||||||||||||||
| 1401 | if (broken[amindex] && broken[pmindex]) {
| 0-2 | ||||||||||||||||||
| 1402 | QDTPDEBUG << str << "didn't make it"; dead code: QMessageLogger(__FILE__, 1402, __PRETTY_FUNCTION__).debug() << str << "didn't make it"; | - | ||||||||||||||||||
| 1403 | return Neither; executed 1 time by 1 test: return Neither;Executed by:
| 1 | ||||||||||||||||||
| 1404 | } | - | ||||||||||||||||||
| 1405 | continue; executed 1 time by 1 test: continue;Executed by:
| 1 | ||||||||||||||||||
| 1406 | } else { | - | ||||||||||||||||||
| 1407 | str[i] = ampm[j].at(index); // fix case | - | ||||||||||||||||||
| 1408 | } never executed: end of block | 0 | ||||||||||||||||||
| 1409 | } | - | ||||||||||||||||||
| 1410 | ampm[j].remove(index, 1); | - | ||||||||||||||||||
| 1411 | } never executed: end of block | 0 | ||||||||||||||||||
| 1412 | } never executed: end of block | 0 | ||||||||||||||||||
| 1413 | } never executed: end of block | 0 | ||||||||||||||||||
| 1414 | } never executed: end of block | 0 | ||||||||||||||||||
| 1415 | if (!broken[pmindex] && !broken[amindex])
| 0 | ||||||||||||||||||
| 1416 | return PossibleBoth; never executed: return PossibleBoth; | 0 | ||||||||||||||||||
| 1417 | return (!broken[amindex] ? PossibleAM : PossiblePM); never executed: return (!broken[amindex] ? PossibleAM : PossiblePM);
| 0 | ||||||||||||||||||
| 1418 | } | - | ||||||||||||||||||
| 1419 | - | |||||||||||||||||||
| 1420 | /*! | - | ||||||||||||||||||
| 1421 | \internal | - | ||||||||||||||||||
| 1422 | Max number of units that can be changed by this section. | - | ||||||||||||||||||
| 1423 | */ | - | ||||||||||||||||||
| 1424 | - | |||||||||||||||||||
| 1425 | int QDateTimeParser::SectionNode::maxChange() const | - | ||||||||||||||||||
| 1426 | { | - | ||||||||||||||||||
| 1427 | switch (type) { | - | ||||||||||||||||||
| 1428 | // Time. unit is msec | - | ||||||||||||||||||
| 1429 | case MSecSection: return 999; never executed: return 999;never executed: case MSecSection: | 0 | ||||||||||||||||||
| 1430 | case SecondSection: return 59 * 1000; never executed: return 59 * 1000;never executed: case SecondSection: | 0 | ||||||||||||||||||
| 1431 | case MinuteSection: return 59 * 60 * 1000; executed 11 times by 1 test: return 59 * 60 * 1000;Executed by:
executed 11 times by 1 test: case MinuteSection:Executed by:
| 11 | ||||||||||||||||||
| 1432 | case Hour24Section: case Hour12Section: return 59 * 60 * 60 * 1000; executed 9 times by 1 test: return 59 * 60 * 60 * 1000;Executed by:
executed 9 times by 1 test: case Hour24Section:Executed by:
never executed: case Hour12Section: | 0-9 | ||||||||||||||||||
| 1433 | - | |||||||||||||||||||
| 1434 | // Date. unit is day | - | ||||||||||||||||||
| 1435 | case DayOfWeekSectionShort: never executed: case DayOfWeekSectionShort: | 0 | ||||||||||||||||||
| 1436 | case DayOfWeekSectionLong: return 7; never executed: return 7;never executed: case DayOfWeekSectionLong: | 0 | ||||||||||||||||||
| 1437 | case DaySection: return 30; never executed: return 30;never executed: case DaySection: | 0 | ||||||||||||||||||
| 1438 | case MonthSection: return 365 - 31; never executed: return 365 - 31;never executed: case MonthSection: | 0 | ||||||||||||||||||
| 1439 | case YearSection: return 9999 * 365; executed 29 times by 1 test: return 9999 * 365;Executed by:
executed 29 times by 1 test: case YearSection:Executed by:
| 29 | ||||||||||||||||||
| 1440 | case YearSection2Digits: return 100 * 365; executed 3 times by 1 test: return 100 * 365;Executed by:
executed 3 times by 1 test: case YearSection2Digits:Executed by:
| 3 | ||||||||||||||||||
| 1441 | default: never executed: default: | 0 | ||||||||||||||||||
| 1442 | qWarning("QDateTimeParser::maxChange() Internal error (%s)", | - | ||||||||||||||||||
| 1443 | qPrintable(name())); | - | ||||||||||||||||||
| 1444 | } never executed: end of block | 0 | ||||||||||||||||||
| 1445 | - | |||||||||||||||||||
| 1446 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 1447 | } | - | ||||||||||||||||||
| 1448 | - | |||||||||||||||||||
| 1449 | QDateTimeParser::FieldInfo QDateTimeParser::fieldInfo(int index) const | - | ||||||||||||||||||
| 1450 | { | - | ||||||||||||||||||
| 1451 | FieldInfo ret = 0; | - | ||||||||||||||||||
| 1452 | const SectionNode &sn = sectionNode(index); | - | ||||||||||||||||||
| 1453 | switch (sn.type) { | - | ||||||||||||||||||
| 1454 | case MSecSection: executed 221 times by 2 tests: case MSecSection:Executed by:
| 221 | ||||||||||||||||||
| 1455 | ret |= Fraction; | - | ||||||||||||||||||
| 1456 | // fallthrough | - | ||||||||||||||||||
| 1457 | case SecondSection: code before this statement executed 221 times by 2 tests: case SecondSection:Executed by:
executed 1736 times by 4 tests: case SecondSection:Executed by:
| 221-1736 | ||||||||||||||||||
| 1458 | case MinuteSection: executed 1952 times by 8 tests: case MinuteSection:Executed by:
| 1952 | ||||||||||||||||||
| 1459 | case Hour24Section: executed 1299 times by 6 tests: case Hour24Section:Executed by:
| 1299 | ||||||||||||||||||
| 1460 | case Hour12Section: executed 831 times by 5 tests: case Hour12Section:Executed by:
| 831 | ||||||||||||||||||
| 1461 | case YearSection: executed 1932 times by 6 tests: case YearSection:Executed by:
| 1932 | ||||||||||||||||||
| 1462 | case YearSection2Digits: executed 883 times by 7 tests: case YearSection2Digits:Executed by:
| 883 | ||||||||||||||||||
| 1463 | ret |= Numeric; | - | ||||||||||||||||||
| 1464 | if (sn.type != YearSection) {
| 1932-6922 | ||||||||||||||||||
| 1465 | ret |= AllowPartial; | - | ||||||||||||||||||
| 1466 | } executed 6922 times by 10 tests: end of blockExecuted by:
| 6922 | ||||||||||||||||||
| 1467 | if (sn.count != 1) {
| 318-8536 | ||||||||||||||||||
| 1468 | ret |= FixedWidth; | - | ||||||||||||||||||
| 1469 | } executed 8536 times by 11 tests: end of blockExecuted by:
| 8536 | ||||||||||||||||||
| 1470 | break; executed 8854 times by 11 tests: break;Executed by:
| 8854 | ||||||||||||||||||
| 1471 | case MonthSection: executed 1786 times by 7 tests: case MonthSection:Executed by:
| 1786 | ||||||||||||||||||
| 1472 | case DaySection: executed 2715 times by 10 tests: case DaySection:Executed by:
| 2715 | ||||||||||||||||||
| 1473 | switch (sn.count) { | - | ||||||||||||||||||
| 1474 | case 2: executed 3511 times by 7 tests: case 2:Executed by:
| 3511 | ||||||||||||||||||
| 1475 | ret |= FixedWidth; | - | ||||||||||||||||||
| 1476 | // fallthrough | - | ||||||||||||||||||
| 1477 | case 1: code before this statement executed 3511 times by 7 tests: case 1:Executed by:
executed 970 times by 7 tests: case 1:Executed by:
| 970-3511 | ||||||||||||||||||
| 1478 | ret |= (Numeric|AllowPartial); | - | ||||||||||||||||||
| 1479 | break; executed 4481 times by 10 tests: break;Executed by:
| 4481 | ||||||||||||||||||
| 1480 | } | - | ||||||||||||||||||
| 1481 | break; executed 4501 times by 10 tests: break;Executed by:
| 4501 | ||||||||||||||||||
| 1482 | case DayOfWeekSectionShort: never executed: case DayOfWeekSectionShort: | 0 | ||||||||||||||||||
| 1483 | case DayOfWeekSectionLong: never executed: case DayOfWeekSectionLong: | 0 | ||||||||||||||||||
| 1484 | if (sn.count == 3)
| 0 | ||||||||||||||||||
| 1485 | ret |= FixedWidth; never executed: ret |= FixedWidth; | 0 | ||||||||||||||||||
| 1486 | break; never executed: break; | 0 | ||||||||||||||||||
| 1487 | case AmPmSection: never executed: case AmPmSection: | 0 | ||||||||||||||||||
| 1488 | ret |= FixedWidth; | - | ||||||||||||||||||
| 1489 | break; never executed: break; | 0 | ||||||||||||||||||
| 1490 | default: never executed: default: | 0 | ||||||||||||||||||
| 1491 | qWarning("QDateTimeParser::fieldInfo Internal error 2 (%d %s %d)", | - | ||||||||||||||||||
| 1492 | index, qPrintable(sn.name()), sn.count); | - | ||||||||||||||||||
| 1493 | break; never executed: break; | 0 | ||||||||||||||||||
| 1494 | } | - | ||||||||||||||||||
| 1495 | return ret; executed 13355 times by 11 tests: return ret;Executed by:
| 13355 | ||||||||||||||||||
| 1496 | } | - | ||||||||||||||||||
| 1497 | - | |||||||||||||||||||
| 1498 | QString QDateTimeParser::SectionNode::format() const | - | ||||||||||||||||||
| 1499 | { | - | ||||||||||||||||||
| 1500 | QChar fillChar; | - | ||||||||||||||||||
| 1501 | switch (type) { | - | ||||||||||||||||||
| 1502 | case AmPmSection: return count == 1 ? QLatin1String("AP") : QLatin1String("ap"); never executed: return count == 1 ? QLatin1String("AP") : QLatin1String("ap");
never executed: case AmPmSection: | 0 | ||||||||||||||||||
| 1503 | case MSecSection: fillChar = QLatin1Char('z'); break; never executed: break;never executed: case MSecSection: | 0 | ||||||||||||||||||
| 1504 | case SecondSection: fillChar = QLatin1Char('s'); break; never executed: break;never executed: case SecondSection: | 0 | ||||||||||||||||||
| 1505 | case MinuteSection: fillChar = QLatin1Char('m'); break; never executed: break;never executed: case MinuteSection: | 0 | ||||||||||||||||||
| 1506 | case Hour24Section: fillChar = QLatin1Char('H'); break; never executed: break;never executed: case Hour24Section: | 0 | ||||||||||||||||||
| 1507 | case Hour12Section: fillChar = QLatin1Char('h'); break; never executed: break;never executed: case Hour12Section: | 0 | ||||||||||||||||||
| 1508 | case DayOfWeekSectionShort: never executed: case DayOfWeekSectionShort: | 0 | ||||||||||||||||||
| 1509 | case DayOfWeekSectionLong: never executed: case DayOfWeekSectionLong: | 0 | ||||||||||||||||||
| 1510 | case DaySection: fillChar = QLatin1Char('d'); break; executed 2 times by 1 test: break;Executed by:
executed 2 times by 1 test: case DaySection:Executed by:
| 2 | ||||||||||||||||||
| 1511 | case MonthSection: fillChar = QLatin1Char('M'); break; executed 2 times by 1 test: break;Executed by:
executed 2 times by 1 test: case MonthSection:Executed by:
| 2 | ||||||||||||||||||
| 1512 | case YearSection2Digits: never executed: case YearSection2Digits: | 0 | ||||||||||||||||||
| 1513 | case YearSection: fillChar = QLatin1Char('y'); break; executed 2 times by 1 test: break;Executed by:
executed 2 times by 1 test: case YearSection:Executed by:
| 2 | ||||||||||||||||||
| 1514 | default: never executed: default: | 0 | ||||||||||||||||||
| 1515 | qWarning("QDateTimeParser::sectionFormat Internal error (%s)", | - | ||||||||||||||||||
| 1516 | qPrintable(name(type))); | - | ||||||||||||||||||
| 1517 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 1518 | } | - | ||||||||||||||||||
| 1519 | if (fillChar.isNull()) {
| 0-6 | ||||||||||||||||||
| 1520 | qWarning("QDateTimeParser::sectionFormat Internal error 2"); | - | ||||||||||||||||||
| 1521 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 1522 | } | - | ||||||||||||||||||
| 1523 | - | |||||||||||||||||||
| 1524 | QString str; | - | ||||||||||||||||||
| 1525 | str.fill(fillChar, count); | - | ||||||||||||||||||
| 1526 | return str; executed 6 times by 1 test: return str;Executed by:
| 6 | ||||||||||||||||||
| 1527 | } | - | ||||||||||||||||||
| 1528 | - | |||||||||||||||||||
| 1529 | - | |||||||||||||||||||
| 1530 | /*! | - | ||||||||||||||||||
| 1531 | \internal | - | ||||||||||||||||||
| 1532 | - | |||||||||||||||||||
| 1533 | Returns \c true if str can be modified to represent a | - | ||||||||||||||||||
| 1534 | number that is within min and max. | - | ||||||||||||||||||
| 1535 | */ | - | ||||||||||||||||||
| 1536 | - | |||||||||||||||||||
| 1537 | bool QDateTimeParser::potentialValue(const QString &str, int min, int max, int index, | - | ||||||||||||||||||
| 1538 | const QDateTime ¤tValue, int insert) const | - | ||||||||||||||||||
| 1539 | { | - | ||||||||||||||||||
| 1540 | if (str.isEmpty()) {
| 3-1610 | ||||||||||||||||||
| 1541 | return true; executed 3 times by 1 test: return true;Executed by:
| 3 | ||||||||||||||||||
| 1542 | } | - | ||||||||||||||||||
| 1543 | const int size = sectionMaxSize(index); | - | ||||||||||||||||||
| 1544 | int val = (int)locale().toUInt(str); | - | ||||||||||||||||||
| 1545 | const SectionNode &sn = sectionNode(index); | - | ||||||||||||||||||
| 1546 | if (sn.type == YearSection2Digits) {
| 20-1590 | ||||||||||||||||||
| 1547 | val += currentValue.date().year() - (currentValue.date().year() % 100); | - | ||||||||||||||||||
| 1548 | } executed 20 times by 2 tests: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 1549 | if (val >= min && val <= max && str.size() == size) {
| 201-1409 | ||||||||||||||||||
| 1550 | return true; executed 495 times by 4 tests: return true;Executed by:
| 495 | ||||||||||||||||||
| 1551 | } else if (val > max) {
| 410-705 | ||||||||||||||||||
| 1552 | return false; executed 410 times by 1 test: return false;Executed by:
| 410 | ||||||||||||||||||
| 1553 | } else if (str.size() == size && val < min) {
| 0-590 | ||||||||||||||||||
| 1554 | return false; executed 115 times by 1 test: return false;Executed by:
| 115 | ||||||||||||||||||
| 1555 | } | - | ||||||||||||||||||
| 1556 | - | |||||||||||||||||||
| 1557 | const int len = size - str.size(); | - | ||||||||||||||||||
| 1558 | for (int i=0; i<len; ++i) {
| 45-590 | ||||||||||||||||||
| 1559 | for (int j=0; j<10; ++j) {
| 45-1061 | ||||||||||||||||||
| 1560 | if (potentialValue(str + QLatin1Char('0' + j), min, max, index, currentValue, insert)) {
| 519-542 | ||||||||||||||||||
| 1561 | return true; executed 542 times by 4 tests: return true;Executed by:
| 542 | ||||||||||||||||||
| 1562 | } else if (insert >= 0) {
| 9-510 | ||||||||||||||||||
| 1563 | QString tmp = str; | - | ||||||||||||||||||
| 1564 | tmp.insert(insert, QLatin1Char('0' + j)); | - | ||||||||||||||||||
| 1565 | if (potentialValue(tmp, min, max, index, currentValue, insert))
| 3-6 | ||||||||||||||||||
| 1566 | return true; executed 3 times by 1 test: return true;Executed by:
| 3 | ||||||||||||||||||
| 1567 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 1568 | } executed 516 times by 1 test: end of blockExecuted by:
| 516 | ||||||||||||||||||
| 1569 | } executed 45 times by 1 test: end of blockExecuted by:
| 45 | ||||||||||||||||||
| 1570 | - | |||||||||||||||||||
| 1571 | return false; executed 45 times by 1 test: return false;Executed by:
| 45 | ||||||||||||||||||
| 1572 | } | - | ||||||||||||||||||
| 1573 | - | |||||||||||||||||||
| 1574 | bool QDateTimeParser::skipToNextSection(int index, const QDateTime ¤t, const QString &text) const | - | ||||||||||||||||||
| 1575 | { | - | ||||||||||||||||||
| 1576 | Q_ASSERT(current >= getMinimum() && current <= getMaximum()); | - | ||||||||||||||||||
| 1577 | - | |||||||||||||||||||
| 1578 | const SectionNode &node = sectionNode(index); | - | ||||||||||||||||||
| 1579 | Q_ASSERT(text.size() < sectionMaxSize(index)); | - | ||||||||||||||||||
| 1580 | - | |||||||||||||||||||
| 1581 | const QDateTime maximum = getMaximum(); | - | ||||||||||||||||||
| 1582 | const QDateTime minimum = getMinimum(); | - | ||||||||||||||||||
| 1583 | QDateTime tmp = current; | - | ||||||||||||||||||
| 1584 | int min = absoluteMin(index); | - | ||||||||||||||||||
| 1585 | setDigit(tmp, index, min); | - | ||||||||||||||||||
| 1586 | if (tmp < minimum) {
| 17-474 | ||||||||||||||||||
| 1587 | min = getDigit(minimum, index); | - | ||||||||||||||||||
| 1588 | } executed 17 times by 1 test: end of blockExecuted by:
| 17 | ||||||||||||||||||
| 1589 | - | |||||||||||||||||||
| 1590 | int max = absoluteMax(index, current); | - | ||||||||||||||||||
| 1591 | setDigit(tmp, index, max); | - | ||||||||||||||||||
| 1592 | if (tmp > maximum) {
| 33-458 | ||||||||||||||||||
| 1593 | max = getDigit(maximum, index); | - | ||||||||||||||||||
| 1594 | } executed 33 times by 2 tests: end of blockExecuted by:
| 33 | ||||||||||||||||||
| 1595 | int pos = cursorPosition() - node.pos; | - | ||||||||||||||||||
| 1596 | if (pos < 0 || pos >= text.size())
| 7-479 | ||||||||||||||||||
| 1597 | pos = -1; executed 484 times by 4 tests: pos = -1;Executed by:
| 484 | ||||||||||||||||||
| 1598 | - | |||||||||||||||||||
| 1599 | const bool potential = potentialValue(text, min, max, index, current, pos); | - | ||||||||||||||||||
| 1600 | return !potential; executed 491 times by 4 tests: return !potential;Executed by:
| 491 | ||||||||||||||||||
| 1601 | - | |||||||||||||||||||
| 1602 | /* If the value potentially can become another valid entry we | - | ||||||||||||||||||
| 1603 | * don't want to skip to the next. E.g. In a M field (month | - | ||||||||||||||||||
| 1604 | * without leading 0 if you type 1 we don't want to autoskip but | - | ||||||||||||||||||
| 1605 | * if you type 3 we do | - | ||||||||||||||||||
| 1606 | */ | - | ||||||||||||||||||
| 1607 | } | - | ||||||||||||||||||
| 1608 | - | |||||||||||||||||||
| 1609 | /*! | - | ||||||||||||||||||
| 1610 | \internal | - | ||||||||||||||||||
| 1611 | For debugging. Returns the name of the section \a s. | - | ||||||||||||||||||
| 1612 | */ | - | ||||||||||||||||||
| 1613 | - | |||||||||||||||||||
| 1614 | QString QDateTimeParser::SectionNode::name(QDateTimeParser::Section s) | - | ||||||||||||||||||
| 1615 | { | - | ||||||||||||||||||
| 1616 | switch (s) { | - | ||||||||||||||||||
| 1617 | case QDateTimeParser::AmPmSection: return QLatin1String("AmPmSection"); never executed: return QLatin1String("AmPmSection");never executed: case QDateTimeParser::AmPmSection: | 0 | ||||||||||||||||||
| 1618 | case QDateTimeParser::DaySection: return QLatin1String("DaySection"); never executed: return QLatin1String("DaySection");never executed: case QDateTimeParser::DaySection: | 0 | ||||||||||||||||||
| 1619 | case QDateTimeParser::DayOfWeekSectionShort: return QLatin1String("DayOfWeekSectionShort"); never executed: return QLatin1String("DayOfWeekSectionShort");never executed: case QDateTimeParser::DayOfWeekSectionShort: | 0 | ||||||||||||||||||
| 1620 | case QDateTimeParser::DayOfWeekSectionLong: return QLatin1String("DayOfWeekSectionLong"); never executed: return QLatin1String("DayOfWeekSectionLong");never executed: case QDateTimeParser::DayOfWeekSectionLong: | 0 | ||||||||||||||||||
| 1621 | case QDateTimeParser::Hour24Section: return QLatin1String("Hour24Section"); never executed: return QLatin1String("Hour24Section");never executed: case QDateTimeParser::Hour24Section: | 0 | ||||||||||||||||||
| 1622 | case QDateTimeParser::Hour12Section: return QLatin1String("Hour12Section"); never executed: return QLatin1String("Hour12Section");never executed: case QDateTimeParser::Hour12Section: | 0 | ||||||||||||||||||
| 1623 | case QDateTimeParser::MSecSection: return QLatin1String("MSecSection"); never executed: return QLatin1String("MSecSection");never executed: case QDateTimeParser::MSecSection: | 0 | ||||||||||||||||||
| 1624 | case QDateTimeParser::MinuteSection: return QLatin1String("MinuteSection"); never executed: return QLatin1String("MinuteSection");never executed: case QDateTimeParser::MinuteSection: | 0 | ||||||||||||||||||
| 1625 | case QDateTimeParser::MonthSection: return QLatin1String("MonthSection"); never executed: return QLatin1String("MonthSection");never executed: case QDateTimeParser::MonthSection: | 0 | ||||||||||||||||||
| 1626 | case QDateTimeParser::SecondSection: return QLatin1String("SecondSection"); never executed: return QLatin1String("SecondSection");never executed: case QDateTimeParser::SecondSection: | 0 | ||||||||||||||||||
| 1627 | case QDateTimeParser::YearSection: return QLatin1String("YearSection"); never executed: return QLatin1String("YearSection");never executed: case QDateTimeParser::YearSection: | 0 | ||||||||||||||||||
| 1628 | case QDateTimeParser::YearSection2Digits: return QLatin1String("YearSection2Digits"); never executed: return QLatin1String("YearSection2Digits");never executed: case QDateTimeParser::YearSection2Digits: | 0 | ||||||||||||||||||
| 1629 | case QDateTimeParser::NoSection: return QLatin1String("NoSection"); never executed: return QLatin1String("NoSection");never executed: case QDateTimeParser::NoSection: | 0 | ||||||||||||||||||
| 1630 | case QDateTimeParser::FirstSection: return QLatin1String("FirstSection"); never executed: return QLatin1String("FirstSection");never executed: case QDateTimeParser::FirstSection: | 0 | ||||||||||||||||||
| 1631 | case QDateTimeParser::LastSection: return QLatin1String("LastSection"); never executed: return QLatin1String("LastSection");never executed: case QDateTimeParser::LastSection: | 0 | ||||||||||||||||||
| 1632 | default: return QLatin1String("Unknown section ") + QString::number(int(s)); never executed: return QLatin1String("Unknown section ") + QString::number(int(s));never executed: default: | 0 | ||||||||||||||||||
| 1633 | } | - | ||||||||||||||||||
| 1634 | } | - | ||||||||||||||||||
| 1635 | - | |||||||||||||||||||
| 1636 | /*! | - | ||||||||||||||||||
| 1637 | \internal | - | ||||||||||||||||||
| 1638 | For debugging. Returns the name of the state \a s. | - | ||||||||||||||||||
| 1639 | */ | - | ||||||||||||||||||
| 1640 | - | |||||||||||||||||||
| 1641 | QString QDateTimeParser::stateName(State s) const | - | ||||||||||||||||||
| 1642 | { | - | ||||||||||||||||||
| 1643 | switch (s) { | - | ||||||||||||||||||
| 1644 | case Invalid: return QLatin1String("Invalid"); never executed: return QLatin1String("Invalid");never executed: case Invalid: | 0 | ||||||||||||||||||
| 1645 | case Intermediate: return QLatin1String("Intermediate"); never executed: return QLatin1String("Intermediate");never executed: case Intermediate: | 0 | ||||||||||||||||||
| 1646 | case Acceptable: return QLatin1String("Acceptable"); never executed: return QLatin1String("Acceptable");never executed: case Acceptable: | 0 | ||||||||||||||||||
| 1647 | default: return QLatin1String("Unknown state ") + QString::number(s); never executed: return QLatin1String("Unknown state ") + QString::number(s);never executed: default: | 0 | ||||||||||||||||||
| 1648 | } | - | ||||||||||||||||||
| 1649 | } | - | ||||||||||||||||||
| 1650 | - | |||||||||||||||||||
| 1651 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||
| 1652 | bool QDateTimeParser::fromString(const QString &t, QDate *date, QTime *time) const | - | ||||||||||||||||||
| 1653 | { | - | ||||||||||||||||||
| 1654 | QDateTime val(QDate(1900, 1, 1), QDATETIMEEDIT_TIME_MIN); | - | ||||||||||||||||||
| 1655 | QString text = t; | - | ||||||||||||||||||
| 1656 | int copy = -1; | - | ||||||||||||||||||
| 1657 | const StateNode tmp = parse(text, copy, val, false); | - | ||||||||||||||||||
| 1658 | if (tmp.state != Acceptable || tmp.conflicts) {
| 5-495 | ||||||||||||||||||
| 1659 | return false; executed 148 times by 4 tests: return false;Executed by:
| 148 | ||||||||||||||||||
| 1660 | } | - | ||||||||||||||||||
| 1661 | if (time) {
| 36-454 | ||||||||||||||||||
| 1662 | const QTime t = tmp.value.time(); | - | ||||||||||||||||||
| 1663 | if (!t.isValid()) {
| 0-454 | ||||||||||||||||||
| 1664 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1665 | } | - | ||||||||||||||||||
| 1666 | *time = t; | - | ||||||||||||||||||
| 1667 | } executed 454 times by 7 tests: end of blockExecuted by:
| 454 | ||||||||||||||||||
| 1668 | - | |||||||||||||||||||
| 1669 | if (date) {
| 6-484 | ||||||||||||||||||
| 1670 | const QDate d = tmp.value.date(); | - | ||||||||||||||||||
| 1671 | if (!d.isValid()) {
| 0-484 | ||||||||||||||||||
| 1672 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1673 | } | - | ||||||||||||||||||
| 1674 | *date = d; | - | ||||||||||||||||||
| 1675 | } executed 484 times by 7 tests: end of blockExecuted by:
| 484 | ||||||||||||||||||
| 1676 | return true; executed 490 times by 8 tests: return true;Executed by:
| 490 | ||||||||||||||||||
| 1677 | } | - | ||||||||||||||||||
| 1678 | #endif // QT_NO_DATESTRING | - | ||||||||||||||||||
| 1679 | - | |||||||||||||||||||
| 1680 | QDateTime QDateTimeParser::getMinimum() const | - | ||||||||||||||||||
| 1681 | { | - | ||||||||||||||||||
| 1682 | return QDateTime(QDATETIMEEDIT_DATE_MIN, QDATETIMEEDIT_TIME_MIN, spec); executed 1175 times by 8 tests: return QDateTime(QDate(100, 1, 1), QTime(0, 0, 0, 0), spec);Executed by:
| 1175 | ||||||||||||||||||
| 1683 | } | - | ||||||||||||||||||
| 1684 | - | |||||||||||||||||||
| 1685 | QDateTime QDateTimeParser::getMaximum() const | - | ||||||||||||||||||
| 1686 | { | - | ||||||||||||||||||
| 1687 | return QDateTime(QDATETIMEEDIT_DATE_MAX, QDATETIMEEDIT_TIME_MAX, spec); executed 1139 times by 8 tests: return QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999), spec);Executed by:
| 1139 | ||||||||||||||||||
| 1688 | } | - | ||||||||||||||||||
| 1689 | - | |||||||||||||||||||
| 1690 | QString QDateTimeParser::getAmPmText(AmPm ap, Case cs) const | - | ||||||||||||||||||
| 1691 | { | - | ||||||||||||||||||
| 1692 | const QLocale loc = locale(); | - | ||||||||||||||||||
| 1693 | QString raw = ap == AmText ? loc.amText() : loc.pmText();
| 60 | ||||||||||||||||||
| 1694 | return cs == UpperCase ? raw.toUpper() : raw.toLower(); executed 120 times by 2 tests: return cs == UpperCase ? raw.toUpper() : raw.toLower();Executed by:
| 56-120 | ||||||||||||||||||
| 1695 | } | - | ||||||||||||||||||
| 1696 | - | |||||||||||||||||||
| 1697 | /* | - | ||||||||||||||||||
| 1698 | \internal | - | ||||||||||||||||||
| 1699 | - | |||||||||||||||||||
| 1700 | I give arg2 preference because arg1 is always a QDateTime. | - | ||||||||||||||||||
| 1701 | */ | - | ||||||||||||||||||
| 1702 | - | |||||||||||||||||||
| 1703 | bool operator==(const QDateTimeParser::SectionNode &s1, const QDateTimeParser::SectionNode &s2) | - | ||||||||||||||||||
| 1704 | { | - | ||||||||||||||||||
| 1705 | return (s1.type == s2.type) && (s1.pos == s2.pos) && (s1.count == s2.count); never executed: return (s1.type == s2.type) && (s1.pos == s2.pos) && (s1.count == s2.count);
| 0 | ||||||||||||||||||
| 1706 | } | - | ||||||||||||||||||
| 1707 | - | |||||||||||||||||||
| 1708 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 1709 | - | |||||||||||||||||||
| 1710 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |