diff options
author | Dimitri van Heesch <dimitri@stack.nl> | 2018-08-19 14:10:55 (GMT) |
---|---|---|
committer | Dimitri van Heesch <dimitri@stack.nl> | 2018-08-19 14:10:55 (GMT) |
commit | 0b4b3698b29436b299d4e4a315d610bc1ab98acb (patch) | |
tree | 1babc69fbeab1211926ed7462a9db6ec50809d89 /qtools | |
parent | 9ba8bd85999fa7423eb5b44c680e72ad2e9c31bf (diff) | |
download | Doxygen-0b4b3698b29436b299d4e4a315d610bc1ab98acb.zip Doxygen-0b4b3698b29436b299d4e4a315d610bc1ab98acb.tar.gz Doxygen-0b4b3698b29436b299d4e4a315d610bc1ab98acb.tar.bz2 |
Bug 691689 - Line numbers for examples
Diffstat (limited to 'qtools')
-rw-r--r-- | qtools/CMakeLists.txt | 1 | ||||
-rw-r--r-- | qtools/qcstringlist.cpp | 192 | ||||
-rw-r--r-- | qtools/qcstringlist.h | 47 |
3 files changed, 240 insertions, 0 deletions
diff --git a/qtools/CMakeLists.txt b/qtools/CMakeLists.txt index 17f8eb4..cc64de1 100644 --- a/qtools/CMakeLists.txt +++ b/qtools/CMakeLists.txt @@ -22,6 +22,7 @@ qstring.cpp qtextstream.cpp qtextcodec.cpp qstringlist.cpp +qcstringlist.cpp qxml.cpp qmap.cpp qthread.cpp diff --git a/qtools/qcstringlist.cpp b/qtools/qcstringlist.cpp new file mode 100644 index 0000000..5725971 --- /dev/null +++ b/qtools/qcstringlist.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 1997-2018 by Dimitri van Heesch. +** +** Permission to use, copy, modify, and distribute this software and its +** documentation under the terms of the GNU General Public License is hereby +** granted. No representations are made about the suitability of this software +** for any purpose. It is provided "as is" without express or implied warranty. +** See the GNU General Public License for more details. +** +** Implementation of QCStringList +** +**********************************************************************/ + +#include "qcstringlist.h" + +#include "qstrlist.h" +#include "qdatastream.h" +#include "qtl.h" + +/*! + Splits the string \a str using \a sep as separator. Returns the + list of strings. If \a allowEmptyEntries is TRUE, also empty + entries are inserted into the list, else not. So if you have + a string 'abc..d.e.', a list which contains 'abc', 'd', and 'e' + would be returned if \a allowEmptyEntries is FALSE, but + a list containing 'abc', '', 'd', 'e' and '' would be returned if + \a allowEmptyEntries is TRUE. + If \a str doesn't contain \a sep, a stringlist + with one item, which is the same as \a str, is returned. + + \sa join() +*/ + +QCStringList QCStringList::split( char sep, const QCString &str, bool allowEmptyEntries ) +{ + char cs[2] = { sep, '\0' }; + return split( cs, str, allowEmptyEntries ); +} + +/*! + Splits the string \a str using \a sep as separator. Returns the + list of strings. If \a allowEmptyEntries is TRUE, also empty + entries are inserted into the list, else not. So if you have + a string 'abc..d.e.', a list which contains 'abc', 'd', and 'e' + would be returned if \a allowEmptyEntries is FALSE, but + a list containing 'abc', '', 'd', 'e' and '' would be returned if + \a allowEmptyEntries is TRUE. + If \a str doesn't contain \a sep, a stringlist + with one item, which is the same as \a str, is returned. + + \sa join() +*/ + +QCStringList QCStringList::split( const QCString &sep, const QCString &str, bool allowEmptyEntries ) +{ + QCStringList lst; + + int j = 0; + int i = str.find( sep, j ); + + while ( i != -1 ) { + if ( str.mid( j, i - j ).length() > 0 ) + lst << str.mid( j, i - j ); + else if ( allowEmptyEntries ) + lst << QCString(); + j = i + sep.length(); + i = str.find( sep, j ); + } + + int l = str.length() - 1; + if ( str.mid( j, l - j + 1 ).length() > 0 ) + lst << str.mid( j, l - j + 1 ); + else if ( allowEmptyEntries ) + lst << QCString(); + + return lst; +} + +/*! + Splits the string \a str using the regular expression \a sep as separator. Returns the + list of strings. If \a allowEmptyEntries is TRUE, also empty + entries are inserted into the list, else not. So if you have + a string 'abc..d.e.', a list which contains 'abc', 'd', and 'e' + would be returned if \a allowEmptyEntries is FALSE, but + a list containing 'abc', '', 'd', 'e' and '' would be returned if + \a allowEmptyEntries is TRUE. + If \a str doesn't contain \a sep, a stringlist + with one item, which is the same as \a str, is returned. + + \sa join() +*/ + +QCStringList QCStringList::split( const QRegExp &sep, const QCString &str, bool allowEmptyEntries ) +{ + QCStringList lst; + + int j = 0; + int len = 0; + int i = sep.match( str.data(), j, &len ); + + while ( i != -1 ) { + if ( str.mid( j, i - j ).length() > 0 ) + lst << str.mid( j, i - j ); + else if ( allowEmptyEntries ) + lst << QCString(); + j = i + len; + i = sep.match( str.data(), j, &len ); + } + + int l = str.length() - 1; + if ( str.mid( j, l - j + 1 ).length() > 0 ) + lst << str.mid( j, l - j + 1 ); + else if ( allowEmptyEntries ) + lst << QCString(); + + return lst; +} + +/*! + Returns a list of all strings containing the substring \a str. + + If \a cs is TRUE, the grep is done case sensitively, else not. +*/ + +QCStringList QCStringList::grep( const QCString &str, bool cs ) const +{ + QCStringList res; + for ( QCStringList::ConstIterator it = begin(); it != end(); ++it ) + if ( (*it).contains( str, cs ) ) + res << *it; + + return res; +} + +/*! + Returns a list of all strings containing a substring that matches + the regular expression \a expr. +*/ + +QCStringList QCStringList::grep( const QRegExp &expr ) const +{ + QCStringList res; + for ( QCStringList::ConstIterator it = begin(); it != end(); ++it ) + if ( (*it).contains( expr ) ) + res << *it; + + return res; +} + +/*! + Joins the stringlist into a single string with each element + separated by \a sep. + + \sa split() +*/ +QCString QCStringList::join( const QCString &sep ) const +{ + QCString res; + bool alredy = FALSE; + for ( QCStringList::ConstIterator it = begin(); it != end(); ++it ) { + if ( alredy ) + res += sep; + alredy = TRUE; + res += *it; + } + + return res; +} + +Q_EXPORT QDataStream &operator>>( QDataStream & s, QCStringList& l ) +{ + return s >> (QValueList<QCString>&)l; +} + +Q_EXPORT QDataStream &operator<<( QDataStream & s, const QCStringList& l ) +{ + return s << (const QValueList<QCString>&)l; +} + +/*! + Converts from a QStrList (ASCII) to a QCStringList (Unicode). +*/ +QCStringList QCStringList::fromStrList(const QStrList& ascii) +{ + QCStringList res; + const char * s; + for ( QStrListIterator it(ascii); (s=it.current()); ++it ) + res << s; + return res; +} + diff --git a/qtools/qcstringlist.h b/qtools/qcstringlist.h new file mode 100644 index 0000000..604a196 --- /dev/null +++ b/qtools/qcstringlist.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 1997-2018 by Dimitri van Heesch. +** +** Permission to use, copy, modify, and distribute this software and its +** documentation under the terms of the GNU General Public License is hereby +** granted. No representations are made about the suitability of this software +** for any purpose. It is provided "as is" without express or implied warranty. +** See the GNU General Public License for more details. +** +** Note: this is a variant of the qstringlist.h but for QCString's +** +**********************************************************************/ +#ifndef QCSTRINGLIST_H +#define QCSTRINGLIST_H + +#include "qvaluelist.h" +#include "qcstring.h" +#include "qregexp.h" + +class QStrList; +class QDataStream; + +class QCStringList : public QValueList<QCString> +{ +public: + QCStringList() { } + QCStringList( const QCStringList& l ) : QValueList<QCString>(l) { } + QCStringList( const QValueList<QCString>& l ) : QValueList<QCString>(l) { } + QCStringList( const QCString& i ) { append(i); } + QCStringList( const char* i ) { append(i); } + + static QCStringList fromStrList(const QStrList&); + + static QCStringList split( const QCString &sep, const QCString &str, bool allowEmptyEntries = FALSE ); + static QCStringList split( char sep, const QCString &str, bool allowEmptyEntries = FALSE ); + static QCStringList split( const QRegExp &sep, const QCString &str, bool allowEmptyEntries = FALSE ); + QCString join( const QCString &sep ) const; + + QCStringList grep( const QCString &str, bool cs = TRUE ) const; + QCStringList grep( const QRegExp &expr ) const; +}; + +extern Q_EXPORT QDataStream &operator>>( QDataStream &, QCStringList& ); +extern Q_EXPORT QDataStream &operator<<( QDataStream &, const QCStringList& ); + +#endif // QCSTRINGLIST_H |