/*! \fn QVersionNumber QVersionNumber::fromString(const QString &string, int *suffixIndex) Constructs a QVersionNumber from a specially formatted \a string of non-negative decimal numbers delimited by '.'. Once the numerical segments have been parsed, the remainder of the string is considered to be the suffix string. The start index of that string will be stored in \a suffixIndex if it is not null. \snippet qversionnumber/main.cpp 3 \sa isNull() */ QVersionNumber QVersionNumber::fromString(const QString &string, int *suffixIndex) { QVector<int> seg; const QByteArray cString(string.toLatin1()); const char *start = cString.constData(); const char *end = start; const char *lastGoodEnd = start; const char *endOfString = cString.constData() + cString.size(); do { bool ok = false; const qulonglong value = qstrtoull(start, &end, 10, &ok); if (!ok || value > qulonglong(std::numeric_limits<int>::max())) break; seg.append(int(value)); start = end + 1; lastGoodEnd = end; } while (start < endOfString && (end < endOfString && *end == '.')); if (suffixIndex) *suffixIndex = int(lastGoodEnd - cString.constData()); return QVersionNumber(qMove(seg)); }
static bool parseIp4Internal(IPv4Address &address, const char *ptr, bool acceptLeadingZero) { address = 0; int dotCount = 0; while (dotCount < 4) { if (!acceptLeadingZero && *ptr == '0' && ptr[1] != '.' && ptr[1] != '\0') return false; const char *endptr; bool ok; quint64 ll = qstrtoull(ptr, &endptr, 0, &ok); quint32 x = ll; if (!ok || endptr == ptr || ll != x) return false; if (*endptr == '.' || dotCount == 3) { if (x & ~0xff) return false; address <<= 8; } else if (dotCount == 2) { if (x & ~0xffff) return false; address <<= 16; } else if (dotCount == 1) { if (x & ~0xffffff) return false; address <<= 24; } address |= x; if (dotCount == 3 && *endptr != '\0') return false; else if (dotCount == 3 || *endptr == '\0') return true; if (*endptr != '.') return false; ++dotCount; ptr = endptr + 1; } return false; }
static QString winIso639LangName(LCID id) { QString result; // Windows returns the wrong ISO639 for some languages, we need to detect them here using // the language code QString lang_code; wchar_t out[256]; if (GetLocaleInfo(id, LOCALE_ILANGUAGE, out, 255)) // ### shouldn't use them according to msdn lang_code = QString::fromWCharArray(out); if (!lang_code.isEmpty()) { const char *endptr; bool ok; QByteArray latin1_lang_code = lang_code.toLatin1(); int i = qstrtoull(latin1_lang_code, &endptr, 16, &ok); if (ok && *endptr == '\0') { switch (i) { case 0x814: result = QLatin1String("nn"); // Nynorsk break; default: break; } } } if (!result.isEmpty()) return result; // not one of the problematic languages - do the usual lookup if (GetLocaleInfo(id, LOCALE_SISO639LANGNAME , out, 255)) result = QString::fromWCharArray(out); return result; }