89 fString = new char[fLength+1];
90 strncpy(fString, tl.fString, fLength);
148 char *newstring =
new char[
fLength - length+1];
165 char *newstring =
new char[strlen(
text)+
fLength+1];
169 strcpy(newstring+pos,
text);
193 char *retstring =
new char[length+1];
194 retstring[length] =
'\0';
223 }
else if (isalnum(
fString[i])) {
230 if (isalnum(
fString[end])) ++end;
252 char *retstring =
new char[length+1];
253 retstring[length] =
'\0';
272 newstring[pos-1] = 0;
286 newstring =
new char[
fLength+2];
290 newstring[pos] = character;
374 end.
fY =
text->RowCount() - 1;
375 end.
fX =
text->GetLineLength(end.
fY) - 1;
408 while (travel != 0) {
410 travel = travel->
fNext;
433 Long_t count, charcount, i, cnt;
435 char *buf,
c, *src, *dst, *buffer, *buf2;
440 if (!(fp = fopen(fn,
"r")))
return kFALSE;
443 fseek(fp, startpos, SEEK_SET);
445 while (fgets(buf,
kMaxLen, fp)) {
446 if ((length != -1) && (charcount+(
Int_t)strlen(buf) > length)) {
447 count = length - charcount;
451 charcount += strlen(buf);
452 buf2 =
new char[count+1];
457 while ((
c = *src++)) {
459 if (
c == 0x0D ||
c == 0x0A)
462 else if (
c == 0x09) {
464 while (((dst-buf2) & 0x7) && (cnt++ < count-1))
468 if (cnt++ >= count-1)
break;
472 const size_t bufferSize = strlen(buf2)+1;
473 buffer =
new char[bufferSize];
474 strlcpy(buffer, buf2, bufferSize);
475 temp->fLength = strlen(buf2);
476 temp->fString = buffer;
477 temp->fNext = temp->fPrev = 0;
485 travel->
fNext = temp;
486 temp->fPrev = travel;
487 travel = travel->
fNext;
517 char *buf,
c, *src, *dst, *buffer, *buf2, *s;
518 const char *tbuf = txtbuf;
522 if (!tbuf || !tbuf[0])
528 if ((s = (
char*)strchr(tbuf,
'\n'))) {
534 strncpy(buf, tbuf, s-tbuf+1);
549 while ((
c = *src++)) {
551 if (
c == 0x0D ||
c == 0x0A)
554 else if (
c == 0x09) {
556 while (((dst-buf2) & 0x7) && (cnt++ <
kMaxLen-1))
564 const size_t bufferSize = strlen(buf2) + 1;
565 buffer =
new char[bufferSize];
566 strlcpy(buffer, buf2, bufferSize);
567 temp->fLength = strlen(buf2);
568 temp->fString = buffer;
569 temp->fNext = temp->fPrev = 0;
577 travel->
fNext = temp;
578 temp->fPrev = travel;
579 travel = travel->
fNext;
585 if (!lastnl && !*tbuf && *(tbuf-1) ==
'\n') {
590 if (!finished && strlen(tbuf))
613 if (!(fp = fopen(fn,
"w")))
return kFALSE;
617 buffer =
new char[travel->
fLength+2];
619 buffer[travel->
fLength] =
'\n';
620 buffer[travel->
fLength+1] =
'\0';
621 while (buffer[i] !=
'\0') {
622 if (buffer[i] ==
'\t') {
624 while (buffer[j] == 16)
627 strcpy(buffer+i+1, buffer+j);
631 if (fputs(buffer, fp) == EOF) {
637 travel = travel->
fNext;
654 if (!(fp = fopen(fn,
"a")))
return kFALSE;
658 buffer =
new char[travel->
fLength+2];
660 buffer[travel->
fLength] =
'\n';
661 buffer[travel->
fLength+1] =
'\0';
662 while (buffer[i] !=
'\0') {
663 if (buffer[i] ==
'\t') {
665 while (buffer[j] == 16 && buffer[j] !=
'\0')
668 strcpy(buffer+i+1, buffer+j);
672 if (fputs(buffer, fp) == EOF) {
678 travel = travel->
fNext;
691 if ((pos.fY >=
fRowCount) || (pos.fY < 0))
707 if ((pos.fY >=
fRowCount) || (pos.fY < 0) || (pos.fX < 0))
764 delete [] tempbuffer;
821 if (start_src.
fY == end_src.
fY) {
822 len = end_src.
fX - start_src.
fX+1;
828 lineString = src->
GetLine(start_src, len);
830 delete [] lineString;
833 pos.fY = start_src.
fY+1;
835 for ( ; pos.fY < end_src.
fY; pos.fY++) {
837 lineString = src->
GetLine(pos, llen > 0 ? llen : 0);
843 delete [] lineString;
846 if (start_src.
fY != end_src.
fY) {
849 lineString = src->
GetLine(pos, end_src.
fX+1);
855 delete [] lineString;
860 if (ins_pos.
fX == 0) {
869 delete [] restString;
915 start_src.
fX = start_src.
fY = 0;
916 end_src.
fY =
text->RowCount()-1;
917 end_src.
fX =
text->GetLineLength(end_src.
fY)-1;
942 newline->
fPrev = previous;
944 previous->
fNext = newline;
998 return fCurrent->GetText(pos.fX, length);
1019 delete [] tempbuffer;
1027 temp->fNext->fPrev = temp;
1096 while (buffer[i] !=
'\0') {
1097 if (buffer[i] ==
'\t') {
1099 while (buffer[j] == 16 && buffer[j] !=
'\0') {
1103 strcpy(buffer+i+1, buffer+j);
1108 char c, *src, *dst, *buf2;
1116 while ((
c = *src++)) {
1120 while (((dst-buf2) & 0x7) && (cnt++ <
kMaxLen-1)) {
1126 if (cnt++ >=
kMaxLen-1)
break;
1142 const char *searchString,
1167 for (
int i = (
int)
start.fX; i >= 0; i--) {
1203 if (!
Search(&foundPos,
start, oldText, direction, caseSensitive)) {
1208 delEnd.
fY = foundPos.
fY;
1209 delEnd.
fX = foundPos.
fX + strlen(oldText) - 1;
1228 travel = travel->
fNext;
1249 char *txt = travel->
GetText();
1251 travel = travel->
fNext;
1252 if (travel)
ret +=
'\n';
int Int_t
Signed integer 4 bytes (int).
int Ssiz_t
String size (currently int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
bool Bool_t
Boolean (0=false, 1=true) (bool).
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
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).
TGTextLine(const TGTextLine &)
copy constructor
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
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.
TGText(const TGText &)
copy constructor
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