Added regexp_parse_int32() functions and new regexp_parse_uint32() overloads.

This commit is contained in:
LoRd_MuldeR 2017-12-11 01:06:28 +01:00
parent 8adbc8a212
commit 96eaf7ddcc
2 changed files with 63 additions and 6 deletions

View File

@ -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. * \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 &regexp, quint32 &value); MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value);
MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 &value);
MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value, const size_t &offset);
MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 &value, const size_t &offset);
/** /**
* \brief Parse regular expression results * \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. * \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 &regexp, quint32 *values, const size_t &count); MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &count);
MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 *values, const size_t &count);
MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &offset, const size_t &count);
MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 *values, const size_t &offset, const size_t &count);
/** /**
* \brief Retrieve a list of all available codepages * \brief Retrieve a list of all available codepages
@ -369,6 +375,10 @@ namespace MUtils
*/ */
#define MUTILS_BOOLIFY(X) (!(!(X))) #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. /** \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) \ #define MUTILS_NO_COPY(CLASS) \

View File

@ -697,23 +697,70 @@ QString MUtils::clean_file_path(const QString &path, const bool &pretty)
bool MUtils::regexp_parse_uint32(const QRegExp &regexp, quint32 &value) bool MUtils::regexp_parse_uint32(const QRegExp &regexp, quint32 &value)
{ {
return regexp_parse_uint32(regexp, &value, 1); return regexp_parse_uint32(regexp, &value, 1U, 1U);
}
bool MUtils::regexp_parse_int32(const QRegExp &regexp, qint32 &value)
{
return regexp_parse_int32(regexp, &value, 1U, 1U);
}
bool MUtils::regexp_parse_uint32(const QRegExp &regexp, quint32 &value, const size_t &offset)
{
return regexp_parse_uint32(regexp, &value, offset, 1U);
}
bool MUtils::regexp_parse_int32(const QRegExp &regexp, qint32 &value, const size_t &offset)
{
return regexp_parse_int32(regexp, &value, offset, 1U);
} }
bool MUtils::regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &count) bool MUtils::regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &count)
{
return regexp_parse_uint32(regexp, values, 1U, count);
}
bool MUtils::regexp_parse_int32(const QRegExp &regexp, qint32 *values, const size_t &count)
{
return regexp_parse_int32(regexp, values, 1U, count);
}
bool MUtils::regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &offset, const size_t &count)
{ {
const QStringList caps = regexp.capturedTexts(); const QStringList caps = regexp.capturedTexts();
if(caps.isEmpty() || (quint32(caps.count()) <= count)) if (caps.isEmpty() || (quint32(caps.count()) <= count))
{ {
return false; return false;
} }
for(size_t i = 0; i < count; i++) for (size_t i = 0; i < count; i++)
{ {
bool ok = false; bool ok = false;
values[i] = caps[i+1].toUInt(&ok); values[i] = caps[offset+i].toUInt(&ok);
if(!ok) if (!ok)
{
return false;
}
}
return true;
}
bool MUtils::regexp_parse_int32(const QRegExp &regexp, 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; return false;
} }