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';
195 strncpy(retstring, fString+pos, (
UInt_t)length);
223 }
else if (isalnum(
fString[i])) {
225 if (isalnum(
fString[start])) --start;
230 if (isalnum(
fString[end])) ++end;
252 char *retstring =
new char[length+1];
253 retstring[length] =
'\0';
254 strncpy(retstring,
fString+start, length);
272 newstring[pos-1] = 0;
286 newstring =
new char[
fLength+2];
290 newstring[pos] = character;
316 fFilename(gt.fFilename),
317 fIsSaved(gt.fIsSaved),
319 fCurrent(gt.fCurrent),
320 fCurrentRow(gt.fCurrentRow),
321 fRowCount(gt.fRowCount),
322 fColCount(gt.fColCount),
323 fLongestLine(gt.fLongestLine)
409 while (travel != 0) {
411 travel = travel->
fNext;
436 char *buf, c, *src, *dst, *buffer, *buf2;
441 if (!(fp = fopen(fn,
"r")))
return kFALSE;
444 fseek(fp, startpos, SEEK_SET);
446 while (fgets(buf,
kMaxLen, fp)) {
447 if ((length != -1) && (charcount+(
Int_t)strlen(buf) > length)) {
448 count = length - charcount;
452 charcount += strlen(buf);
453 buf2 =
new char[count+1];
458 while ((c = *src++)) {
460 if (c == 0x0D || c == 0x0A)
463 else if (c == 0x09) {
465 while (((dst-buf2) & 0x7) && (cnt++ < count-1))
469 if (cnt++ >= count-1)
break;
473 const size_t bufferSize = strlen(buf2)+1;
474 buffer =
new char[bufferSize];
475 strlcpy(buffer, buf2, bufferSize);
486 travel->
fNext = temp;
487 temp->
fPrev = travel;
488 travel = travel->
fNext;
518 char *buf, c, *src, *dst, *buffer, *buf2, *s;
519 const char *tbuf = txtbuf;
523 if (!tbuf || !tbuf[0])
529 if ((s = (
char*)strchr(tbuf,
'\n'))) {
535 strncpy(buf, tbuf, s-tbuf+1);
550 while ((c = *src++)) {
552 if (c == 0x0D || c == 0x0A)
555 else if (c == 0x09) {
557 while (((dst-buf2) & 0x7) && (cnt++ <
kMaxLen-1))
565 const size_t bufferSize = strlen(buf2) + 1;
566 buffer =
new char[bufferSize];
567 strlcpy(buffer, buf2, bufferSize);
578 travel->
fNext = temp;
579 temp->
fPrev = travel;
580 travel = travel->
fNext;
586 if (!lastnl && !*tbuf && *(tbuf-1) ==
'\n') {
591 if (!finished && tbuf && strlen(tbuf))
614 if (!(fp = fopen(fn,
"w")))
return kFALSE;
618 buffer =
new char[travel->
fLength+2];
620 buffer[travel->
fLength] =
'\n';
621 buffer[travel->
fLength+1] =
'\0';
622 while (buffer[i] !=
'\0') {
623 if (buffer[i] ==
'\t') {
625 while (buffer[j] == 16)
628 strcpy(buffer+i+1, buffer+j);
632 if (fputs(buffer, fp) == EOF) {
638 travel = travel->
fNext;
655 if (!(fp = fopen(fn,
"a")))
return kFALSE;
659 buffer =
new char[travel->
fLength+2];
661 buffer[travel->
fLength] =
'\n';
662 buffer[travel->
fLength+1] =
'\0';
663 while (buffer[i] !=
'\0') {
664 if (buffer[i] ==
'\t') {
666 while (buffer[j] == 16 && buffer[j] !=
'\0')
669 strcpy(buffer+i+1, buffer+j);
673 if (fputs(buffer, fp) == EOF) {
679 travel = travel->
fNext;
692 if ((pos.
fY >= fRowCount) || (pos.
fY < 0))
695 if (!SetCurrentRow(pos.
fY))
return kFALSE;
696 fCurrent->DelChar(pos.
fX);
708 if ((pos.
fY >= fRowCount) || (pos.
fY < 0) || (pos.
fX < 0))
711 if (!SetCurrentRow(pos.
fY))
return kFALSE;
712 fCurrent->InsChar(pos.
fX, c);
724 if (pos.
fY >= fRowCount)
727 if (!SetCurrentRow(pos.
fY))
return -1;
728 return fCurrent->GetChar(pos.
fX);
737 if ((start.
fY < 0) || (start.
fY >= fRowCount) ||
738 (end.
fY < 0) || (end.
fY >= fRowCount)) {
748 if (!SetCurrentRow(start.
fY))
return kFALSE;
750 if (start.
fY == end.
fY) {
751 fCurrent->DelText(start.
fX, end.
fX-start.
fX+1);
754 fCurrent->DelText(start.
fX, fCurrent->fLength-start.
fX);
755 SetCurrentRow(fCurrentRow+1);
756 for (
Long_t i = start.
fY+1; i < end.
fY; i++) {
757 DelLine(fCurrentRow);
760 tempbuffer = fCurrent->GetText(end.
fX+1, fCurrent->fLength-end.
fX-1);
761 DelLine(fCurrentRow);
762 SetCurrentRow(start.
fY);
764 fCurrent->InsText(fCurrent->GetLineLength(), tempbuffer);
765 delete [] tempbuffer;
767 if (fCurrent->fNext) {
768 fCurrent->InsText(fCurrent->fLength, fCurrent->fNext->fString);
769 DelLine(fCurrentRow+1);
770 SetCurrentRow(start.
fY);
799 if (ins_pos.
fY > fRowCount)
808 if (ins_pos.
fY == fRowCount) {
809 pos.
fY = fRowCount - 1;
814 if (!SetCurrentRow(ins_pos.
fY))
return kFALSE;
818 restString = fCurrent->GetText(ins_pos.
fX, fCurrent->fLength - ins_pos.
fX);
819 fCurrent->DelText(ins_pos.
fX, fCurrent->fLength - ins_pos.
fX);
820 following = fCurrent->
fNext;
822 if (start_src.
fY == end_src.
fY) {
823 len = end_src.
fX - start_src.
fX+1;
829 lineString = src->
GetLine(start_src, len);
830 fCurrent->InsText(ins_pos.
fX, lineString);
831 delete [] lineString;
834 pos.
fY = start_src.
fY+1;
836 for ( ; pos.
fY < end_src.
fY; pos.
fY++) {
838 lineString = src->
GetLine(pos, llen > 0 ? llen : 0);
840 fCurrent->fNext->fPrev = fCurrent;
841 fCurrent = fCurrent->fNext;
844 delete [] lineString;
847 if (start_src.
fY != end_src.
fY) {
850 lineString = src->
GetLine(pos, end_src.
fX+1);
852 fCurrent->fNext->fPrev = fCurrent;
853 fCurrent = fCurrent->fNext;
856 delete [] lineString;
861 if (ins_pos.
fX == 0) {
863 fCurrent->fNext->fPrev = fCurrent;
864 fCurrent = fCurrent->fNext;
869 fCurrent->InsText(fCurrent->fLength, restString);
870 delete [] restString;
873 fCurrent->fNext = following;
874 if (fCurrent->fNext) {
889 if (pos.
fY < 0 || pos.
fY > fRowCount) {
893 if (pos.
fY == fRowCount) {
894 SetCurrentRow(fRowCount-1);
896 fCurrent->fNext->fPrev = fCurrent;
899 SetCurrentRow(pos.
fY);
900 fCurrent->InsText(pos.
fX, buffer);
916 start_src.
fX = start_src.
fY = 0;
920 return InsText(end, text, start_src, end_src);
930 if ((
Long_t)pos > fRowCount) {
933 if ((
Long_t)pos < fRowCount) {
936 SetCurrentRow(fRowCount-1);
939 if (!fCurrent)
return kFALSE;
941 previous = fCurrent->
fPrev;
943 newline->
fPrev = previous;
945 previous->
fNext = newline;
950 newline->
fNext = fCurrent;
951 fCurrent->
fPrev = newline;
965 if (!SetCurrentRow(pos) || (fRowCount == 1)) {
977 fCurrent = fCurrent->
fNext;
979 fCurrent = fCurrent->
fPrev;
998 if (SetCurrentRow(pos.
fY)) {
999 return fCurrent->GetText(pos.
fX, length);
1009 if (!SetCurrentRow(pos.
fY))
1011 if ((pos.
fX < 0) || (pos.
fX > (
Long_t)fCurrent->fLength))
1016 if (pos.
fX < (
Long_t)fCurrent->fLength) {
1017 tempbuffer = fCurrent->
GetText(pos.
fX, fCurrent->fLength-pos.
fX);
1019 fCurrent->DelText(pos.
fX, fCurrent->fLength - pos.
fX);
1020 delete [] tempbuffer;
1024 temp->
fPrev = fCurrent;
1026 fCurrent->
fNext = temp;
1034 fCurrent = fCurrent->fNext;
1044 if (!SetCurrentRow(row)) {
1047 return (
Long_t)fCurrent->GetLineLength();
1057 if ((row < 0) || (row >= fRowCount)) {
1060 if (row > fCurrentRow) {
1061 for (count = fCurrentRow; count < row; count++) {
1062 if (!fCurrent->fNext) {
1063 fCurrentRow = count;
1066 fCurrent = fCurrent->fNext;
1069 if (fCurrentRow == row)
1071 for (count = fCurrentRow; count > row; count--) {
1072 if (!fCurrent->fPrev) {
1073 fCurrentRow = count;
1076 fCurrent = fCurrent->fPrev;
1088 if (!SetCurrentRow(row)) {
1096 buffer = fCurrent->fString;
1097 while (buffer[i] !=
'\0') {
1098 if (buffer[i] ==
'\t') {
1100 while (buffer[j] == 16 && buffer[j] !=
'\0') {
1104 strcpy(buffer+i+1, buffer+j);
1109 char c, *src, *dst, *buf2;
1117 while ((c = *src++)) {
1121 while (((dst-buf2) & 0x7) && (cnt++ <
kMaxLen-1)) {
1127 if (cnt++ >=
kMaxLen-1)
break;
1131 fCurrent->fString = buf2;
1132 fCurrent->fLength = strlen(buf2);
1143 const char *searchString,
1146 if (!SetCurrentRow(start.
fY))
1153 TString s = fCurrent->fString;
1158 foundPos->
fY = fCurrentRow;
1161 if (!SetCurrentRow(fCurrentRow+1))
1167 TString s = fCurrent->fString;
1168 for (
int i = (
int)start.
fX; i >= 0; i--) {
1171 if (x >= start.
fX) {
1181 foundPos->
fY = fCurrentRow;
1184 if (!SetCurrentRow(fCurrentRow-1)) {
1187 start.
fX = fCurrent->fLength;
1199 if (!SetCurrentRow(start.
fY)) {
1204 if (!Search(&foundPos, start, oldText, direction, caseSensitive)) {
1209 delEnd.
fY = foundPos.
fY;
1210 delEnd.
fX = foundPos.
fX + strlen(oldText) - 1;
1227 fLongestLine = line_count;
1229 travel = travel->
fNext;
1248 fLongestLine = line_count;
1251 travel = travel->
fNext;
1252 if (travel) ret +=
'\n';
TGText()
Create default (empty) text buffer.
Bool_t Append(const char *fn)
Append buffer to file fn.
Bool_t InsText(TGLongPosition pos, const char *buf)
Insert single line at specified position.
void Clear()
Clear text buffer.
virtual ~TGTextLine()
Delete a line of text.
void DelText(ULong_t pos, ULong_t length)
Delete length chars from line starting at position pos.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Bool_t BreakLine(TGLongPosition pos)
Break line at position pos. Returns false if pos is not valid.
Bool_t LoadBuffer(const char *txtbuf)
Load a 0 terminated buffer. Lines will be split at ' '.
Bool_t DelChar(TGLongPosition pos)
Delete character at specified position pos.
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.
void DelChar(ULong_t pos)
Delete a character from the line.
char * GetLine(TGLongPosition pos, ULong_t length)
Return string at position pos.
TGTextLine & operator=(const TGTextLine &)
assignment operator
Bool_t Load(const char *fn, Long_t startpos=0, Long_t length=-1)
Load text from file fn.
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.
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)...
TGText & operator=(const TGText &)
assignment operator
char GetChar(TGLongPosition pos)
Get character a position pos. If charcater not valid return -1.
void Init()
Common initialization method.
Bool_t DelText(TGLongPosition start, TGLongPosition end)
Delete text between start and end positions.
Bool_t Save(const char *fn)
Save text buffer to file fn.
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
TGTextLine()
Create empty line of text (default ctor).
Bool_t InsChar(TGLongPosition pos, char c)
Insert character c at the specified position pos.
TString AsString()
Returns content as ROOT string.
Bool_t AddText(TGText *text)
Add another text buffer to this buffer.
void InsChar(ULong_t pos, char character)
Insert a character at the specified position.
Bool_t DelLine(ULong_t pos)
Delete specified row. Returns false if row does not exist.
void ReTab(Long_t row)
Redo all tabs in a line. Needed after a new tab is inserted.
char * GetText(ULong_t pos, ULong_t length)
Get length characters from line starting at pos.
Bool_t InsLine(ULong_t row, const char *string)
Insert string before specified position.
void Clear()
Clear a line of text.
void LongestLine()
Set fLongestLine.
char GetChar(ULong_t pos)
Get a character at the specified position from the line.
Bool_t SetCurrentRow(Long_t row)
Make specified row the current row.
virtual ~TGText()
Destroy text buffer.