strparse.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef HEADER_CURL_STRPARSE_H
  2. #define HEADER_CURL_STRPARSE_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include "../curl_setup.h"
  27. #define STRE_OK 0
  28. #define STRE_BIG 1
  29. #define STRE_SHORT 2
  30. #define STRE_BEGQUOTE 3
  31. #define STRE_ENDQUOTE 4
  32. #define STRE_BYTE 5
  33. #define STRE_NEWLINE 6
  34. #define STRE_OVERFLOW 7
  35. #define STRE_NO_NUM 8
  36. /* public struct, but all accesses should be done using the provided
  37. functions */
  38. struct Curl_str {
  39. const char *str;
  40. size_t len;
  41. };
  42. void curlx_str_init(struct Curl_str *out);
  43. void curlx_str_assign(struct Curl_str *out, const char *str, size_t len);
  44. #define curlx_str(x) ((x)->str)
  45. #define curlx_strlen(x) ((x)->len)
  46. /* Get a word until the first space
  47. return non-zero on error */
  48. int curlx_str_word(const char **linep, struct Curl_str *out, const size_t max);
  49. /* Get a word until the first DELIM or end of string
  50. return non-zero on error */
  51. int curlx_str_until(const char **linep, struct Curl_str *out, const size_t max,
  52. char delim);
  53. /* Get a word until a newline byte or end of string. At least one byte long.
  54. return non-zero on error */
  55. int curlx_str_untilnl(const char **linep, struct Curl_str *out,
  56. const size_t max);
  57. /* Get a "quoted" word. No escaping possible.
  58. return non-zero on error */
  59. int curlx_str_quotedword(const char **linep, struct Curl_str *out,
  60. const size_t max);
  61. /* Advance over a single character.
  62. return non-zero on error */
  63. int curlx_str_single(const char **linep, char byte);
  64. /* Advance over a single space.
  65. return non-zero on error */
  66. int curlx_str_singlespace(const char **linep);
  67. /* Get an unsigned decimal number. Return non-zero on error */
  68. int curlx_str_number(const char **linep, curl_off_t *nump, curl_off_t max);
  69. /* As above with CURL_OFF_T_MAX but also pass leading blanks */
  70. int curlx_str_numblanks(const char **str, curl_off_t *num);
  71. /* Get an unsigned hexadecimal number. Return non-zero on error */
  72. int curlx_str_hex(const char **linep, curl_off_t *nump, curl_off_t max);
  73. /* Get an unsigned octal number. Return non-zero on error */
  74. int curlx_str_octal(const char **linep, curl_off_t *nump, curl_off_t max);
  75. /* Check for CR or LF
  76. return non-zero on error */
  77. int curlx_str_newline(const char **linep);
  78. /* case insensitive compare that the parsed string matches the
  79. given string. */
  80. int curlx_str_casecompare(struct Curl_str *str, const char *check);
  81. int curlx_str_cmp(struct Curl_str *str, const char *check);
  82. int curlx_str_nudge(struct Curl_str *str, size_t num);
  83. int curlx_str_cspn(const char **linep, struct Curl_str *out, const char *cspn);
  84. void curlx_str_trimblanks(struct Curl_str *out);
  85. void curlx_str_passblanks(const char **linep);
  86. /* given a hexadecimal letter, return the binary value. '0' returns 0, 'a'
  87. returns 10. THIS ONLY WORKS ON VALID HEXADECIMAL LETTER INPUT. Verify
  88. before calling this!
  89. */
  90. extern const unsigned char Curl_hexasciitable[];
  91. #define Curl_hexval(x) (unsigned char)(Curl_hexasciitable[(x) - '0'] & 0x0f)
  92. #endif /* HEADER_CURL_STRPARSE_H */