23 #include "katetextline.h"
24 #include "katerenderer.h"
26 #include <tdeglobal.h>
46 uint oldTextLen = m_text.length();
47 m_text.insert (pos, insText, insLen);
48 uint textLen = m_text.length();
51 m_attributes.resize (textLen);
54 if (pos >= oldTextLen)
56 for (uint z = oldTextLen; z < pos; z++)
60 else if (oldTextLen > 0)
62 for (
int z = oldTextLen -1; z >= (int) pos; z--)
63 m_attributes[z+insLen] = m_attributes[z];
67 for (uint z = 0; z < insLen; z++)
70 m_attributes[z+pos] = 0;
72 m_attributes[z+pos] = insAttribs[z];
82 uint textLen = m_text.length();
90 if ((pos + delLen) > textLen)
91 delLen = textLen - pos;
94 for (uint z = pos; z < textLen - delLen; z++)
95 m_attributes[z] = m_attributes[z+delLen];
97 m_text.remove (pos, delLen);
98 m_attributes.resize (m_text.length ());
103 if (newLen < m_text.length())
105 m_text.truncate (newLen);
106 m_attributes.truncate (newLen);
112 const uint len = m_text.length();
113 const TQChar *unicode = m_text.unicode();
115 for(uint i = pos; i < len; i++)
117 if(!unicode[i].isSpace())
126 const int len = m_text.length();
128 if (pos >= (uint)len)
131 const TQChar *unicode = m_text.unicode();
133 for(
int i = pos; i >= 0; i--)
135 if(!unicode[i].isSpace())
155 return (first > -1) ? ((TQChar*)m_text.unicode())+first : m_text.unicode();
161 const uint len = m_text.length();
162 const TQChar *unicode = m_text.unicode();
164 for(uint i = 0; i < len; i++)
166 if(unicode[i].isSpace())
168 if (unicode[i] == TQChar(
'\t'))
169 d += tabwidth - (d % tabwidth);
182 const uint len = m_text.length();
183 const uint matchlen = match.length();
185 if ((pos+matchlen) > len)
192 const TQChar *unicode = m_text.unicode();
193 const TQChar *matchUnicode = match.unicode();
195 for (uint i=0; i < matchlen; i++)
196 if (unicode[i+pos] != matchUnicode[i])
204 const uint matchlen = match.length();
206 if (matchlen > m_text.length())
209 const TQChar *unicode = m_text.unicode();
210 const TQChar *matchUnicode = match.unicode();
212 for (uint i=0; i < matchlen; i++)
213 if (unicode[i] != matchUnicode[i])
221 const uint matchlen = match.length();
223 if (matchlen > m_text.length())
226 const TQChar *unicode = m_text.unicode();
227 const TQChar *matchUnicode = match.unicode();
229 uint start = m_text.length() - matchlen;
230 for (uint i=0; i < matchlen; i++)
231 if (unicode[start+i] != matchUnicode[i])
241 const uint n = kMin (pos, (uint)m_text.length());
242 const TQChar *unicode = m_text.unicode();
244 for ( uint z = 0; z < n; z++)
246 if (unicode[z] == TQChar(
'\t'))
247 x += tabChars - (x % tabChars);
259 const uint len = m_text.length();
260 const TQChar *unicode = m_text.unicode();
262 for ( uint z = 0; z < len; z++)
264 if (unicode[z] == TQChar(
'\t'))
265 x += tabChars - (x % tabChars);
273 bool KateTextLine::searchText (uint startCol,
const TQString &text, uint *foundAtCol, uint *matchLen,
bool casesensitive,
bool backwards)
280 uint l = text.length();
282 if ( col == (
int) m_text.length() ) ++startCol;
285 index = m_text.findRev( text, col, casesensitive );
287 }
while ( col >= 0 && l + index >= startCol );
290 index = m_text.find (text, startCol, casesensitive);
295 (*foundAtCol) = index;
297 (*matchLen)=text.length();
313 if ( col == (
int) m_text.length() ) ++startCol;
315 index = regexp.searchRev (m_text, col);
317 }
while ( col >= 0 && regexp.matchedLength() + index >= (int)startCol );
320 index = regexp.search (m_text, startCol);
325 (*foundAtCol) = index;
328 (*matchLen)=regexp.matchedLength();
337 uint l = m_text.length();
340 if (!withHighlighting)
341 f = f | KateTextLine::flagNoOtherData;
343 memcpy(buf, (
char *) &f, 1);
346 memcpy(buf, &l,
sizeof(uint));
349 memcpy(buf, (
char *) m_text.unicode(),
sizeof(TQChar)*l);
350 buf +=
sizeof(TQChar) * l;
352 if (!withHighlighting)
355 memcpy(buf, (
char *)m_attributes.data(),
sizeof(uchar) * l);
356 buf +=
sizeof (uchar) * l;
358 uint lctx = m_ctx.size();
359 uint lfold = m_foldingList.size();
360 uint lind = m_indentationDepth.size();
362 memcpy(buf, &lctx,
sizeof(uint));
365 memcpy(buf, &lfold,
sizeof(uint));
368 memcpy(buf, &lind,
sizeof(uint));
371 memcpy(buf, (
char *)m_ctx.data(),
sizeof(short) * lctx);
372 buf +=
sizeof (short) * lctx;
374 memcpy(buf, (
char *)m_foldingList.data(),
sizeof(uint)*lfold);
375 buf +=
sizeof (uint) * lfold;
377 memcpy(buf, (
char *)m_indentationDepth.data(),
sizeof(
unsigned short) * lind);
378 buf +=
sizeof (
unsigned short) * lind;
388 memcpy((
char *) &f, buf, 1);
392 memcpy((
char *) &l, buf,
sizeof(uint));
396 m_text.setUnicode ((TQChar *) buf, l);
397 buf +=
sizeof(TQChar) * l;
400 if (f & KateTextLine::flagNoOtherData)
404 if (f & KateTextLine::flagAutoWrapped)
405 m_flags = m_flags | KateTextLine::flagAutoWrapped;
408 m_attributes.fill (0, l);
415 m_attributes.duplicate ((uchar *) buf, l);
416 buf +=
sizeof(uchar) * l;
422 memcpy((
char *) &lctx, buf,
sizeof(uint));
425 memcpy((
char *) &lfold, buf,
sizeof(uint));
428 memcpy((
char *) &lind, buf,
sizeof(uint));
431 m_ctx.duplicate ((
short *) buf, lctx);
432 buf +=
sizeof(short) * lctx;
434 m_foldingList.duplicate ((uint *) buf, lfold);
435 buf +=
sizeof(uint)*lfold;
437 m_indentationDepth.duplicate ((
unsigned short *) buf, lind);
438 buf +=
sizeof(
unsigned short) * lind;
int cursorX(uint pos, uint tabChars) const
Returns the x position of the cursor at the given position, which depends on the number of tab charac...
bool endingWith(const TQString &match) const
Is the line ending with the given string.
char * dump(char *buf, bool withHighlighting) const
Dumps the line to *buf and counts buff dumpSize bytes up as return value.
bool searchText(uint startCol, const TQString &text, uint *foundAtCol, uint *matchLen, bool casesensitive=true, bool backwards=false)
search given string
uint lengthWithTabs(uint tabChars) const
Returns the text length with tabs calced in.
void removeText(uint pos, uint delLen)
remove text at given position
char * restore(char *buf)
Restores the line from *buf and counts buff dumpSize bytes up as return value.
int nextNonSpaceChar(uint pos) const
Find the position of the next char that is not a space.
void insertText(uint pos, uint insLen, const TQChar *insText, uchar *insAttribs=0)
insert text into line
int lastChar() const
Returns the position of the last non-whitespace character.
int previousNonSpaceChar(uint pos) const
Find the position of the previous char that is not a space.
const TQChar * firstNonSpace() const
Gets a null terminated pointer to first non space char.
KateTextLine()
Constructor Creates an empty text line with given attribute and syntax highlight context.
bool stringAtPos(uint pos, const TQString &match) const
Can we find the given string at the given position.
bool startingWith(const TQString &match) const
Is the line starting with the given string.
int firstChar() const
Returns the position of the first non-whitespace character.
~KateTextLine()
Destructor.
void truncate(uint newLen)
Truncates the textline to the new length.
uint indentDepth(uint tabwidth) const
indentation depth of this line