libqutim 0.3.1.0
utils.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** qutIM - instant messenger
00004 **
00005 ** Copyright © 2011 Aleksey Sidorov <gorthauer87@yandex.ru>
00006 ** Copyright © 2012 Ruslan Nigmatullin <euroelessar@yandex.ru>
00007 **
00008 *****************************************************************************
00009 **
00010 ** $QUTIM_BEGIN_LICENSE$
00011 ** This program is free software: you can redistribute it and/or modify
00012 ** it under the terms of the GNU General Public License as published by
00013 ** the Free Software Foundation, either version 3 of the License, or
00014 ** (at your option) any later version.
00015 **
00016 ** This program is distributed in the hope that it will be useful,
00017 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00019 ** See the GNU General Public License for more details.
00020 **
00021 ** You should have received a copy of the GNU General Public License
00022 ** along with this program.  If not, see http://www.gnu.org/licenses/.
00023 ** $QUTIM_END_LICENSE$
00024 **
00025 ****************************************************************************/
00026 
00027 #ifndef UTILS_H
00028 #define UTILS_H
00029 #include "libqutim_global.h"
00030 
00031 namespace qutim_sdk_0_3
00032 {
00033 
00034 template<typename T>
00035 Q_INLINE_TEMPLATE T sender_cast(QObject *sender)
00036 {
00037     Q_ASSERT(qobject_cast<T>(sender));
00038     return static_cast<T>(sender);
00039 }
00040 
00041 class LIBQUTIM_EXPORT UrlParser
00042 {
00043 public:
00044     enum Flag {
00045         None = 0x00
00046     };
00047     Q_DECLARE_FLAGS(Flags, Flag)
00048     struct UrlToken
00049     {
00050         QStringRef text;
00051         QString url;
00052     };
00053     typedef QList<UrlToken> UrlTokenList;
00054     
00055     static UrlTokenList tokenize(const QString &text, Flags flags = None);
00056     static QString parseUrls(const QString &text, Flags flags = None);
00057 private:
00058     UrlParser();
00059     ~UrlParser();
00060 };
00061 
00062 } //namespace qutim_sdk_0_3
00063 
00064 Q_DECLARE_OPERATORS_FOR_FLAGS(qutim_sdk_0_3::UrlParser::Flags)
00065 
00066 #endif // UTILS_H
00067