Don't you think that parsing same strings all other and other again (sorting) is not quite efficient?
Suggestion: parse a string into some sort of (natural) comparison friendly structure. The comparison of two strings will turn into comparison these structures.
Something like this:
TCompareSection = record
isNum: Boolean;
ist : integer;
iend : integer;
// or even substr: string;
// uppercasesub : string; ???
num : Qword;
end;
TComparisonInfo = class(TObject)
private
fSections : array of TCompareSection;
fCount : integer;
fSource : string;
protected PrepareSections(const a: string) ;
public
constructor Create(const a: strings)
function Compare(info: TComparisonInfo): Integer;
end;
protected TComparisonInfo.PrepareSections(const a: string) ;
var
i : integer;
begin
i:=1;
while i<length(a) do begin
if a[i] in ('0'..'9') then ParseNumerical(a,i)
else ParseString(a,i);
end;
end;
function TComparisonInfo.Compare(info: TComparisonInfo): Integer;
var
i,j : integer;
begin
j:=0;
Result:=0;
for i:=0 to fCount -1 do
if fSource[i].isNum and fSource[j].isNum then
Result:=CompareInt
else if (not fSource[i].isNum ) and (not fSource[j].isNum )
Result:=CompareStr
else
Result:=what ever goes first (numerical or string);
if Result<>0 then Exit;
end;
Greater memory consumption? - Yes.
Faster? - Yes (no time penalty for parsing the same data)