diff --git a/include/MUtils/Global.h b/include/MUtils/Global.h index 91cf945..bcf660f 100644 --- a/include/MUtils/Global.h +++ b/include/MUtils/Global.h @@ -296,6 +296,9 @@ namespace MUtils * \return The function returns `true`, if the regular expression's capture could be parsed successfully; it returns `false`, if the capture contains an invalid string or if there are insufficient captures in given the [QRegExp](http://doc.qt.io/qt-4.8/qregexp.html) object. */ MUTILS_API bool regexp_parse_uint32(const QRegExp ®exp, quint32 &value); + MUTILS_API bool regexp_parse_int32(const QRegExp ®exp, qint32 &value); + MUTILS_API bool regexp_parse_uint32(const QRegExp ®exp, quint32 &value, const size_t &offset); + MUTILS_API bool regexp_parse_int32(const QRegExp ®exp, qint32 &value, const size_t &offset); /** * \brief Parse regular expression results @@ -311,6 +314,9 @@ namespace MUtils * \return The function returns `true`, if all of the regular expression's captures could be parsed successfully; it returns `false`, if any of the captures contain an invalid string or if there are insufficient captures in given the [QRegExp](http://doc.qt.io/qt-4.8/qregexp.html) object. */ MUTILS_API bool regexp_parse_uint32(const QRegExp ®exp, quint32 *values, const size_t &count); + MUTILS_API bool regexp_parse_int32(const QRegExp ®exp, qint32 *values, const size_t &count); + MUTILS_API bool regexp_parse_uint32(const QRegExp ®exp, quint32 *values, const size_t &offset, const size_t &count); + MUTILS_API bool regexp_parse_int32(const QRegExp ®exp, qint32 *values, const size_t &offset, const size_t &count); /** * \brief Retrieve a list of all available codepages @@ -369,6 +375,10 @@ namespace MUtils */ #define MUTILS_BOOLIFY(X) (!(!(X))) +/** \brief Get length of an array, only works with local array variables! +*/ +#define MUTILS_ARR2LEN(X) (sizeof((X)) / sizeof((X)[0])) + /** \brief Disables copy constructor and assignment operator in the specified class. This macro should be used in the "private" section of the class' declaration. */ #define MUTILS_NO_COPY(CLASS) \ diff --git a/src/Global.cpp b/src/Global.cpp index b10ed68..2cf9423 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -697,23 +697,70 @@ QString MUtils::clean_file_path(const QString &path, const bool &pretty) bool MUtils::regexp_parse_uint32(const QRegExp ®exp, quint32 &value) { - return regexp_parse_uint32(regexp, &value, 1); + return regexp_parse_uint32(regexp, &value, 1U, 1U); +} + +bool MUtils::regexp_parse_int32(const QRegExp ®exp, qint32 &value) +{ + return regexp_parse_int32(regexp, &value, 1U, 1U); +} + +bool MUtils::regexp_parse_uint32(const QRegExp ®exp, quint32 &value, const size_t &offset) +{ + return regexp_parse_uint32(regexp, &value, offset, 1U); +} + +bool MUtils::regexp_parse_int32(const QRegExp ®exp, qint32 &value, const size_t &offset) +{ + return regexp_parse_int32(regexp, &value, offset, 1U); } bool MUtils::regexp_parse_uint32(const QRegExp ®exp, quint32 *values, const size_t &count) +{ + return regexp_parse_uint32(regexp, values, 1U, count); +} + +bool MUtils::regexp_parse_int32(const QRegExp ®exp, qint32 *values, const size_t &count) +{ + return regexp_parse_int32(regexp, values, 1U, count); +} + +bool MUtils::regexp_parse_uint32(const QRegExp ®exp, quint32 *values, const size_t &offset, const size_t &count) { const QStringList caps = regexp.capturedTexts(); - - if(caps.isEmpty() || (quint32(caps.count()) <= count)) + + if (caps.isEmpty() || (quint32(caps.count()) <= count)) { return false; } - for(size_t i = 0; i < count; i++) + for (size_t i = 0; i < count; i++) { bool ok = false; - values[i] = caps[i+1].toUInt(&ok); - if(!ok) + values[i] = caps[offset+i].toUInt(&ok); + if (!ok) + { + return false; + } + } + + return true; +} + +bool MUtils::regexp_parse_int32(const QRegExp ®exp, qint32 *values, const size_t &offset, const size_t &count) +{ + const QStringList caps = regexp.capturedTexts(); + + if (caps.isEmpty() || (quint32(caps.count()) <= count)) + { + return false; + } + + for (size_t i = 0; i < count; i++) + { + bool ok = false; + values[i] = caps[offset+i].toInt(&ok); + if (!ok) { return false; }