/usr/include/segment.h is in libdewalls-dev 1.0.0+ds1-4ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | #ifndef DEWALLS_SEGMENT_H
#define DEWALLS_SEGMENT_H
#include <QSharedPointer>
#include <QString>
#include <QObject>
#include <QRegExp>
#include <QList>
#include "dewallsexport.h"
namespace dewalls {
class SegmentImpl;
class Segment;
typedef QSharedPointer<SegmentImpl> SegmentPtr;
/**
* @brief The data that's implicitly shared by Segment instances
*/
class SegmentImpl
{
public:
friend class Segment;
SegmentImpl(QString value, QString source, int startLine, int startCol);
SegmentImpl(QString value);
protected:
SegmentImpl(SegmentPtr sourceSegment, int sourceIndex, QString value, QString source,
int startLine, int startCol);
SegmentImpl(SegmentPtr sourceSegment, int sourceIndex, QString value, QString source,
int startLine, int startCol, int endLine, int endCol);
private:
SegmentImpl() = delete;
SegmentImpl(SegmentImpl& other) = delete;
SegmentImpl& operator=(SegmentImpl& other) = delete;
SegmentPtr _sourceSegment;
int _sourceIndex;
QString _value;
QString _source;
int _startLine;
int _startCol;
int _endLine;
int _endCol;
};
/**
* @brief A wrapper for a QString that maintains information about where it's located in
* some source file. Subsegments of this Segment created with mid(), split(), trimmed(), etc.
* will also contain proper location information. This way, if a parser encounters a
* syntax error in any subsegment of a file or line it's operating on, it can underline the
* error in context using cout << segment.mid(errorStart, errorLen).underlineInContext().toStdString().
*
* Not to be confused with Walls #segment directives.
*
* Many methods simply delegate to the wrapped QString. Others have an analogous signature but
* return Segment or QList<Segment> instead of QString or QStringList.
*
* Segment uses implicit sharing like many Qt classes.
*/
class DEWALLS_LIB_EXPORT Segment
{
public:
Segment();
Segment(QString value);
Segment(QString value, QString source, int startLine, int startCol);
Segment(Segment&& other);
Segment(const Segment& other) = default;
Segment sourceSegment() const;
int sourceIndex() const;
QString value() const;
QString source() const;
int startLine() const;
int startCol() const;
int endLine() const;
int endCol() const;
int length() const;
bool isEmpty() const;
const QChar at(int index) const;
Segment atAsSegment(int index) const;
Segment mid(int position, int n = -1) const;
Segment left(int n) const;
Segment right(int n) const;
QList<Segment> split(const QRegExp& re, QString::SplitBehavior behavior = QString::KeepEmptyParts) const;
QList<Segment> split(const QString& pattern, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
int compare(const QString& other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
int compare(const QStringRef& other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool contains(const QString& str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool contains(const QStringRef& str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool contains(const QRegExp& rx) const;
bool contains(QRegExp& rx) const;
bool endsWith(const QString& str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool endsWith(const QStringRef& str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
int indexOf(const QString& str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
int indexOf(const QStringRef& str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
int lastIndexOf(const QString& str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
int lastIndexOf(const QStringRef& str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
std::string toStdString() const;
std::wstring toStdWString() const;
Segment trimmed() const;
QString toUpper() const;
QString toLower() const;
QString::const_iterator begin() const;
QString::const_iterator end() const;
const QChar operator[](int position) const;
const QChar operator[](uint position) const;
QString underlineInContext() const;
inline friend void swap(Segment& first, Segment& second)
{
using std::swap;
swap(first._impl, second._impl);
}
Segment& operator =(Segment other);
friend std::ostream& operator<<(std::ostream& os, const Segment& obj)
{
return os << obj.value().toStdString();
}
protected:
Segment(SegmentPtr impl);
private:
SegmentPtr _impl;
};
inline bool exactMatch(QRegExp& rx, const Segment& segment) {
return rx.exactMatch(segment.value());
}
inline int indexIn(QRegExp& rx, const Segment& segment, int offset = 0, QRegExp::CaretMode caretMode = QRegExp::CaretAtZero) {
return rx.indexIn(segment.value(), offset, caretMode);
}
inline int lastIndexIn(QRegExp& rx, const Segment& segment, int offset = -1, QRegExp::CaretMode caretMode = QRegExp::CaretAtZero) {
return rx.lastIndexIn(segment.value(), offset, caretMode);
}
inline Segment cap(QRegExp& rx, const Segment& segment, int nth = 0)
{
return segment.mid(rx.pos(nth), rx.cap(nth).length());
}
inline Segment::Segment()
: Segment(QString(), QString(), 0, 0)
{
}
inline Segment::Segment(Segment&& other)
{
swap(*this, other);
}
inline Segment& Segment::operator =(Segment other)
{
swap(*this, other);
return *this;
}
inline Segment Segment::sourceSegment() const
{
return Segment(_impl->_sourceSegment);
}
inline int Segment::sourceIndex() const
{
return _impl->_sourceIndex;
}
inline QString Segment::value() const
{
return _impl->_value;
}
inline QString Segment::source() const
{
return _impl->_source;
}
inline int Segment::startLine() const
{
return _impl->_startLine;
}
inline int Segment::startCol() const
{
return _impl->_startCol;
}
inline int Segment::endLine() const
{
return _impl->_endLine;
}
inline int Segment::endCol() const
{
return _impl->_endCol;
}
inline int Segment::length() const
{
return _impl->_value.length();
}
inline bool Segment::isEmpty() const
{
return _impl->_value.isEmpty();
}
inline const QChar Segment::at(int i) const
{
return _impl->_value.at(i);
}
inline Segment Segment::atAsSegment(int i) const
{
return mid(i, i == length() ? 0 : 1);
}
inline Segment Segment::left(int n) const
{
return mid(0, n);
}
inline Segment Segment::right(int n) const
{
return mid(length() - n, n);
}
inline int Segment::compare(const QString& other, Qt::CaseSensitivity cs) const
{
return value().compare(other, cs);
}
inline int Segment::compare(const QStringRef& other, Qt::CaseSensitivity cs) const
{
return value().compare(other, cs);
}
inline bool Segment::contains(const QString& str, Qt::CaseSensitivity cs) const
{
return value().contains(str, cs);
}
inline bool Segment::contains(const QStringRef& str, Qt::CaseSensitivity cs) const
{
return value().contains(str, cs);
}
inline bool Segment::contains(const QRegExp& rx) const
{
return value().contains(rx);
}
inline bool Segment::contains(QRegExp& rx) const
{
return value().contains(rx);
}
inline bool Segment::endsWith(const QString& str, Qt::CaseSensitivity cs) const
{
return value().endsWith(str, cs);
}
inline bool Segment::endsWith(const QStringRef& str, Qt::CaseSensitivity cs) const
{
return value().endsWith(str, cs);
}
inline int Segment::indexOf(const QString& str, int from, Qt::CaseSensitivity cs) const
{
return value().indexOf(str, from, cs);
}
inline int Segment::indexOf(const QStringRef& str, int from, Qt::CaseSensitivity cs) const
{
return value().indexOf(str, from, cs);
}
inline int Segment::lastIndexOf(const QString& str, int from, Qt::CaseSensitivity cs) const
{
return value().lastIndexOf(str, from, cs);
}
inline int Segment::lastIndexOf(const QStringRef& str, int from, Qt::CaseSensitivity cs) const
{
return value().lastIndexOf(str, from, cs);
}
inline std::string Segment::toStdString() const
{
return value().toStdString();
}
inline std::wstring Segment::toStdWString() const
{
return value().toStdWString();
}
inline Segment Segment::trimmed() const
{
QString val = value();
auto start = val.begin();
auto end = val.end();
while (start < end && start->isSpace()) start++;
while (end > start && (end - 1)->isSpace()) end--;
return mid(start - val.begin(), end - start);
}
inline QString Segment::toUpper() const
{
return value().toUpper();
}
inline QString Segment::toLower() const
{
return value().toLower();
}
inline QString::const_iterator Segment::begin() const
{
return value().begin();
}
inline QString::const_iterator Segment::end() const
{
return value().end();
}
inline const QChar Segment::operator [](int position) const
{
return value()[position];
}
inline const QChar Segment::operator [](uint position) const
{
return value()[position];
}
} // namespace dewalls
#endif // DEWALLS_SEGMENT_H
|