args.h 2.0 KB

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