| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2020 Jonathan Poelen <jonathan.poelen@gmail.com> |
| 3 | |
| 4 | SPDX-License-Identifier: MIT |
| 5 | */ |
| 6 | |
| 7 | #ifndef KSYNTAXHIGHLIGHTING_WORDDELIMITERS_P_H |
| 8 | #define KSYNTAXHIGHLIGHTING_WORDDELIMITERS_P_H |
| 9 | |
| 10 | #include <QString> |
| 11 | |
| 12 | #include <bitset> |
| 13 | |
| 14 | namespace KSyntaxHighlighting |
| 15 | { |
| 16 | /** |
| 17 | * Represents a list of character that separates 2 words. |
| 18 | * |
| 19 | * Default delimiters are .():!+*,-<=>%&/;?[]^{|}~\, space (' ') and tabulator ('\t'). |
| 20 | * |
| 21 | * @see Rule |
| 22 | * @since 5.74 |
| 23 | */ |
| 24 | class WordDelimiters |
| 25 | { |
| 26 | public: |
| 27 | WordDelimiters(); |
| 28 | |
| 29 | /** |
| 30 | * Initialize with a default delimiters. |
| 31 | */ |
| 32 | explicit WordDelimiters(QStringView str); |
| 33 | |
| 34 | /** |
| 35 | * Returns @c true if @p c is a word delimiter; otherwise returns @c false. |
| 36 | */ |
| 37 | bool contains(QChar c) const; |
| 38 | |
| 39 | /** |
| 40 | * Appends each character of @p s to word delimiters. |
| 41 | */ |
| 42 | void append(QStringView s); |
| 43 | |
| 44 | /** |
| 45 | * Removes each character of @p s from word delimiters. |
| 46 | */ |
| 47 | void remove(QStringView c); |
| 48 | |
| 49 | private: |
| 50 | /** |
| 51 | * An array which represents ascii characters for very fast lookup. |
| 52 | * The character is used as an index and the value @c true indicates a word delimiter. |
| 53 | */ |
| 54 | std::bitset<128> asciiDelimiters; |
| 55 | |
| 56 | /** |
| 57 | * Contains characters that are not ascii and is empty for most syntax definition. |
| 58 | */ |
| 59 | QString notAsciiDelimiters; |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | #endif |
| 64 | |