KSyntaxHighlighting

worddelimiters.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Jonathan Poelen <jonathan.poelen@gmail.com>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "worddelimiters_p.h"
8
9using namespace KSyntaxHighlighting;
10
11WordDelimiters::WordDelimiters()
12 : asciiDelimiters{}
13{
14 for (const char *p = "\t !%&()*+,-./:;<=>?[\\]^{|}~"; *p; ++p) {
15 asciiDelimiters.set(*p);
16 }
17}
18
19WordDelimiters::WordDelimiters(QStringView str)
20 : asciiDelimiters{}
21{
22 append(str);
23}
24
25bool WordDelimiters::contains(QChar c) const
26{
27 if (c.unicode() < 128) {
28 return asciiDelimiters.test(c.unicode());
29 }
30 // perf tells contains is MUCH faster than binary search here, very short array
31 return notAsciiDelimiters.contains(c);
32}
33
34void WordDelimiters::append(QStringView s)
35{
36 for (QChar c : s) {
37 if (c.unicode() < 128) {
38 asciiDelimiters.set(c.unicode());
39 } else {
40 notAsciiDelimiters.append(c);
41 }
42 }
43}
44
45void WordDelimiters::remove(QStringView s)
46{
47 for (QChar c : s) {
48 if (c.unicode() < 128) {
49 asciiDelimiters.set(c.unicode(), false);
50 } else {
51 notAsciiDelimiters.remove(c);
52 }
53 }
54}
Syntax highlighting engine for Kate syntax definitions.
char16_t & unicode()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.