Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mschlegel81 committed Mar 12, 2023
1 parent 84ab34c commit a796001
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
13 changes: 1 addition & 12 deletions logicalgates.pas
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,12 @@ T_wireValue=record
FUNCTION get2ComplementValue (CONST wire:T_wireValue; OUT valid:boolean):longint;

FUNCTION gatesTotal(CONST gateCount:T_gateCount):longint;
FUNCTION gateCountReport(CONST gateCount:T_gateCount):string;

FUNCTION serialize(CONST wireValue: T_wireValue): qword;
FUNCTION deserialize(n: qword): T_wireValue;

IMPLEMENTATION
USES sysutils,myStringUtil;
USES sysutils;
FUNCTION getBinaryString(CONST wire: T_wireValue): shortstring;
VAR i:longint;
begin
Expand Down Expand Up @@ -627,16 +626,6 @@ T_wireValue=record
for gt in T_gateType do result+=gateCount[gt];
end;

FUNCTION gateCountReport(CONST gateCount: T_gateCount): string;
VAR gt:T_gateType;
begin
result:='';
for gt in T_gateType do if gateCount[gt]>0 then begin
if result<>'' then result+=LineEnding;
result+=C_gateTypeName[gt]+C_tabChar+intToStr(gateCount[gt]);
end;
end;

FUNCTION parseWireBin(CONST s: string; CONST width: byte): T_wireValue;
VAR i:longint;
k:longint;
Expand Down
44 changes: 43 additions & 1 deletion sprites.pas
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
FUNCTION get7SegmentSprite(CONST wireValue: T_wireValue; CONST marked:boolean):P_sprite;
FUNCTION getWatcherSprite(CONST ioLabel_:shortstring; CONST ioIndex:longint; CONST wireValue:T_wireValue; CONST isInput,leftOrRight:boolean):P_sprite;
IMPLEMENTATION
USES sysutils,myStringUtil,types,Classes,math;
USES sysutils,types,Classes,math,strutils;
VAR ioSpriteMap,
blockSpriteMap,
ioBlockSpriteMap,
Expand Down Expand Up @@ -712,6 +712,48 @@
end;
end;

FUNCTION split(CONST s:ansistring; CONST splitters:T_arrayOfString; CONST retainSplitters:boolean=false):T_arrayOfString;
PROCEDURE nextSplitterPos(CONST startSearchAt:longint; OUT splitterStart,splitterEnd:longint); inline;
VAR splitter:string;
i:longint;
begin
splitterStart:=length(s)+1;
splitterEnd:=splitterStart;
for splitter in splitters do if length(splitter)>0 then begin
i:=PosEx(splitter,s,startSearchAt);
if (i>0) and (i<splitterStart) then begin
splitterStart:=i;
splitterEnd:=i+length(splitter);
end;
end;
end;

VAR resultLen:longint=0;
PROCEDURE appendToResult(CONST part:string); inline;
begin
if length(result)<resultLen+1 then setLength(result,round(length(result)*1.2)+2);
result[resultLen]:=part;
inc(resultLen);
end;

VAR partStart:longint=1;
splitterStart,splitterEnd:longint;
endsOnSplitter:boolean=false;
begin
setLength(result,0);
nextSplitterPos(partStart,splitterStart,splitterEnd);
endsOnSplitter:=splitterEnd>splitterStart;
while(partStart<=length(s)) do begin
appendToResult(copy(s,partStart,splitterStart-partStart));
partStart:=splitterEnd;
endsOnSplitter:=splitterEnd>splitterStart;
if endsOnSplitter and retainSplitters then appendToResult(copy(s,splitterStart,splitterEnd-splitterStart));
nextSplitterPos(partStart,splitterStart,splitterEnd);
end;
if endsOnSplitter and not retainSplitters then appendToResult('');
setLength(result,resultLen);
end;

begin
lines:=split(s,LineEnding);

Expand Down

0 comments on commit a796001

Please sign in to comment.