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
#include <qvaluevector.h>
00031
00040 class TextLine :
public KShared
00041 {
00042
public:
00043
typedef KSharedPtr<TextLine> Ptr;
00044
typedef QValueVector<Ptr> List;
00045
00046
public:
00051
TextLine ();
00052 ~
TextLine ();
00053
00057
public:
00061 inline uint
length()
const {
return m_text.
length(); }
00062
00066 inline bool hlLineContinue ()
const {
return m_flags & TextLine::flagHlContinue; }
00067
00068
inline bool isVisible ()
const {
return m_flags & TextLine::flagVisible; }
00069
00070
inline bool isAutoWrapped ()
const {
return m_flags & TextLine::flagAutoWrapped; }
00071
00075
int firstChar() const;
00076
00080
int lastChar() const;
00081
00089
int nextNonSpaceChar(uint pos) const;
00090
00098
int previousNonSpaceChar(uint pos) const;
00099
00103 inline
QChar getChar (uint pos)
const
00104
{
00105
return m_text[pos];
00106 }
00107
00111 inline const QChar *
text()
const {
return m_text.
unicode(); };
00112
00113
inline uchar *attributes ()
const {
return m_attributes.
data(); }
00114
00118 inline const QString&
string()
const {
return m_text; };
00119
00123 inline QString string(uint startCol, uint length)
const {
return m_text.
mid(startCol, length); };
00124
inline QConstString constString(uint startCol, uint length)
const {
return QConstString(m_text.
unicode() + startCol, length); };
00125
00126
00127
00128
00129
const QChar *firstNonSpace() const;
00130
00131 uint indentDepth (uint tabwidth) const;
00132
00137
int cursorX(uint pos, uint tabChars) const;
00138
00142
bool stringAtPos(uint pos, const
QString& match) const;
00143
00147
bool startingWith(const
QString& match) const;
00148
00152
bool endingWith(const
QString& match) const;
00153
00157 inline
short *ctx ()
const {
return m_ctx.
data (); };
00158
00162 inline bool ctxSize ()
const {
return m_ctx.
size (); };
00163
00167 inline bool ctxEmpty ()
const {
return m_ctx.
isEmpty (); };
00168
00169
bool searchText (uint startCol,
const QString &text, uint *foundAtCol, uint *matchLen,
bool casesensitive =
true,
bool backwards =
false);
00170
bool searchText (uint startCol,
const QRegExp ®exp, uint *foundAtCol, uint *matchLen,
bool backwards =
false);
00171
00175 inline uchar
attribute (uint pos)
const
00176
{
00177
if (pos < m_text.
length())
return m_attributes[pos];
00178
return 0;
00179 }
00180
00184 inline const QString &
textArray ()
const {
return m_text; };
00185
inline const QMemArray<uchar> &attributesArray ()
const {
return m_attributes; };
00186
inline const QMemArray<short> &ctxArray ()
const {
return m_ctx; };
00187
inline const QMemArray<signed char> &foldingListArray ()
const {
return m_foldingList; };
00188
inline const QMemArray<unsigned short> &indentationDepthArray ()
const {
return m_indentationDepth; };
00189
00193
public:
00197
void insertText (uint pos, uint insLen,
const QChar *insText, uchar *insAttribs = 0);
00198
void removeText (uint pos, uint delLen);
00199
00203
void append(
const QChar *s, uint l);
00204
00208
void truncate(uint newLen);
00209
00213
QString withoutTrailingSpaces();
00214
00218 inline void setHlLineContinue (
bool cont)
00219 {
00220
if (cont) m_flags = m_flags | TextLine::flagHlContinue;
00221
else m_flags = m_flags & ~ TextLine::flagHlContinue;
00222 }
00223
00224
inline void setVisible(
bool val)
00225 {
00226
if (val) m_flags = m_flags | TextLine::flagVisible;
00227
else m_flags = m_flags & ~ TextLine::flagVisible;
00228 }
00229
00230
inline void setAutoWrapped (
bool wrapped)
00231 {
00232
if (wrapped) m_flags = m_flags | TextLine::flagAutoWrapped;
00233
else m_flags = m_flags & ~ TextLine::flagAutoWrapped;
00234 }
00235
00239
void setAttribs(uchar attribute, uint start, uint end);
00240
00244 inline void setContext(
short *newctx, uint len)
00245 {
00246 m_ctx.
duplicate (newctx, len);
00247 }
00248
00249
inline void setFoldingList (
QMemArray<signed char> &val)
00250 {
00251 m_foldingList=val;
00252 m_foldingList.
detach();
00253 }
00254
00255
inline void setIndentationDepth (
QMemArray<unsigned short> &val)
00256 {
00257 m_indentationDepth = val;
00258 m_indentationDepth.
detach();
00259 }
00260
00264
public:
00268 uint
dumpSize () const;
00269
00274
char *dump (
char *buf) const;
00275
00280
char *restore (
char *buf);
00281
00282 enum Flags
00283 {
00284 flagNoOtherData = 0x1,
00285 flagHlContinue = 0x2,
00286 flagVisible = 0x4,
00287 flagAutoWrapped = 0x8
00288 };
00289
00293
private:
00297
QString m_text;
00298
QMemArray<uchar> m_attributes;
00299
00303
QMemArray<short> m_ctx;
00304
QMemArray<signed char> m_foldingList;
00305
QMemArray<unsigned short> m_indentationDepth;
00306
00310 uchar m_flags;
00311 };
00312
00313
#endif