Kate
katetextline.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __KATE_TEXTLINE_H__
00024 #define __KATE_TEXTLINE_H__
00025
00026 #include <ksharedptr.h>
00027
00028 #include <QtCore/QString>
00029 #include <QtCore/QVector>
00030
00031
00039 class KateTextLine : public KShared
00040 {
00041 public:
00045 typedef KSharedPtr<KateTextLine> Ptr;
00046
00047 public:
00051 enum Flags
00052 {
00053 flagHlContinue = 1,
00054 flagAutoWrapped = 2,
00055 flagFoldingColumnsOutdated = 4,
00056 flagNoIndentationBasedFolding = 8,
00057 flagNoIndentationBasedFoldingAtStart = 16
00058 };
00059
00060 public:
00066 KateTextLine ();
00067
00068 KateTextLine (const QChar *data, int length);
00069
00073 ~KateTextLine ();
00074
00078 public:
00082 inline void setFoldingColumnsOutdated(bool set) { if (set) m_flags |= KateTextLine::flagFoldingColumnsOutdated; else m_flags&=
00083 (~KateTextLine::flagFoldingColumnsOutdated);}
00084
00088 inline bool foldingColumnsOutdated() const { return m_flags & KateTextLine::flagFoldingColumnsOutdated; }
00089
00090
00094 inline int length() const { return m_text.length(); }
00095
00100 inline bool hlLineContinue () const { return m_flags & KateTextLine::flagHlContinue; }
00101
00106 inline bool isAutoWrapped () const { return m_flags & KateTextLine::flagAutoWrapped; }
00107
00112 int firstChar() const;
00113
00118 int lastChar() const;
00119
00126 int nextNonSpaceChar(uint pos) const;
00127
00134 int previousNonSpaceChar(int pos) const;
00135
00140 inline QChar at (int column) const
00141 {
00142 if (column >= 0 && column < m_text.length())
00143 return m_text[column];
00144
00145 return QChar();
00146 }
00147
00151 inline QChar operator[](int column) const
00152 {
00153 if (column >= 0 && column < m_text.length())
00154 return m_text[column];
00155
00156 return QChar();
00157 }
00158
00162 inline const QString& string() const { return m_text; }
00163
00167 inline QString string(int column, int length) const
00168 { return m_text.mid(column, length); }
00169
00173 int indentDepth (int tabWidth) const;
00174
00178 int toVirtualColumn (int column, int tabWidth) const;
00179
00184 int fromVirtualColumn (int column, int tabWidth) const;
00185
00189 int virtualLength (int tabWidth) const;
00190
00195 bool matchesAt(int column, const QString& match) const;
00196
00200 inline bool startsWith(const QString& match) const { return m_text.startsWith (match); }
00201
00205 inline bool endsWith(const QString& match) const { return m_text.endsWith (match); }
00206
00218 bool searchText (uint startCol, uint endCol,const QString &text,
00219 uint *foundAtCol, uint *matchLen,
00220 bool casesensitive = true,
00221 bool backwards = false) const;
00222
00232 bool searchText (uint startCol, const QRegExp ®exp,
00233 uint *foundAtCol, uint *matchLen,
00234 bool backwards = false) const;
00235
00243 inline uchar attribute (int pos) const
00244 {
00245 for (int i=0; i < m_attributesList.size(); i+=3)
00246 {
00247 if (pos >= m_attributesList[i] && pos < m_attributesList[i]+m_attributesList[i+1])
00248 return m_attributesList[i+2];
00249
00250 if (pos < m_attributesList[i])
00251 break;
00252 }
00253
00254 return 0;
00255 }
00256
00261 inline const QVector<short> &ctxArray () const { return m_ctx; }
00262
00266 inline bool noIndentBasedFolding() const { return m_flags & KateTextLine::flagNoIndentationBasedFolding; }
00267 inline bool noIndentBasedFoldingAtStart() const { return m_flags & KateTextLine::flagNoIndentationBasedFoldingAtStart; }
00272 inline const QVector<int> &foldingListArray () const { return m_foldingList; }
00273
00278 inline const QVector<unsigned short> &indentationDepthArray () const { return m_indentationDepth; }
00279
00285 void insertText (int pos, const QString& insText);
00286
00292 void removeText (uint pos, uint delLen);
00293
00298 void truncate(int newLen);
00299
00304 inline void setHlLineContinue (bool cont)
00305 {
00306 if (cont) m_flags = m_flags | KateTextLine::flagHlContinue;
00307 else m_flags = m_flags & ~ KateTextLine::flagHlContinue;
00308 }
00309
00314 inline void setAutoWrapped (bool wrapped)
00315 {
00316 if (wrapped) m_flags = m_flags | KateTextLine::flagAutoWrapped;
00317 else m_flags = m_flags & ~ KateTextLine::flagAutoWrapped;
00318 }
00319
00324 inline void setContext (QVector<short> &val) { m_ctx = val; }
00325
00329 inline void setNoIndentBasedFolding(bool val)
00330 {
00331 if (val) m_flags = m_flags | KateTextLine::flagNoIndentationBasedFolding;
00332 else m_flags = m_flags & ~ KateTextLine::flagNoIndentationBasedFolding;
00333 }
00334
00335 inline void setNoIndentBasedFoldingAtStart(bool val)
00336 {
00337 if (val) m_flags = m_flags | KateTextLine::flagNoIndentationBasedFoldingAtStart;
00338 else m_flags = m_flags & ~ KateTextLine::flagNoIndentationBasedFoldingAtStart;
00339 }
00340
00345 inline void setFoldingList (QVector<int> &val) { m_foldingList = val; }
00346
00351 inline void setIndentationDepth (QVector<unsigned short> &val) { m_indentationDepth = val; }
00352
00356 public:
00357 void addAttribute (int start, int length, int attribute);
00358
00359 void clearAttributes () { m_attributesList.clear (); }
00360
00361 const QVector<int> &attributesList () const { return m_attributesList; }
00362
00366 private:
00370 QString m_text;
00371
00376 QVector<int> m_attributesList;
00377
00381 QVector<short> m_ctx;
00382
00386 QVector<int> m_foldingList;
00387
00391 QVector<unsigned short> m_indentationDepth;
00392
00396 uchar m_flags;
00397 };
00398
00399 #endif
00400
00401