args.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <m-string.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /** Extract int value and trim arguments string
  9. *
  10. * @param args - arguments string
  11. * @param word first argument, output
  12. * @return true - success
  13. * @return false - arguments string does not contain int
  14. */
  15. bool args_read_int_and_trim(string_t args, int* value);
  16. /**
  17. * @brief Extract first argument from arguments string and trim arguments string
  18. *
  19. * @param args arguments string
  20. * @param word first argument, output
  21. * @return true - success
  22. * @return false - arguments string does not contain anything
  23. */
  24. bool args_read_string_and_trim(string_t args, string_t word);
  25. /**
  26. * @brief Extract the first quoted argument from the argument string and trim the argument string. If the argument is not quoted, calls args_read_string_and_trim.
  27. *
  28. * @param args arguments string
  29. * @param word first argument, output, without quotes
  30. * @return true - success
  31. * @return false - arguments string does not contain anything
  32. */
  33. bool args_read_probably_quoted_string_and_trim(string_t args, string_t word);
  34. /**
  35. * @brief Convert hex ASCII values to byte array
  36. *
  37. * @param args arguments string
  38. * @param bytes byte array pointer, output
  39. * @param bytes_count needed bytes count
  40. * @return true - success
  41. * @return false - arguments string does not contain enough values, or contain non-hex ASCII values
  42. */
  43. bool args_read_hex_bytes(string_t args, uint8_t* bytes, size_t bytes_count);
  44. /************************************ HELPERS ***************************************/
  45. /**
  46. * @brief Get length of first word from arguments string
  47. *
  48. * @param args arguments string
  49. * @return size_t length of first word
  50. */
  51. size_t args_get_first_word_length(string_t args);
  52. /**
  53. * @brief Get length of arguments string
  54. *
  55. * @param args arguments string
  56. * @return size_t length of arguments string
  57. */
  58. size_t args_length(string_t args);
  59. /**
  60. * @brief Convert ASCII hex values to byte
  61. *
  62. * @param hi_nibble ASCII hi nibble character
  63. * @param low_nibble ASCII low nibble character
  64. * @param byte byte pointer, output
  65. * @return bool conversion status
  66. */
  67. bool args_char_to_hex(char hi_nibble, char low_nibble, uint8_t* byte);
  68. #ifdef __cplusplus
  69. }
  70. #endif