summaryrefslogtreecommitdiff
path: root/mystringlistunit.pas
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2015-11-28 19:19:13 +0100
committerErich Eckner <git@eckner.net>2015-11-28 19:19:13 +0100
commit4ce8c945fe445bc844b8ac33f2d4d173a78c46b1 (patch)
treedb41ea90cda94943d7da6aee3c5d3b2280b431de /mystringlistunit.pas
parent579f6432482fb5a806c579e5125444a2f1d4945f (diff)
downloadunits-4ce8c945fe445bc844b8ac33f2d4d173a78c46b1.tar.xz
numerische Sortierung in mystringlistunit.pas ermöglicht
Diffstat (limited to 'mystringlistunit.pas')
-rw-r--r--mystringlistunit.pas45
1 files changed, 45 insertions, 0 deletions
diff --git a/mystringlistunit.pas b/mystringlistunit.pas
index 7483e36..0a043a3 100644
--- a/mystringlistunit.pas
+++ b/mystringlistunit.pas
@@ -23,6 +23,7 @@ type
function readln(out s: string): boolean; inline;
function metaReadln(out s: string; subRoutine: boolean): boolean; inline;
procedure grep(expr: string);
+ function grepFirst(expr: string): string;
function hatZeile(zeile: string): boolean; // invers zu "grep -c"
function eof: boolean;
procedure rewind;
@@ -37,6 +38,7 @@ type
procedure _del(var s: string; p,c: longint); inline; // identisch zu delete(s,p,c) -- lediglich um delete innerhalb von tMyStringlist verfügbar zu haben
procedure _mov(const source;var dest;count:SizeInt); // identisch zu move(source,dest,count) -- lediglich um move innerhalb von tMyStringlist verfügbar zu haben
+function numerischerVergleich(list: tStringList; index1,index2: integer): integer;
implementation
@@ -151,6 +153,23 @@ begin
re.free;
end;
+function tMyStringlist.grepFirst(expr: string): string;
+var
+ re: tRegExpr;
+ i: longint;
+begin
+ re:=tRegExpr.create;
+ re.expression:=expr;
+ for i:=count-1 downto 0 do
+ if re.exec(self[i]) then begin
+ result:=self[i];
+ re.free;
+ exit;
+ end;
+ re.free;
+ result:='';
+end;
+
function tMyStringlist.hatZeile(zeile: string): boolean;
var
re: tRegExpr;
@@ -461,5 +480,31 @@ begin
move(source,dest,count);
end;
+function numerischerVergleich(list: tStringList; index1,index2: integer): integer;
+var
+ neg: boolean;
+ i: longint;
+begin
+ if (leftStr(list[index1],1)='-') xor (leftStr(list[index2],1)='-') then begin
+ result:=2*byte(leftStr(list[index2],1)='-')-1;
+ exit;
+ end;
+ neg:=leftStr(list[index1],1)='-';
+ result:=length(list[index1])-length(list[index2]);
+ if result=0 then begin
+ for i:=1 to length(list[index1]) do begin
+ if list[index1][i]<list[index2][i] then begin
+ result:=-1;
+ break;
+ end;
+ if list[index1][i]>list[index2][i] then begin
+ result:=1;
+ break;
+ end;
+ end;
+ end;
+ result:=result*(1-2*byte(neg));
+end;
+
end.