Created
March 18, 2020 06:07
-
-
Save HemulGM/ca63eca683e9aea2c98ff9ac9eb4fa4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GetParamStr(P: PChar; var Param: string): PChar; | |
var | |
i, Len: Integer; | |
Start, S: PChar; | |
begin | |
// U-OK | |
while True do | |
begin | |
while (P[0] <> #0) and (P[0] <= ' ') do | |
Inc(P); | |
if (P[0] = '"') and (P[1] = '"') then | |
Inc(P, 2) | |
else | |
Break; | |
end; | |
Len := 0; | |
Start := P; | |
while P[0] > ' ' do | |
begin | |
if P[0] = '"' then | |
begin | |
Inc(P); | |
while (P[0] <> #0) and (P[0] <> '"') do | |
begin | |
Inc(Len); | |
Inc(P); | |
end; | |
if P[0] <> #0 then | |
Inc(P); | |
end | |
else | |
begin | |
Inc(Len); | |
Inc(P); | |
end; | |
end; | |
SetLength(Param, Len); | |
P := Start; | |
S := Pointer(Param); | |
i := 0; | |
while P[0] > ' ' do | |
begin | |
if P[0] = '"' then | |
begin | |
Inc(P); | |
while (P[0] <> #0) and (P[0] <> '"') do | |
begin | |
S[i] := P^; | |
Inc(P); | |
Inc(i); | |
end; | |
if P[0] <> #0 then | |
Inc(P); | |
end | |
else | |
begin | |
S[i] := P^; | |
Inc(P); | |
Inc(i); | |
end; | |
end; | |
Result := P; | |
end; | |
function GetParam(Str: string; Index: Integer): string; | |
var | |
P: PChar; | |
Buffer: array[0..260] of Char; | |
begin | |
Result := ''; | |
P := PChar(Str); | |
while True do | |
begin | |
P := GetParamStr(P, Result); | |
if (Index = 0) or (Result = '') then | |
Break; | |
Dec(Index); | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment