From ec56c3a4d7f170622948dd4a09ab649f2db1ffa8 Mon Sep 17 00:00:00 2001 From: pierre Date: Mon, 9 Sep 2002 06:58:27 +0000 Subject: [PATCH] + FastBufStream.readline method added --- ide/wcedit.pas | 9 ++++-- ide/weditor.pas | 22 +++++++++----- ide/wutils.pas | 78 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 97 insertions(+), 12 deletions(-) diff --git a/ide/wcedit.pas b/ide/wcedit.pas index 86406df891..b822e62514 100644 --- a/ide/wcedit.pas +++ b/ide/wcedit.pas @@ -164,7 +164,7 @@ type procedure PositionChanged; virtual; procedure LimitsChanged; virtual; function IsClipboard: Boolean; virtual; - function LoadFromStream(Stream: PStream): boolean; virtual; + function LoadFromStream(Stream: PFastBufStream): boolean; virtual; function SaveToStream(Stream: PStream): boolean; virtual; function SaveAreaToStream(Stream: PStream; StartP,EndP: TPoint): boolean;virtual; destructor Done; virtual; @@ -1666,7 +1666,7 @@ begin S.Write(HighlightRow,SizeOf(HighlightRow)); end;*) -function TCodeEditor.LoadFromStream(Stream: PStream): boolean; +function TCodeEditor.LoadFromStream(Stream: PFastBufStream): boolean; var OK: boolean; begin OK:=Core^.LoadFromStream(@Self,Stream); @@ -2050,7 +2050,10 @@ end; END. { $Log$ - Revision 1.13 2002-09-07 15:40:47 peter + Revision 1.14 2002-09-09 06:58:28 pierre + + FastBufStream.readline method added + + Revision 1.13 2002/09/07 15:40:47 peter * old logs removed and tabs fixed Revision 1.12 2002/09/03 11:50:08 pierre diff --git a/ide/weditor.pas b/ide/weditor.pas index 70fbcfd962..d613ba0f4a 100644 --- a/ide/weditor.pas +++ b/ide/weditor.pas @@ -403,7 +403,7 @@ type function GetLastVisibleLine : sw_integer; public { Storage } - function LoadFromStream(Editor: PCustomCodeEditor; Stream: PStream): boolean; virtual; + function LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean; virtual; function SaveToStream(Editor: PCustomCodeEditor; Stream: PStream): boolean; virtual; function SaveAreaToStream(Editor: PCustomCodeEditor; Stream: PStream; StartP,EndP: TPoint): boolean; virtual; {$ifdef TP}public{$else}protected{$endif} @@ -538,7 +538,7 @@ type {a}procedure AdjustSelectionPos(CurPosX, CurPosY: sw_integer; DeltaX, DeltaY: sw_integer); {a}procedure GetContent(ALines: PUnsortedStringCollection); virtual; {a}procedure SetContent(ALines: PUnsortedStringCollection); virtual; - {a}function LoadFromStream(Stream: PStream): boolean; virtual; + {a}function LoadFromStream(Stream: PFastBufStream): boolean; virtual; {a}function SaveToStream(Stream: PStream): boolean; virtual; {a}function SaveAreaToStream(Stream: PStream; StartP,EndP: TPoint): boolean;virtual; function LoadFromFile(const AFileName: string): boolean; virtual; @@ -2805,7 +2805,7 @@ begin Abstract; end; -function TCustomCodeEditor.LoadFromStream(Stream: PStream): boolean; +function TCustomCodeEditor.LoadFromStream(Stream: PFastBufStream): boolean; begin Abstract; LoadFromStream:=false; @@ -2830,7 +2830,7 @@ begin end; function TCustomCodeEditor.LoadFromFile(const AFileName: string): boolean; -var S: PBufStream; +var S: PFastBufStream; OK: boolean; begin New(S, Init(AFileName,stOpenRead,EditorTextBufSize)); @@ -5442,7 +5442,7 @@ end; procedure TCustomCodeEditor.ReadBlock; var FileName: string; - S: PBufStream; + S: PFastBufStream; E: PCodeEditor; R: TRect; begin @@ -6621,7 +6621,7 @@ begin GetPalette:=@P; end; -function TCustomCodeEditorCore.LoadFromStream(Editor: PCustomCodeEditor; Stream: PStream): boolean; +function TCustomCodeEditorCore.LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean; var S: string; AllLinesComplete,LineComplete,hasCR,OK: boolean; begin @@ -6635,7 +6635,10 @@ begin begin while OK and (eofstream(Stream)=false) and (GetLineCount#10 then stream^.seek(pos); end; + if (c=#10) or eofstream(stream) then linecomplete:=true; if (c=#10) then @@ -879,6 +882,76 @@ begin end; end; +procedure TFastBufStream.Readline(var s:string;var linecomplete,hasCR : boolean); + var + c : char; + i,pos,StartPos : longint; + charsInS : boolean; + begin + linecomplete:=false; + c:=#0; + i:=0; + { this created problems for lines longer than 255 characters + now those lines are cutted into pieces without warning PM } + { changed implicit 255 to High(S), so it will be automatically extended + when longstrings eventually become default - Gabor } + if (bufend-bufptr>=High(S)) and (getpos+High(S)=getsize)) and (c<>#10) and (i#10 then + begin + inc(i); + if not CharsInS then + s[i]:=c; + end; + end; + if CharsInS and (i<>High(S)) then + begin + if c=#10 then + Seek(StartPos+i+1) + else + Seek(StartPos+i); + end; + { if there was a CR LF then remove the CR Dos newline style } + if (i>0) and (s[i]=#13) then + begin + dec(i); + end; + if (c=#13) and (not (getpos>=getsize)) then + begin + read(c,sizeof(c)); + end; + if (i=High(S)) and not (getpos>=getsize) then + begin + pos:=getpos; + read(c,sizeof(c)); + if (c=#13) and not (getpos>=getsize) then + read(c,sizeof(c)); + if c<>#10 then + seek(pos); + end; + if (c=#10) or (getpos>=getsize) then + linecomplete:=true; + if (c=#10) then + hasCR:=true; + s[0]:=chr(i); + end; + + + function TTextCollection.Compare(Key1, Key2: Pointer): Sw_Integer; var K1: PString absolute Key1; K2: PString absolute Key2; @@ -1289,7 +1362,10 @@ BEGIN END. { $Log$ - Revision 1.12 2002-09-07 15:40:50 peter + Revision 1.13 2002-09-09 06:58:27 pierre + + FastBufStream.readline method added + + Revision 1.12 2002/09/07 15:40:50 peter * old logs removed and tabs fixed Revision 1.11 2002/09/06 09:53:53 pierre