86 fPrev(tl.fPrev), fNext(tl.fNext)
149 char *newstring =
new char[
fLength - length+1];
166 char *newstring =
new char[strlen(
text)+
fLength+1];
170 strcpy(newstring+pos,
text);
194 char *retstring =
new char[length+1];
195 retstring[length] =
'\0';
224 }
else if (isalnum(
fString[i])) {
226 if (isalnum(
fString[start])) --start;
231 if (isalnum(
fString[end])) ++end;
253 char *retstring =
new char[length+1];
254 retstring[length] =
'\0';
255 strncpy(retstring,
fString+start, length);
273 newstring[pos-1] = 0;
287 newstring =
new char[
fLength+2];
291 newstring[pos] = character;
317 fFilename(gt.fFilename),
318 fIsSaved(gt.fIsSaved),
320 fCurrent(gt.fCurrent),
321 fCurrentRow(gt.fCurrentRow),
322 fRowCount(gt.fRowCount),
323 fColCount(gt.fColCount),
324 fLongestLine(gt.fLongestLine)
376 end.
fY =
text->RowCount() - 1;
377 end.
fX =
text->GetLineLength(end.
fY) - 1;
410 while (travel != 0) {
412 travel = travel->
fNext;
435 Long_t count, charcount, i, cnt;
437 char *buf,
c, *src, *dst, *buffer, *buf2;
442 if (!(fp = fopen(fn,
"r")))
return kFALSE;
445 fseek(fp, startpos, SEEK_SET);
447 while (fgets(buf,
kMaxLen, fp)) {
448 if ((length != -1) && (charcount+(
Int_t)strlen(buf) > length)) {
449 count = length - charcount;
453 charcount += strlen(buf);
454 buf2 =
new char[count+1];
459 while ((
c = *src++)) {
461 if (
c == 0x0D ||
c == 0x0A)
464 else if (
c == 0x09) {
466 while (((dst-buf2) & 0x7) && (cnt++ < count-1))
470 if (cnt++ >= count-1)
break;
474 const size_t bufferSize = strlen(buf2)+1;
475 buffer =
new char[bufferSize];
476 strlcpy(buffer, buf2, bufferSize);
487 travel->
fNext = temp;
488 temp->
fPrev = travel;
489 travel = travel->
fNext;
519 char *buf,
c, *src, *dst, *buffer, *buf2, *s;
520 const char *tbuf = txtbuf;
524 if (!tbuf || !tbuf[0])
530 if ((s = (
char*)strchr(tbuf,
'\n'))) {
536 strncpy(buf, tbuf, s-tbuf+1);
551 while ((
c = *src++)) {
553 if (
c == 0x0D ||
c == 0x0A)
556 else if (
c == 0x09) {
558 while (((dst-buf2) & 0x7) && (cnt++ <
kMaxLen-1))
566 const size_t bufferSize = strlen(buf2) + 1;
567 buffer =
new char[bufferSize];
568 strlcpy(buffer, buf2, bufferSize);
579 travel->
fNext = temp;
580 temp->
fPrev = travel;
581 travel = travel->
fNext;
587 if (!lastnl && !*tbuf && *(tbuf-1) ==
'\n') {
592 if (!finished && strlen(tbuf))
615 if (!(fp = fopen(fn,
"w")))
return kFALSE;
619 buffer =
new char[travel->
fLength+2];
621 buffer[travel->
fLength] =
'\n';
622 buffer[travel->
fLength+1] =
'\0';
623 while (buffer[i] !=
'\0') {
624 if (buffer[i] ==
'\t') {
626 while (buffer[j] == 16)
629 strcpy(buffer+i+1, buffer+j);
633 if (fputs(buffer, fp) == EOF) {
639 travel = travel->
fNext;
656 if (!(fp = fopen(fn,
"a")))
return kFALSE;
660 buffer =
new char[travel->
fLength+2];
662 buffer[travel->
fLength] =
'\n';
663 buffer[travel->
fLength+1] =
'\0';
664 while (buffer[i] !=
'\0') {
665 if (buffer[i] ==
'\t') {
667 while (buffer[j] == 16 && buffer[j] !=
'\0')
670 strcpy(buffer+i+1, buffer+j);
674 if (fputs(buffer, fp) == EOF) {
680 travel = travel->
fNext;
751 if (start.
fY == end.
fY) {
757 for (
Long_t i = start.
fY+1; i < end.
fY; i++) {
766 delete [] tempbuffer;
823 if (start_src.
fY == end_src.
fY) {
824 len = end_src.
fX - start_src.
fX+1;
830 lineString = src->
GetLine(start_src, len);
832 delete [] lineString;
835 pos.
fY = start_src.
fY+1;
837 for ( ; pos.
fY < end_src.
fY; pos.
fY++) {
839 lineString = src->
GetLine(pos, llen > 0 ? llen : 0);
845 delete [] lineString;
848 if (start_src.
fY != end_src.
fY) {
851 lineString = src->
GetLine(pos, end_src.
fX+1);
857 delete [] lineString;
862 if (ins_pos.
fX == 0) {
871 delete [] restString;
917 start_src.
fX = start_src.
fY = 0;
918 end_src.
fY =
text->RowCount()-1;
919 end_src.
fX =
text->GetLineLength(end_src.
fY)-1;
944 newline->
fPrev = previous;
946 previous->
fNext = newline;
1021 delete [] tempbuffer;
1098 while (buffer[i] !=
'\0') {
1099 if (buffer[i] ==
'\t') {
1101 while (buffer[j] == 16 && buffer[j] !=
'\0') {
1105 strcpy(buffer+i+1, buffer+j);
1110 char c, *src, *dst, *buf2;
1118 while ((
c = *src++)) {
1122 while (((dst-buf2) & 0x7) && (cnt++ <
kMaxLen-1)) {
1128 if (cnt++ >=
kMaxLen-1)
break;
1144 const char *searchString,
1169 for (
int i = (
int)start.
fX; i >= 0; i--) {
1172 if (
x >= start.
fX) {
1205 if (!
Search(&foundPos, start, oldText, direction, caseSensitive)) {
1210 delEnd.
fY = foundPos.
fY;
1211 delEnd.
fX = foundPos.
fX + strlen(oldText) - 1;
1230 travel = travel->
fNext;
1251 char *txt = travel->
GetText();
1253 travel = travel->
fNext;
1254 if (travel) ret +=
'\n';
virtual ~TGTextLine()
Delete a line of text.
TGTextLine * fPrev
previous line
char * fString
line of text
void DelChar(ULong_t pos)
Delete a character from the line.
void InsChar(ULong_t pos, char character)
Insert a character at the specified position.
char GetChar(ULong_t pos)
Get a character at the specified position from the line.
char * GetWord(ULong_t pos)
Get word at position. Returned string must be deleted.
void InsText(ULong_t pos, const char *text)
Insert text in line starting at position pos.
TGTextLine * fNext
next line
void Clear()
Clear a line of text.
TGTextLine()
Create empty line of text (default ctor).
void DelText(ULong_t pos, ULong_t length)
Delete length chars from line starting at position pos.
ULong_t fLength
length of line
char * GetText(ULong_t pos, ULong_t length)
Get length characters from line starting at pos.
TGTextLine & operator=(const TGTextLine &)
assignment operator
A TGText is a multi line text buffer.
Bool_t InsChar(TGLongPosition pos, char c)
Insert character c at the specified position pos.
void ReTab(Long_t row)
Redo all tabs in a line. Needed after a new tab is inserted.
virtual ~TGText()
Destroy text buffer.
Long_t fColCount
number of columns in current line
Bool_t AddText(TGText *text)
Add another text buffer to this buffer.
TGTextLine * fFirst
first line of text
Bool_t DelText(TGLongPosition start, TGLongPosition end)
Delete text between start and end positions.
TString fFilename
name of opened file ("" if open buffer)
TGText()
Create default (empty) text buffer.
Long_t fLongestLine
length of longest line
Long_t fRowCount
number of rows
Bool_t fIsSaved
false if text needs to be saved
void LongestLine()
Set fLongestLine.
Bool_t Search(TGLongPosition *foundPos, TGLongPosition start, const char *searchString, Bool_t direction, Bool_t caseSensitive)
Search for string searchString starting at the specified position going in forward (direction = true)...
Bool_t DelLine(ULong_t pos)
Delete specified row. Returns false if row does not exist.
Bool_t Save(const char *fn)
Save text buffer to file fn.
Bool_t Replace(TGLongPosition start, const char *oldText, const char *newText, Bool_t direction, Bool_t caseSensitive)
Replace oldText by newText. Returns false if nothing replaced.
Bool_t InsLine(ULong_t row, const char *string)
Insert string before specified position.
Bool_t SetCurrentRow(Long_t row)
Make specified row the current row.
Long_t fCurrentRow
current row number
Bool_t DelChar(TGLongPosition pos)
Delete character at specified position pos.
Bool_t BreakLine(TGLongPosition pos)
Break line at position pos. Returns false if pos is not valid.
Bool_t InsText(TGLongPosition pos, const char *buf)
Insert single line at specified position.
char * GetLine(TGLongPosition pos, ULong_t length)
Return string at position pos.
TGTextLine * fCurrent
current line
char GetChar(TGLongPosition pos)
Get character a position pos. If character not valid return -1.
Bool_t Load(const char *fn, Long_t startpos=0, Long_t length=-1)
Load text from file fn.
Bool_t LoadBuffer(const char *txtbuf)
Load a 0 terminated buffer. Lines will be split at ' '.
void Clear()
Clear text buffer.
Bool_t Append(const char *fn)
Append buffer to file fn.
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
void Init()
Common initialization method.
TString AsString()
Returns content as ROOT string.
TGText & operator=(const TGText &)
assignment operator
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const