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
00170 QString leadingWhitespace() const;
00171
00175 int indentDepth (int tabWidth) const;
00176
00180 int toVirtualColumn (int column, int tabWidth) const;
00181
00186 int fromVirtualColumn (int column, int tabWidth) const;
00187
00191 int virtualLength (int tabWidth) const;
00192
00197 bool matchesAt(int column, const QString& match) const;
00198
00202 inline bool startsWith(const QString& match) const { return m_text.startsWith (match); }
00203
00207 inline bool endsWith(const QString& match) const { return m_text.endsWith (match); }
00208
00220 bool searchText (uint startCol, uint endCol,const QString &text,
00221 uint *foundAtCol, uint *matchLen,
00222 bool casesensitive = true,
00223 bool backwards = false) const;
00224
00234 bool searchText (uint startCol, const QRegExp ®exp,
00235 uint *foundAtCol, uint *matchLen,
00236 bool backwards = false) const;
00237
00245 inline uchar attribute (int pos) const
00246 {
00247 for (int i=0; i < m_attributesList.size(); i+=3)
00248 {
00249 if (pos >= m_attributesList[i] && pos < m_attributesList[i]+m_attributesList[i+1])
00250 return m_attributesList[i+2];
00251
00252 if (pos < m_attributesList[i])
00253 break;
00254 }
00255
00256 return 0;
00257 }
00258
00263 inline const QVector<short> &ctxArray () const { return m_ctx; }
00264
00268 inline bool noIndentBasedFolding() const { return m_flags & KateTextLine::flagNoIndentationBasedFolding; }
00269 inline bool noIndentBasedFoldingAtStart() const { return m_flags & KateTextLine::flagNoIndentationBasedFoldingAtStart; }
00274 inline const QVector<int> &foldingListArray () const { return m_foldingList; }
00275
00280 inline const QVector<unsigned short> &indentationDepthArray () const { return m_indentationDepth; }
00281
00287 void insertText (int pos, const QString& insText);
00288
00294 void removeText (uint pos, uint delLen);
00295
00300 void truncate(int newLen);
00301
00306 inline void setHlLineContinue (bool cont)
00307 {
00308 if (cont) m_flags = m_flags | KateTextLine::flagHlContinue;
00309 else m_flags = m_flags & ~ KateTextLine::flagHlContinue;
00310 }
00311
00316 inline void setAutoWrapped (bool wrapped)
00317 {
00318 if (wrapped) m_flags = m_flags | KateTextLine::flagAutoWrapped;
00319 else m_flags = m_flags & ~ KateTextLine::flagAutoWrapped;
00320 }
00321
00326 inline void setContext (QVector<short> &val) { m_ctx = val; }
00327
00331 inline void setNoIndentBasedFolding(bool val)
00332 {
00333 if (val) m_flags = m_flags | KateTextLine::flagNoIndentationBasedFolding;
00334 else m_flags = m_flags & ~ KateTextLine::flagNoIndentationBasedFolding;
00335 }
00336
00337 inline void setNoIndentBasedFoldingAtStart(bool val)
00338 {
00339 if (val) m_flags = m_flags | KateTextLine::flagNoIndentationBasedFoldingAtStart;
00340 else m_flags = m_flags & ~ KateTextLine::flagNoIndentationBasedFoldingAtStart;
00341 }
00342
00347 inline void setFoldingList (QVector<int> &val) { m_foldingList = val; }
00348
00353 inline void setIndentationDepth (QVector<unsigned short> &val) { m_indentationDepth = val; }
00354
00358 public:
00359 void addAttribute (int start, int length, int attribute);
00360
00361 void clearAttributes () { m_attributesList.clear (); }
00362
00363 const QVector<int> &attributesList () const { return m_attributesList; }
00364
00368 private:
00372 QString m_text;
00373
00378 QVector<int> m_attributesList;
00379
00383 QVector<short> m_ctx;
00384
00388 QVector<int> m_foldingList;
00389
00393 QVector<unsigned short> m_indentationDepth;
00394
00398 uchar m_flags;
00399 };
00400
00401 #endif
00402
00403