| 1 | /* |
| 2 | This file is part of the KDE Baloo project. |
| 3 | SPDX-FileCopyrightText: 2025 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 | */ |
| 7 | |
| 8 | #ifndef BALOO_TERMGENERATOR_P_H |
| 9 | #define BALOO_TERMGENERATOR_P_H |
| 10 | |
| 11 | namespace Baloo |
| 12 | { |
| 13 | namespace detail |
| 14 | { |
| 15 | |
| 16 | bool verifySurrogates(QStringView text) |
| 17 | { |
| 18 | if (auto size = text.size(); size == 1) { |
| 19 | return !text.back().isSurrogate(); |
| 20 | } else if (size == 0) { |
| 21 | return true; |
| 22 | } |
| 23 | |
| 24 | for (qsizetype i = 0; i < text.size() - 1; i++) { |
| 25 | const QChar &c = text.at(n: i); |
| 26 | if (!c.isSurrogate()) { |
| 27 | continue; |
| 28 | } |
| 29 | if (c.isLowSurrogate()) { |
| 30 | return false; |
| 31 | } else if (!text.at(n: i + 1).isLowSurrogate()) { |
| 32 | return false; |
| 33 | } else { |
| 34 | i++; |
| 35 | } |
| 36 | } |
| 37 | if (!text.back().isSurrogate()) { |
| 38 | return true; |
| 39 | } else if (text.back().isHighSurrogate()) { |
| 40 | return false; |
| 41 | } else { |
| 42 | auto back2 = text.at(n: text.size() - 2); |
| 43 | return back2.isHighSurrogate(); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | } // namespace detail |
| 48 | } // namespace Baloo |
| 49 | |
| 50 | #endif // BALOO_TERMGENERATOR_P_H |
| 51 | |