summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qdatetime.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qdatetime.cpp')
-rw-r--r--src/corelib/tools/qdatetime.cpp56
1 files changed, 21 insertions, 35 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index aa37f8c9da..2b006fe2d5 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -159,7 +159,7 @@ static const char qt_shortMonthNames[][4] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
-int qt_monthNumberFromShortName(const QString &shortName)
+static int qt_monthNumberFromShortName(QStringRef shortName)
{
for (unsigned int i = 0; i < sizeof(qt_shortMonthNames) / sizeof(qt_shortMonthNames[0]); ++i) {
if (shortName == QLatin1String(qt_shortMonthNames[i], 3))
@@ -167,7 +167,23 @@ int qt_monthNumberFromShortName(const QString &shortName)
}
return -1;
}
-#endif
+int qt_monthNumberFromShortName(const QString &shortName)
+{ return qt_monthNumberFromShortName(QStringRef(&shortName)); }
+
+static int fromShortMonthName(const QStringRef &monthName)
+{
+ // Assume that English monthnames are the default
+ int month = qt_monthNumberFromShortName(monthName);
+ if (month != -1)
+ return month;
+ // If English names can't be found, search the localized ones
+ for (int i = 1; i <= 12; ++i) {
+ if (monthName == QDate::shortMonthName(i))
+ return i;
+ }
+ return -1;
+}
+#endif // QT_NO_TEXTDATE
#ifndef QT_NO_DATESTRING
static void rfcDateImpl(const QString &s, QDate *dd = 0, QTime *dt = 0, int *utcOffset = 0)
@@ -1253,25 +1269,10 @@ QDate QDate::fromString(const QString& string, Qt::DateFormat format)
return QDate();
QStringRef monthName = parts.at(1);
- int month = -1;
- // Assume that English monthnames are the default
- for (int i = 0; i < 12; ++i) {
- if (monthName == QLatin1String(qt_shortMonthNames[i])) {
- month = i + 1;
- break;
- }
- }
- // If English names can't be found, search the localized ones
+ const int month = fromShortMonthName(monthName);
if (month == -1) {
- for (int i = 1; i <= 12; ++i) {
- if (monthName == QDate::shortMonthName(i)) {
- month = i;
- break;
- }
- }
- if (month == -1)
- // Month name matches neither English nor other localised name.
- return QDate();
+ // Month name matches neither English nor other localised name.
+ return QDate();
}
bool ok = false;
@@ -4389,21 +4390,6 @@ int QDateTime::utcOffset() const
#ifndef QT_NO_DATESTRING
-static int fromShortMonthName(const QStringRef &monthName)
-{
- // Assume that English monthnames are the default
- for (int i = 0; i < 12; ++i) {
- if (monthName == QLatin1String(qt_shortMonthNames[i]))
- return i + 1;
- }
- // If English names can't be found, search the localized ones
- for (int i = 1; i <= 12; ++i) {
- if (monthName == QDate::shortMonthName(i))
- return i;
- }
- return -1;
-}
-
/*!
\fn QDateTime QDateTime::fromString(const QString &string, Qt::DateFormat format)