| 1 | // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/miscellaneous/regexfactory.cpp`/ |
| 2 | |
| 3 | /**************************************************************************** |
| 4 | ** |
| 5 | ** Copyright (C) 2016 Giuseppe D'Angelo <[email protected]>. |
| 6 | ** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected], author Giuseppe D'Angelo |
| 7 | *<[email protected]> |
| 8 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 9 | ** Contact: https://www.qt.io/licensing/ |
| 10 | ** |
| 11 | ** This file is part of the QtCore module of the Qt Toolkit. |
| 12 | ** |
| 13 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 14 | ** Commercial License Usage |
| 15 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 16 | ** accordance with the commercial license agreement provided with the |
| 17 | ** Software or, alternatively, in accordance with the terms contained in |
| 18 | ** a written agreement between you and The Qt Company. For licensing terms |
| 19 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 20 | ** information use the contact form at https://www.qt.io/contact-us. |
| 21 | ** |
| 22 | ** GNU Lesser General Public License Usage |
| 23 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 24 | ** General Public License version 3 as published by the Free Software |
| 25 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 26 | ** packaging of this file. Please review the following information to |
| 27 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 28 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 29 | ** |
| 30 | ** GNU General Public License Usage |
| 31 | ** Alternatively, this file may be used under the terms of the GNU |
| 32 | ** General Public License version 2.0 or (at your option) the GNU General |
| 33 | ** Public license version 3 or any later version approved by the KDE Free |
| 34 | ** Qt Foundation. The licenses are as published by the Free Software |
| 35 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 36 | ** included in the packaging of this file. Please review the following |
| 37 | ** information to ensure the GNU General Public License requirements will |
| 38 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 39 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 40 | ** |
| 41 | ** $QT_END_LICENSE$ |
| 42 | ** |
| 43 | ****************************************************************************/ |
| 44 | |
| 45 | #include "miscellaneous/regexfactory.h"cxx . . $ `<file>/src/librssguard/miscellaneous/regexfactory.h`/ |
| 46 | |
| 47 | QStringcxx . . $ QString# RegexFactorycxx . . $ RegexFactory#::wildcardToRegularExpressioncxx . . $ RegexFactory#wildcardToRegularExpression(fd988a2ab94d906b).(const QStringcxx . . $ QString#& pattern) { |
| 48 | const int wclen = pattern.lengthcxx . . $ QString#length(6b0412d51016192f).(); |
| 49 | QStringcxx . . $ QString# rxcxx . . $ QString#QString(ced63f7c635d850d).; |
| 50 | |
| 51 | rx.reservecxx . . $ QString#reserve(35cb52607f6af42f).(wclen + wclen / 16); |
| 52 | int i = 0; |
| 53 | const QCharcxx . . $ QChar#* wc = pattern.unicodecxx . . $ QString#unicode(4b5a7d1cd542e2bb).(); |
| 54 | |
| 55 | #if defined(Q_OS_WIN) |
| 56 | const QLatin1Char nativePathSeparator('\\'); |
| 57 | const QLatin1String starEscape("[^/\\\\]*"); |
| 58 | const QLatin1String questionMarkEscape("[^/\\\\]"); |
| 59 | #else |
| 60 | const QLatin1Charcxx . . $ QLatin1Char# nativePathSeparatorcxx . . $ QLatin1Char#QLatin1Char(65960c15425b226).('/'); |
| 61 | const QLatin1Stringcxx . . $ QLatin1String# starEscapecxx . . $ QLatin1String#QLatin1String(aac1607cfe1c1740).("[^/]*"); |
| 62 | const QLatin1Stringcxx . . $ QLatin1String# questionMarkEscapecxx . . $ QLatin1String#QLatin1String(aac1607cfe1c1740).("[^/]"); |
| 63 | #endif |
| 64 | |
| 65 | while (i < wclen) { |
| 66 | const QCharcxx . . $ QChar# c = wc[i++]; |
| 67 | |
| 68 | switch (c.unicodecxx . . $ QChar#unicode(a45d90656f9dea2b).()) { |
| 69 | case '*': |
| 70 | rx +=cxx . . $ QString#`operator+=`(10913c921d46e09a). starEscape; |
| 71 | break; |
| 72 | |
| 73 | case '?': |
| 74 | rx +=cxx . . $ QString#`operator+=`(10913c921d46e09a). questionMarkEscape; |
| 75 | break; |
| 76 | |
| 77 | case '\\': |
| 78 | #if defined(Q_OS_WIN) |
| 79 | case '/': |
| 80 | rx += QLatin1String("[/\\\\]"); |
| 81 | break; |
| 82 | #endif |
| 83 | case '$': |
| 84 | case '(': |
| 85 | case ')': |
| 86 | case '+': |
| 87 | case '.': |
| 88 | case '^': |
| 89 | case '{': |
| 90 | case '|': |
| 91 | case '}': |
| 92 | rx +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). QLatin1Charcxx . . $ QChar#QChar(93d577a3e9528307).('\\'); |
| 93 | rx +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). c; |
| 94 | break; |
| 95 | |
| 96 | case '[': |
| 97 | rx +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). c; |
| 98 | |
| 99 | // Support for the [!abc] or [!a-c] syntax |
| 100 | if (i < wclen) { |
| 101 | if (wc[i] ==cxx . . $ `operator==`(f71319ce7e384db6). QLatin1Charcxx . . $ QChar#QChar(93d577a3e9528307).('!')) { |
| 102 | rx +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). QLatin1Charcxx . . $ QChar#QChar(93d577a3e9528307).('^'); |
| 103 | ++i; |
| 104 | } |
| 105 | |
| 106 | if (i < wclen && wc[i] ==cxx . . $ `operator==`(f71319ce7e384db6). QLatin1Charcxx . . $ QChar#QChar(93d577a3e9528307).(']')) |
| 107 | rx +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). wc[i++]; |
| 108 | |
| 109 | while (i < wclen && wc[i] !=cxx . . $ `operator!=`(f71319ce7e384db6). QLatin1Charcxx . . $ QChar#QChar(93d577a3e9528307).(']')) { |
| 110 | // The '/' appearing in a character class invalidates the |
| 111 | // regular expression parsing. It also concerns '\\' on |
| 112 | // Windows OS types. |
| 113 | if (wc[i] ==cxx . . $ `operator==`(f71319ce7e384db6). QLatin1Charcxx . . $ QChar#QChar(93d577a3e9528307).('/') || wc[i] ==cxx . . $ `operator==`(f71319ce7e384db6). nativePathSeparatorcxx . . $ QChar#QChar(93d577a3e9528307).) |
| 114 | return rxcxx . . $ QString#QString(28715ad661ad3cec).; |
| 115 | |
| 116 | if (wc[i] ==cxx . . $ `operator==`(f71319ce7e384db6). QLatin1Charcxx . . $ QChar#QChar(93d577a3e9528307).('\\')) |
| 117 | rx +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). QLatin1Charcxx . . $ QChar#QChar(93d577a3e9528307).('\\'); |
| 118 | |
| 119 | rx +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). wc[i++]; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | break; |
| 124 | |
| 125 | default: |
| 126 | rx +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). c; |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | return anchoredPatterncxx . . $ RegexFactory#anchoredPattern(fd988a2ab94d906b).(rx); |
| 132 | } |