First up, I love Pascal. But, after coding each project, I end up with these little functions, which are slight variations on what is currently available.
Here are 4 examples:
function PosExIC(const ASubStr, AString: String; const AOffset: Integer): Integer;
var
LPos: PChar;
begin
if (AOffset < 1) or (AOffset > Length(AString)) then begin
Result := 0;
end else begin
LPos := stripos(pchar(AString) + AOffset - 1, pchar(ASubStr));
if LPos = nil then begin
Result := 0;
end else begin
Result := LPos - pchar(AString) + 1;
end;
end;
end;
function PosIC(const ASubStr, AString: String): Integer;
begin
Result := PosExIC(ASubStr, AString, 1);
end;
function RPosSet(const ACharSet: TSysCharSet; const AString: String): Integer;
begin
for Result := Length(AString) downto 1 do begin
if AString[Result] in ACharSet then begin
Exit;
end;
end;
Result := 0;
end;
function RPosSetEx(const ACharSet: TSysCharSet; const AString: String; const AOffset: Integer): Integer;
begin
for Result := Min(AOffset, Length(AString)) downto 1 do begin
if AString[Result] in ACharSet then begin
Exit;
end;
end;
Result := 0;
end;
PosExIC and PosIC are two functions which I don't understand are not in FreePascal. Or, where is the floating point modulus? It would be nice if some basic functions were added without waiting for a Embarcadero initiative.
Maybe, I'm missing some understanding of FreePascal development.
I guess the issue I see is, someone asked for the best way to change the innerhtml of a tag. The answers used regular expressions, which I thought was somewhat of a overkill, considering the simple requirement (and how it would be coded in other languages).
But, if there was a PosIC and PosExIC, then this could have been the solution:
function ChangeInnerHtml(const AHtml, ATag, AInnerHtml: String): String;
var
LStart, LEnd: Integer;
begin
Result := AHtml;
LStart := PosIC('<' + ATag + '>', Result);
if LStart > 0 then begin
LStart += Length(ATag) + 2;
LEnd := PosExIC('</' + ATag + '>', Result, LStart);
if LEnd > 0 then begin
Result := StuffString(Result, LStart, LEnd - LStart, AInnerHtml);
end;
end;
end;
Anyway, so the question is, what do you think is an important "missing function" (based on your own developments), and what would be your implementation?
Cheers.