Advertisement
ZarTek-CREOLE

Untitled

Jan 6th, 2023
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 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. trimmedResponseString: string;
  15. begin
  16. Result := 0;
  17. if (responseString = '') then
  18. Exit;
  19.  
  20. trimmedResponseString := RTrimCRLF(responseString);
  21. responseStringLen := Length(trimmedResponseString);
  22.  
  23. crlfPos := RPos(CRLF_CHAR, trimmedResponseString);
  24. if (crlfPos <= responseStringLen - 3) then
  25. begin
  26. Inc(crlfPos);
  27. if (trimmedResponseString[crlfPos] in [CRLF_CHAR, NEWLINE_CHAR]) then
  28. Inc(crlfPos);
  29.  
  30. responseCodeSubstring := Copy(trimmedResponseString, crlfPos, 3);
  31. if (TryStrToInt(responseCodeSubstring, parsedResponseCode)) then
  32. begin
  33. Result := parsedResponseCode;
  34. if ((responseStringLen > 3) and (trimmedResponseString[crlfPos + 3] <> SPACE_CHAR)) then
  35. Inc(Result, 1000);
  36. end;
  37. end;
  38. end;
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement