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 <qmemarray.h>
00029
#include <qstring.h>
00030
00038 class KateTextLine :
public KShared
00039 {
00040
public:
00044 typedef KSharedPtr<KateTextLine> Ptr;
00045
00046
public:
00050 enum Flags
00051 {
00052 flagNoOtherData = 0x1,
00053 flagHlContinue = 0x2,
00054 flagVisible = 0x4,
00055 flagAutoWrapped = 0x8
00056 };
00057
00058
public:
00064
KateTextLine ();
00065
00069
~KateTextLine ();
00070
00074
public:
00079 inline uint
length()
const {
return m_text.length(); }
00080
00085 inline bool hlLineContinue ()
const {
return m_flags & KateTextLine::flagHlContinue; }
00086
00091 inline bool isVisible ()
const {
return m_flags & KateTextLine::flagVisible; }
00092
00097 inline bool isAutoWrapped ()
const {
return m_flags & KateTextLine::flagAutoWrapped; }
00098
00103
int firstChar() const;
00104
00109
int lastChar() const;
00110
00117
int nextNonSpaceChar(uint pos) const;
00118
00125
int previousNonSpaceChar(uint pos) const;
00126
00133 inline
QChar getChar (uint pos)
const {
return m_text[pos]; }
00134
00139 inline const QChar *
text()
const {
return m_text.unicode(); }
00140
00145 inline uchar *
attributes ()
const {
return m_attributes.data(); }
00146
00151 inline const QString&
string()
const {
return m_text; }
00152
00159 inline QString string(uint startCol, uint length)
const
00160
{
return m_text.mid(startCol, length); }
00161
00168 inline QConstString constString(uint startCol, uint length)
const
00169
{
return QConstString(m_text.unicode() + startCol, length); }
00170
00175
const QChar *
firstNonSpace() const;
00176
00182 uint indentDepth (uint tabwidth) const;
00183
00191
int cursorX(uint pos, uint tabChars) const;
00192
00198 uint lengthWithTabs (uint tabChars) const;
00199
00206
bool stringAtPos(uint pos, const
QString& match) const;
00207
00213
bool startingWith(const
QString& match) const;
00214
00220
bool endingWith(const
QString& match) const;
00221
00232
bool searchText (uint startCol, const
QString &text,
00233 uint *foundAtCol, uint *matchLen,
00234
bool casesensitive = true,
00235
bool backwards = false);
00236
00246
bool searchText (uint startCol, const
QRegExp ®exp,
00247 uint *foundAtCol, uint *matchLen,
00248
bool backwards = false);
00249
00255 inline uchar attribute (uint pos)
const
00256
{
00257
if (pos < m_attributes.size())
return m_attributes[pos];
00258
return 0;
00259 }
00260
00265 inline const QMemArray<short> &
ctxArray ()
const {
return m_ctx; };
00266
00271 inline const QMemArray<signed char> &
foldingListArray ()
const {
return m_foldingList; };
00272
00277 inline const QMemArray<unsigned short> &
indentationDepthArray ()
const {
return m_indentationDepth; };
00278
00286
void insertText (uint pos, uint insLen,
const QChar *insText, uchar *insAttribs = 0);
00287
00293
void removeText (uint pos, uint delLen);
00294
00299
void truncate(uint newLen);
00300
00305 inline void setHlLineContinue (
bool cont)
00306 {
00307
if (cont) m_flags = m_flags | KateTextLine::flagHlContinue;
00308
else m_flags = m_flags & ~ KateTextLine::flagHlContinue;
00309 }
00310
00315 inline void setVisible(
bool val)
00316 {
00317
if (val) m_flags = m_flags | KateTextLine::flagVisible;
00318
else m_flags = m_flags & ~ KateTextLine::flagVisible;
00319 }
00320
00325 inline void setAutoWrapped (
bool wrapped)
00326 {
00327
if (wrapped) m_flags = m_flags | KateTextLine::flagAutoWrapped;
00328
else m_flags = m_flags & ~ KateTextLine::flagAutoWrapped;
00329 }
00330
00337
void setAttribs(uchar attribute, uint start, uint end);
00338
00343 inline void setContext (
QMemArray<short> &val) { m_ctx.assign (val); }
00344
00349 inline void setFoldingList (
QMemArray<signed char> &val) { m_foldingList.assign (val); m_foldingList.detach(); }
00350
00355 inline void setIndentationDepth (
QMemArray<unsigned short> &val) { m_indentationDepth.assign (val); }
00356
00360
public:
00366 inline uint
dumpSize (
bool withHighlighting)
const
00367
{
00368
return ( 1
00369 +
sizeof(uint)
00370 + (m_text.length() *
sizeof(
QChar))
00371 + ( withHighlighting ?
00372 ( (3 *
sizeof(uint))
00373 + (m_text.length() *
sizeof(uchar))
00374 + (m_ctx.size() *
sizeof(
short))
00375 + (m_foldingList.size() *
sizeof(
signed char))
00376 + (m_indentationDepth.size() *
sizeof(
unsigned short))
00377 ) : 0
00378 )
00379 );
00380 }
00381
00389
char *
dump (
char *buf,
bool withHighlighting)
const;
00390
00397
char *
restore (
char *buf);
00398
00402
private:
00406
QString m_text;
00407
00411
QMemArray<uchar> m_attributes;
00412
00416
QMemArray<short> m_ctx;
00417
00421
QMemArray<signed char> m_foldingList;
00422
00426
QMemArray<unsigned short> m_indentationDepth;
00427
00431 uchar m_flags;
00432 };
00433
00434
#endif
00435
00436