diff --git a/src/blackgui/stylesheetutility.cpp b/src/blackgui/stylesheetutility.cpp index fb0368800..0dcf0543d 100644 --- a/src/blackgui/stylesheetutility.cpp +++ b/src/blackgui/stylesheetutility.cpp @@ -151,7 +151,7 @@ namespace BlackGui { if (needsWatcher) { m_fileWatcher.addPath(absolutePath); } QTextStream in(&file); - const QString c = in.readAll(); + const QString c = removeComments(in.readAll(), true, true); const QString f = fileInfo.fileName().toLower(); // keep even empty files as placeholders diff --git a/src/blackmisc/stringutils.cpp b/src/blackmisc/stringutils.cpp index e735aa6e6..efc8de61a 100644 --- a/src/blackmisc/stringutils.cpp +++ b/src/blackmisc/stringutils.cpp @@ -433,6 +433,19 @@ namespace BlackMisc return in; } + QString removeComments(const QString &in, bool removeSlashStar, bool removeDoubleSlash) + { + QString copy(in); + + thread_local const QRegularExpression re1("\\/\\*(.|\\n)*?\\*\\/"); + if (removeSlashStar) { copy.remove(re1); } + + thread_local const QRegularExpression re2("\\/\\/.*"); + if (removeDoubleSlash) { copy.remove(re2); } + + return copy; + } + } // ns //! \endcond diff --git a/src/blackmisc/stringutils.h b/src/blackmisc/stringutils.h index 8efab6d8b..fb7ae3c60 100644 --- a/src/blackmisc/stringutils.h +++ b/src/blackmisc/stringutils.h @@ -289,6 +289,9 @@ namespace BlackMisc //! Convert string to bool BLACKMISC_EXPORT QString joinStringSet(const QSet &set, const QString &separator); + //! Remove comments such as /** **/ or // + BLACKMISC_EXPORT QString removeComments(const QString &in, bool removeSlash, bool removeDoubleSlash); + namespace Mixin { /*!