qdf_str.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * DOC: qdf_str
  20. * QCA driver framework (QDF) string APIs.
  21. */
  22. #ifndef __QDF_STR_H
  23. #define __QDF_STR_H
  24. #include "i_qdf_str.h"
  25. #include "qdf_types.h"
  26. /**
  27. * qdf_is_space() - check if @c is a whitespace character
  28. * @c: the character to check
  29. *
  30. * Whitespace characters include HT, LF, VT, FF, CR, space, and nbsp
  31. *
  32. * Return: true if @ is a whitespace character
  33. */
  34. static inline bool qdf_is_space(char c)
  35. {
  36. return __qdf_is_space(c);
  37. }
  38. /**
  39. * qdf_str_dup() - duplicate null-terminated string @src
  40. * @dest: double pointer to be populated
  41. * @src: the null-terminated string to be duplicated
  42. *
  43. * @dest must be freed using qdf_mem_free() to avoid memory leaks.
  44. *
  45. * Return: QDF_STATUS; @dest set to NULL on failure, a valid address on success
  46. */
  47. QDF_STATUS qdf_str_dup(char **dest, const char *src);
  48. /**
  49. * qdf_str_left_trim() - Trim any leading whitespace from @str
  50. * @str: the string to trim
  51. *
  52. * Return: A pointer to the first non-space character in @str
  53. */
  54. static inline const char *qdf_str_left_trim(const char *str)
  55. {
  56. return __qdf_str_left_trim(str);
  57. }
  58. /**
  59. * qdf_str_right_trim() - Trim any trailing whitespace from @str
  60. * @str: the string to trim
  61. *
  62. * Note: The first trailing whitespace character is replaced with a
  63. * null-terminator
  64. *
  65. * Return: None
  66. */
  67. void qdf_str_right_trim(char *str);
  68. /**
  69. * qdf_str_trim() - Trim any leading/trailing whitespace from @str
  70. * @str: the string to trim
  71. *
  72. * Note: The first trailing whitespace character is replaced with a
  73. * null-terminator
  74. *
  75. * Return: A pointer to the first non-space character in @str
  76. */
  77. static inline char *qdf_str_trim(char *str)
  78. {
  79. return __qdf_str_trim(str);
  80. }
  81. /**
  82. * qdf_str_nlen() - Get string length up to @limit characters
  83. * @str: the string to get the length of
  84. * @limit: the maximum number of characters to check
  85. *
  86. * Return: length of @str, or @limit if the end is not found
  87. */
  88. static inline qdf_size_t qdf_str_nlen(const char *str, size_t limit)
  89. {
  90. return __qdf_str_nlen(str, limit);
  91. }
  92. #endif /* __QDF_STR_H */