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(position: *p);
16 }
17}
18
19WordDelimiters::WordDelimiters(QStringView str)
20 : asciiDelimiters{}
21{
22 append(s: str);
23}
24
25bool WordDelimiters::contains(QChar c) const
26{
27 if (c.unicode() < 128) {
28 return asciiDelimiters.test(position: 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(position: 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(position: c.unicode(), val: false);
50 } else {
51 notAsciiDelimiters.remove(c);
52 }
53 }
54}
55

source code of syntax-highlighting/src/lib/worddelimiters.cpp