String utility function for balanced quotes

This commit is contained in:
Klaus Basan
2020-01-30 12:57:32 +01:00
committed by Mat Sutcliffe
parent 09a3447047
commit 1238357749
2 changed files with 11 additions and 1 deletions

View File

@@ -484,6 +484,13 @@ namespace BlackMisc
return false;
}
bool hasBalancedQuotes(const QString &in, char quote)
{
if (in.isEmpty()) { return true; }
const int c = in.count(quote);
return (c % 2) == 0;
}
} // ns
//! \endcond

View File

@@ -208,6 +208,9 @@ namespace BlackMisc
//! Return string in quotes
BLACKMISC_EXPORT QString inQuotes(const QString &in, bool ignoreEmpty = false);
//! Has balanced quotes
BLACKMISC_EXPORT bool hasBalancedQuotes(const QString &in, char quote = '"');
//! Remove surrounding apostrophes 'foo' -> foo
BLACKMISC_EXPORT QString removeSurroundingApostrophes(const QString &in);
@@ -328,7 +331,7 @@ namespace BlackMisc
//! Operator << when there is no debug stream
friend QNoDebug operator<<(QNoDebug nodebug, const Derived &obj)
{
Q_UNUSED(obj);
Q_UNUSED(obj)
return nodebug;
}