Changeset View
Changeset View
Standalone View
Standalone View
src/lib/text/kstringhandler.cpp
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 116 | { | |||
---|---|---|---|---|---|
133 | 133 | | |||
134 | if (!s.midRef(searchStart, s.length() - searchStart).isEmpty()) { | 134 | if (!s.midRef(searchStart, s.length() - searchStart).isEmpty()) { | ||
135 | l << s.mid(searchStart, s.length() - searchStart); | 135 | l << s.mid(searchStart, s.length() - searchStart); | ||
136 | } | 136 | } | ||
137 | 137 | | |||
138 | return l; | 138 | return l; | ||
139 | } | 139 | } | ||
140 | 140 | | |||
141 | #if KCOREADDONS_BUILD_DEPRECATED_SINCE(5, 67) | ||||
141 | QStringList KStringHandler::perlSplit(const QRegExp &sep, const QString &s, int max) | 142 | QStringList KStringHandler::perlSplit(const QRegExp &sep, const QString &s, int max) | ||
142 | { | 143 | { | ||
144 | // nothing to split | ||||
145 | if (s.isEmpty()) { | ||||
146 | return QStringList(); | ||||
147 | } | ||||
148 | | ||||
143 | bool ignoreMax = 0 == max; | 149 | bool ignoreMax = 0 == max; | ||
144 | 150 | | |||
145 | QStringList l; | 151 | QStringList l; | ||
146 | 152 | | |||
147 | int searchStart = 0; | 153 | int searchStart = 0; | ||
148 | int tokenStart = sep.indexIn(s, searchStart); | 154 | int tokenStart = sep.indexIn(s, searchStart); | ||
149 | int len = sep.matchedLength(); | 155 | int len = sep.matchedLength(); | ||
150 | 156 | | |||
151 | while (-1 != tokenStart && (ignoreMax || l.count() < max - 1)) { | 157 | while (-1 != tokenStart && (ignoreMax || l.count() < max - 1)) { | ||
152 | if (!s.midRef(searchStart, tokenStart - searchStart).isEmpty()) { | 158 | if (!s.midRef(searchStart, tokenStart - searchStart).isEmpty()) { | ||
153 | l << s.mid(searchStart, tokenStart - searchStart); | 159 | l << s.mid(searchStart, tokenStart - searchStart); | ||
154 | } | 160 | } | ||
155 | 161 | | |||
156 | searchStart = tokenStart + len; | 162 | searchStart = tokenStart + len; | ||
157 | tokenStart = sep.indexIn(s, searchStart); | 163 | tokenStart = sep.indexIn(s, searchStart); | ||
158 | len = sep.matchedLength(); | 164 | len = sep.matchedLength(); | ||
159 | } | 165 | } | ||
160 | 166 | | |||
161 | if (!s.midRef(searchStart, s.length() - searchStart).isEmpty()) { | 167 | if (!s.midRef(searchStart, s.length() - searchStart).isEmpty()) { | ||
162 | l << s.mid(searchStart, s.length() - searchStart); | 168 | l << s.mid(searchStart, s.length() - searchStart); | ||
163 | } | 169 | } | ||
164 | 170 | | |||
165 | return l; | 171 | return l; | ||
166 | } | 172 | } | ||
173 | #endif | ||||
174 | | ||||
175 | QStringList KStringHandler::perlSplit(const QRegularExpression &sep, const QString &s, int max) | ||||
176 | { | ||||
177 | // nothing to split | ||||
178 | if (s.isEmpty()) { | ||||
179 | return QStringList(); | ||||
180 | } | ||||
181 | | ||||
182 | bool ignoreMax = max == 0; | ||||
183 | | ||||
184 | QStringList list; | ||||
185 | | ||||
186 | int start = 0; | ||||
187 | QRegularExpressionMatchIterator iter = sep.globalMatch(s); | ||||
188 | QRegularExpressionMatch match; | ||||
189 | QString chunk; | ||||
190 | while (iter.hasNext() && (ignoreMax || list.count() < max - 1)) { | ||||
191 | match = iter.next(); | ||||
192 | chunk = s.mid(start, match.capturedStart() - start); | ||||
193 | if (!chunk.isEmpty()) { | ||||
194 | list.append(chunk); | ||||
195 | } | ||||
196 | start = match.capturedEnd(); | ||||
197 | } | ||||
198 | | ||||
199 | // catch the remainder | ||||
200 | chunk = s.mid(start, s.size() - start); | ||||
201 | if (!chunk.isEmpty()) { | ||||
202 | list.append(chunk); | ||||
203 | } | ||||
204 | | ||||
205 | return list; | ||||
206 | } | ||||
167 | 207 | | |||
168 | QString KStringHandler::tagUrls(const QString &text) | 208 | QString KStringHandler::tagUrls(const QString &text) | ||
169 | { | 209 | { | ||
170 | QString richText(text); | 210 | QString richText(text); | ||
171 | const QRegularExpression urlEx(QStringLiteral("(www\\.(?!\\.)|(fish|ftp|http|https)://[\\d\\w\\./,:_~\\?=&;#@\\-\\+\\%\\$\\(\\)]+)")); | 211 | const QRegularExpression urlEx(QStringLiteral("(www\\.(?!\\.)|(fish|ftp|http|https)://[\\d\\w\\./,:_~\\?=&;#@\\-\\+\\%\\$\\(\\)]+)")); | ||
172 | // the reference \1 is going to be replaced by the matched url | 212 | // the reference \1 is going to be replaced by the matched url | ||
173 | const QLatin1String regexBackRef(QLatin1String("\\1")); | 213 | const QLatin1String regexBackRef(QLatin1String("\\1")); | ||
174 | const QString anchor = QLatin1String("<a href=\"") + regexBackRef + QLatin1String("\">") + regexBackRef + QLatin1String("</a>"); | 214 | const QString anchor = QLatin1String("<a href=\"") + regexBackRef + QLatin1String("\">") + regexBackRef + QLatin1String("</a>"); | ||
▲ Show 20 Lines • Show All 176 Lines • Show Last 20 Lines |