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;
- trimmedResponseString: string;
- begin
- Result := 0;
- if (responseString = '') then
- Exit;
- trimmedResponseString := RTrimCRLF(responseString);
- responseStringLen := Length(trimmedResponseString);
- crlfPos := RPos(CRLF_CHAR, trimmedResponseString);
- if (crlfPos <= responseStringLen - 3) then
- begin
- Inc(crlfPos);
- if (trimmedResponseString[crlfPos] in [CRLF_CHAR, NEWLINE_CHAR]) then
- Inc(crlfPos);
- responseCodeSubstring := Copy(trimmedResponseString, crlfPos, 3);
- if (TryStrToInt(responseCodeSubstring, parsedResponseCode)) then
- begin
- Result := parsedResponseCode;
- if ((responseStringLen > 3) and (trimmedResponseString[crlfPos + 3] <> SPACE_CHAR)) then
- Inc(Result, 1000);
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement