diff --git a/src/blackmisc/stringutils.cpp b/src/blackmisc/stringutils.cpp index f6028b4b6..33a490231 100644 --- a/src/blackmisc/stringutils.cpp +++ b/src/blackmisc/stringutils.cpp @@ -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 diff --git a/src/blackmisc/stringutils.h b/src/blackmisc/stringutils.h index c82847662..a5e44e419 100644 --- a/src/blackmisc/stringutils.h +++ b/src/blackmisc/stringutils.h @@ -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; }