Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Parses the response code from the given string.
- Returns 0 if the response code could not be parsed.
- }
- function ParseResponseCode(const responseString: string): integer;
- const
- SPACE_CHAR = ' ';
- CRLF_CHAR = #13;
- NEWLINE_CHAR = #10;
- var
- crlfPos, responseStringLen: integer;
- parsedResponseCode: integer;
- responseCodeSubstring: string;
- begin
- Result := 0;
- if (responseString = '') then
- Exit;
- responseString := RTrimCRLF(responseString);
- responseStringLen := Length(responseString);
- crlfPos := RPos(CRLF_CHAR, responseString);
- if (crlfPos <= responseStringLen - 3) then
- begin
- Inc(crlfPos);
- if (responseString[crlfPos] in [CRLF_CHAR, NEWLINE_CHAR]) then
- Inc(crlfPos);
- responseCodeSubstring := Copy(responseString, crlfPos, 3);
- if (TryStrToInt(responseCodeSubstring, parsedResponseCode)) then
- begin
- Result := parsedResponseCode;
- if ((responseStringLen > 3) and (responseString[crlfPos + 3] <> SPACE_CHAR)) then
- Inc(Result, 1000);
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement