Added helper function for parsing regular expressions.

This commit is contained in:
LoRd_MuldeR 2014-12-25 00:49:29 +01:00
parent 9a5a81e031
commit d35ed2eb1b
2 changed files with 36 additions and 0 deletions

View File

@ -95,6 +95,11 @@ namespace MUtils
MUTILS_API QString clean_file_name(const QString &name);
MUTILS_API QString clean_file_path(const QString &path);
//Regular expressions
MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value);
MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &count);
//Internationalization
MUTILS_API QStringList available_codepages(const bool &noAliases = true);
//Internal

View File

@ -394,6 +394,37 @@ QString MUtils::clean_file_path(const QString &path)
return parts.join("/");
}
///////////////////////////////////////////////////////////////////////////////
// REGULAR EXPESSION HELPER
///////////////////////////////////////////////////////////////////////////////
bool MUtils::regexp_parse_uint32(const QRegExp &regexp, quint32 &value)
{
return regexp_parse_uint32(regexp, &value, 1);
}
bool MUtils::regexp_parse_uint32(const QRegExp &regexp, quint32 *values, 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[i+1].toUInt(&ok);
if(!ok)
{
return false;
}
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
// AVAILABLE CODEPAGES
///////////////////////////////////////////////////////////////////////////////