File indexing completed on 2023-12-03 05:01:59

0001 /*
0002  * Text Parser common class
0003  * Copyright (C) 2004 Peter Simonsson <psn@linux.se>
0004  * Copyright (C) 2006-2008 Eike Hein <hein@kde.org>
0005  * Copyright (C) 2011 Przemek Czekaj <xcojack@gmail.com>
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Lesser General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2.1 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library; if not, write to the Free Software
0019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0020  */
0021 
0022 #ifndef TEXT_PARSER_H
0023 #define TEXT_PARSER_H
0024 
0025 #include <QObject>
0026 #include <QPair>
0027 #include <QStringList>
0028 
0029 #include <KTp/ktpcommoninternals_export.h>
0030 
0031 namespace KTp
0032 {
0033 
0034 /**
0035  * Useful data container
0036  *
0037  * @var QList urlRanges
0038  * @var QStringList fixedUrls
0039  */
0040 struct KTPCOMMONINTERNALS_EXPORT TextUrlData
0041 {
0042     QList<QPair<int, int> > urlRanges;
0043     QStringList fixedUrls;
0044 };
0045 
0046 /**
0047  * TextParser
0048  *
0049  */
0050 class KTPCOMMONINTERNALS_EXPORT TextParser : public QObject
0051 {
0052 
0053 public:
0054     /**
0055      * Singleton pattern
0056      *
0057      * @param void
0058      * @return TextParser
0059      */
0060     static TextParser *instance();
0061 
0062     /**
0063      * Method extract url from text
0064      *
0065      * @param QString string A whole text
0066      * @param bool doUrlFixup fix the url default true
0067      * @return TextUrlData
0068      * @author Konversation developers
0069      */
0070     TextUrlData extractUrlData(const QString& string, bool doUrlFixup = true);
0071 
0072     /**
0073      * Destructor
0074      *
0075      * @param void
0076      */
0077     ~TextParser() override;
0078 
0079 private:
0080     /**
0081      * Constructor
0082      *
0083      * @param QObject
0084      */
0085     TextParser(QObject *parent = nullptr);
0086 
0087     /**
0088      * @var TextParser
0089      */
0090     static TextParser *s_instance;
0091 };
0092 
0093 }
0094 
0095 #endif // TEXT_PARSER_H