Advertisement
ZarTek-CREOLE

Untitled

Jan 6th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.04 KB | None | 0 0
  1. {
  2.   Parses the response code from the given string.
  3.   Returns 0 if the response code could not be parsed.
  4. }
  5. function ParseResponseCode(const responseString: string): integer;
  6. const
  7.   SPACE_CHAR = ' ';
  8.   CRLF_CHAR = #13;
  9.   NEWLINE_CHAR = #10;
  10. var
  11.   crlfPos, responseStringLen: integer;
  12.   parsedResponseCode: integer;
  13.   responseCodeSubstring: string;
  14. begin
  15.   Result := 0;
  16.   if (responseString = '') then
  17.     Exit;
  18.  
  19.   responseString := RTrimCRLF(responseString);
  20.   responseStringLen := Length(responseString);
  21.  
  22.   crlfPos := RPos(CRLF_CHAR, responseString);
  23.   if (crlfPos <= responseStringLen - 3) then
  24.   begin
  25.     Inc(crlfPos);
  26.     if (responseString[crlfPos] in [CRLF_CHAR, NEWLINE_CHAR]) then
  27.       Inc(crlfPos);
  28.  
  29.     responseCodeSubstring := Copy(responseString, crlfPos, 3);
  30.     if (TryStrToInt(responseCodeSubstring, parsedResponseCode)) then
  31.     begin
  32.       Result := parsedResponseCode;
  33.       if ((responseStringLen > 3) and (responseString[crlfPos + 3] <> SPACE_CHAR)) then
  34.         Inc(Result, 1000);
  35.     end;
  36.   end;
  37. end;
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement