forked from KDE/okteta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextbytearrayanalyzer.hpp
135 lines (117 loc) · 5.16 KB
/
textbytearrayanalyzer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
This file is part of the Okteta Core library, made within the KDE community.
SPDX-FileCopyrightText: 2005, 2008-2009 Friedrich W. H. Kossebau <[email protected]>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef OKTETA_TEXTBYTEARRAYANALYZER_HPP
#define OKTETA_TEXTBYTEARRAYANALYZER_HPP
// lib
#include "oktetacore_export.hpp"
#include "addressrange.hpp"
// Std
#include <memory>
class QString;
namespace Okteta {
class AbstractByteArrayModel;
class CharCodec;
/**
*
* @author Friedrich W. H. Kossebau
*/
class OKTETACORE_EXPORT TextByteArrayAnalyzer
{
public:
TextByteArrayAnalyzer(const AbstractByteArrayModel* byteArrayModel, const CharCodec* charCodec);
TextByteArrayAnalyzer(const TextByteArrayAnalyzer&) = delete;
~TextByteArrayAnalyzer();
TextByteArrayAnalyzer& operator=(const TextByteArrayAnalyzer&) = delete;
public:
/** searches for the start of the word including the given index.
* if no other nonwordchar preceds this is 0;
* If the byte at the given index is already a nonword char the given index is returned.
* @param index index to start with
* @return index of the first char of the current word or the given index if there is none
*/
[[nodiscard]]
Address indexOfWordStart(Address index) const;
[[nodiscard]]
Address indexOfLeftWordSelect(Address index) const;
/** searches for the end of the word including the given index.
* If the byte at the given index is already a nonword char the given index is returned.
* if no other nonwordchar follows, that of the last byte;
* @param index index to start with
* @return index of the last char of the current word or the given index if there is none
*/
[[nodiscard]]
Address indexOfWordEnd(Address index) const;
/** searches for the first char after the end of the word including the given index.
* If the byte at the given index is already a nonword char the given index is returned.
* if no other nonwordchar follows that of behind the last byte;
* @param index index to start with
* @return index of the first char after the current word or the given index if there is none
*/
[[nodiscard]]
Address indexOfRightWordSelect(Address index) const;
/** searches for the first char after the end of the word including the given index.
* If the byte at the given index is already a nonword char the given index is returned.
* if no other nonwordchar follows that of behind the last byte;
* @param index index to start with
* @return index of the first char after the current word or the given index if there is none
*/
// Address indexOfBehindLeftWordEnd( Address index ) const;
/** searches for the first char after the end of the word including the given index.
* If the byte at the given index is already a nonword char the given index is returned.
* if no other nonwordchar follows that of behind the last byte;
* @param index index to start with
* @return index of the first char after the current word or the given index if there is none
*/
// Address indexOfBehindRightWordEnd( Address index ) const;
/** searches the start of the next previous word that does not include the given index,
* if no further word is found 0 is returned.
* if the index is out of range the behaviour is undefined.
* @param index
* @return index of the next previous word start or 0
*/
[[nodiscard]]
Address indexOfPreviousWordStart(Address index) const;
/** searches for the start of the next word not including the given index.
* if there isn't a next word the index behind end is returned
* @param index
* @return index of the start of the next word or behind end
*/
[[nodiscard]]
Address indexOfNextWordStart(Address index) const;
/** searches for the start of the next word not including the given index.
* if there isn't a next word the index of the end is returned
* @param index index to start with
* @return index of the last nonword char before the next word or the last index
*/
[[nodiscard]]
Address indexOfBeforeNextWordStart(Address index) const;
/** if index is out of range the behaviour is undefined
* @param index
* @return @c true if the byte at position i is a char of type CharType
*/
[[nodiscard]]
bool isWordChar(Address index) const;
/** returns the section with a word around index.
* if there is no word the section is empty
* @param index
* @return the section with a word around index.
*/
[[nodiscard]]
AddressRange wordSection(Address index) const;
/** returns the text starting at the given index until the first non-text byte
* if there is no text byte at the index the result is empty.
* @param index
* @param lastIndex if -1 lastIndex is set to the end of th byte array.
* @return the text starting at the index
*/
[[nodiscard]]
QString text(Address index, Address lastIndex = -1) const;
private:
const std::unique_ptr<class TextByteArrayAnalyzerPrivate> d_ptr;
Q_DECLARE_PRIVATE(TextByteArrayAnalyzer)
};
}
#endif