lcore.org gitweb
/
lcore.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add cleartree to bsearchtree which clears a hashtable and frees all resources
[lcore.git]
/
readtxt2.pas
diff --git
a/readtxt2.pas
b/readtxt2.pas
index 84c57652c4e90fe86d85cb4dc263b4261a4a8dd1..12bea5afed8cceeccd92590e58671ab1bf0a7b83 100644
(file)
--- a/
readtxt2.pas
+++ b/
readtxt2.pas
@@
-34,7
+34,7
@@
type
constructor create(asourcestream: tstream; adestroysourcestream:boolean);
\r
constructor createf(filename : string);
\r
\r
constructor create(asourcestream: tstream; adestroysourcestream:boolean);
\r
constructor createf(filename : string);
\r
\r
- function readline:string;
\r
+ function readline:
ansi
string;
\r
function eof:boolean;
\r
destructor destroy; override;
\r
private
\r
function eof:boolean;
\r
destructor destroy; override;
\r
private
\r
@@
-44,6
+44,7
@@
type
currenteol,preveol:integer;
\r
fileeof,reachedeof:boolean;
\r
eoltype:integer;
\r
currenteol,preveol:integer;
\r
fileeof,reachedeof:boolean;
\r
eoltype:integer;
\r
+ procedure checkandread;
\r
end;
\r
\r
implementation
\r
end;
\r
\r
implementation
\r
@@
-54,17
+55,26
@@
begin
sourcestream := asourcestream;
\r
destroysourcestream := adestroysourcestream;
\r
\r
sourcestream := asourcestream;
\r
destroysourcestream := adestroysourcestream;
\r
\r
- if sourcestream.Position >= sourcestream.size then fileeof := true;
\r
+
//
if sourcestream.Position >= sourcestream.size then fileeof := true;
\r
bufpointer := bufsize;
\r
bufpointer := bufsize;
\r
- destroysourcestream := false;
\r
end;
\r
\r
end;
\r
\r
-constructor treadtxt.createf(filename
: string);
\r
+constructor treadtxt.createf(filename: string);
\r
begin
\r
create(tfilestream.create(filename,fmOpenRead),true);
\r
end;
\r
\r
\r
begin
\r
create(tfilestream.create(filename,fmOpenRead),true);
\r
end;
\r
\r
\r
+procedure treadtxt.checkandread;
\r
+begin
\r
+ if bufpointer >= numread then begin
\r
+ numread := sourcestream.read(buf,bufsize);
\r
+ bufpointer := 0;
\r
+ if numread = 0 then fileeof := true;
\r
+
\r
+ end;
\r
+end;
\r
+
\r
function treadtxt.readline;
\r
var
\r
a,b,c,d:integer;
\r
function treadtxt.readline;
\r
var
\r
a,b,c,d:integer;
\r
@@
-72,11
+82,7
@@
begin
\r
result := '';
\r
repeat
\r
\r
result := '';
\r
repeat
\r
- if bufpointer >= bufsize then begin
\r
- numread := sourcestream.read(buf,bufsize);
\r
- bufpointer := 0;
\r
- if sourcestream.Position >= sourcestream.size then fileeof := true;
\r
- end;
\r
+ checkandread;
\r
b := numread-1;
\r
\r
{core search loop begin}
\r
b := numread-1;
\r
\r
{core search loop begin}
\r
@@
-97,7
+103,8
@@
begin
setlength(result,c+b);
\r
move(buf[bufpointer],result[c+1],b);
\r
bufpointer := numread;
\r
setlength(result,c+b);
\r
move(buf[bufpointer],result[c+1],b);
\r
bufpointer := numread;
\r
- if numread < bufsize then begin
\r
+ if fileeof then begin
\r
+ {we reached the end of the file, return what we have}
\r
reachedeof := true;
\r
exit;
\r
end;
\r
reachedeof := true;
\r
exit;
\r
end;
\r
@@
-134,8
+141,8
@@
end;
\r
function treadtxt.eof:boolean;
\r
begin
\r
\r
function treadtxt.eof:boolean;
\r
begin
\r
-
\r
- result := ((bufpointer >=
bufsize
) and fileeof) or reachedeof;
\r
+ checkandread;
\r
+ result := ((bufpointer >=
numread
) and fileeof) or reachedeof;
\r
end;
\r
\r
destructor treadtxt.destroy;
\r
end;
\r
\r
destructor treadtxt.destroy;
\r