From 788e7e42a53b52ff2ff4cb7674ed631233c004a0 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 1 Apr 2019 15:44:59 +0200 Subject: mystringlistunit.pas: tMyStringList.findeZeile() neu --- mystringlistunit.pas | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/mystringlistunit.pas b/mystringlistunit.pas index df900a0..80da220 100644 --- a/mystringlistunit.pas +++ b/mystringlistunit.pas @@ -30,7 +30,8 @@ type procedure replace(von,nach: string); procedure uniq(c: char); procedure append(sl: tMyStringList); overload; - function hatZeile(zeile: string; regex: boolean = true): boolean; // invers zu "grep -c" + function findeZeile(zeile: string; regex: boolean = true): longint; + function hatZeile(zeile: string; regex: boolean = true): boolean; inline; // invers zu "grep -c" function eof: boolean; procedure rewind; procedure stepBack; @@ -301,18 +302,19 @@ begin add(sl[i]); end; -function tMyStringList.hatZeile(zeile: string; regex: boolean = true): boolean; +function tMyStringList.findeZeile(zeile: string; regex: boolean = true): longint; var re: tRegExpr; i: longint; begin - result:=true; + result:=-1; if regex then begin re:=tRegExpr.create; for i:=0 to count-1 do begin re.expression:=self[i]; if re.exec(zeile) then begin re.free; + result:=i; exit; end; end; @@ -320,9 +322,15 @@ begin end else for i:=0 to count-1 do - if self[i]=zeile then + if self[i]=zeile then begin + result:=i; exit; - result:=false; + end; +end; + +function tMyStringList.hatZeile(zeile: string; regex: boolean = true): boolean; +begin + result:=findeZeile(zeile,regex)>=0; end; function tMyStringList.eof: boolean; -- cgit v1.2.3-54-g00ecf