lv_string.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * @file lv_string.h
  3. *
  4. */
  5. #ifndef LV_STRING_H
  6. #define LV_STRING_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /*********************
  11. * INCLUDES
  12. *********************/
  13. #include "../lv_conf_internal.h"
  14. #include "../misc/lv_types.h"
  15. /*********************
  16. * DEFINES
  17. *********************/
  18. /**********************
  19. * TYPEDEFS
  20. **********************/
  21. /**********************
  22. * GLOBAL PROTOTYPES
  23. **********************/
  24. /**
  25. * @brief Copies a block of memory from a source address to a destination address.
  26. * @param dst Pointer to the destination array where the content is to be copied.
  27. * @param src Pointer to the source of data to be copied.
  28. * @param len Number of bytes to copy.
  29. * @return Pointer to the destination array.
  30. * @note The function does not check for any overlapping of the source and destination memory blocks.
  31. */
  32. void * lv_memcpy(void * dst, const void * src, size_t len);
  33. /**
  34. * @brief Fills a block of memory with a specified value.
  35. * @param dst Pointer to the destination array to fill with the specified value.
  36. * @param v Value to be set. The value is passed as an int, but the function fills
  37. * the block of memory using the unsigned char conversion of this value.
  38. * @param len Number of bytes to be set to the value.
  39. */
  40. void lv_memset(void * dst, uint8_t v, size_t len);
  41. /**
  42. * @brief Move a block of memory from source to destination
  43. * @param dst Pointer to the destination array where the content is to be copied.
  44. * @param src Pointer to the source of data to be copied.
  45. * @param len Number of bytes to copy
  46. * @return Pointer to the destination array.
  47. */
  48. void * lv_memmove(void * dst, const void * src, size_t len);
  49. /**
  50. * @brief This function will compare two memory blocks
  51. * @param p1 Pointer to the first memory block
  52. * @param p2 Pointer to the second memory block
  53. * @param len Number of bytes to compare
  54. * @return The difference between the value of the first unmatching byte.
  55. */
  56. int lv_memcmp(const void * p1, const void * p2, size_t len);
  57. /**
  58. * Same as `memset(dst, 0x00, len)`.
  59. * @param dst pointer to the destination buffer
  60. * @param len number of byte to set
  61. */
  62. static inline void lv_memzero(void * dst, size_t len)
  63. {
  64. lv_memset(dst, 0x00, len);
  65. }
  66. /**
  67. * @brief Computes the length of the string str up to, but not including the terminating null character.
  68. * @param str Pointer to the null-terminated byte string to be examined.
  69. * @return The length of the string in bytes.
  70. */
  71. size_t lv_strlen(const char * str);
  72. /**
  73. * @brief Copies up to dst_size-1 (non-null) characters from src to dst. A null terminator is always added.
  74. * @param dst Pointer to the destination array where the content is to be copied.
  75. * @param src Pointer to the source of data to be copied.
  76. * @param dst_size Maximum number of characters to be copied to dst, including the null character.
  77. * @return The length of src. The return value is equivalent to the value returned by lv_strlen(src)
  78. */
  79. size_t lv_strlcpy(char * dst, const char * src, size_t dst_size);
  80. /**
  81. * @brief Copies up to dest_size characters from the string pointed to by src to the character array pointed to by dst
  82. * and fills the remaining length with null bytes.
  83. * @param dst Pointer to the destination array where the content is to be copied.
  84. * @param src Pointer to the source of data to be copied.
  85. * @param dest_size Maximum number of characters to be copied to dst.
  86. * @return A pointer to the destination array, which is dst.
  87. * @note dst will not be null terminated if dest_size bytes were copied from src before the end of src was reached.
  88. */
  89. char * lv_strncpy(char * dst, const char * src, size_t dest_size);
  90. /**
  91. * @brief Copies the string pointed to by src, including the terminating null character,
  92. * to the character array pointed to by dst.
  93. * @param dst Pointer to the destination array where the content is to be copied.
  94. * @param src Pointer to the source of data to be copied.
  95. * @return A pointer to the destination array, which is dst.
  96. */
  97. char * lv_strcpy(char * dst, const char * src);
  98. /**
  99. * @brief This function will compare two strings without specified length.
  100. * @param s1 pointer to the first string
  101. * @param s2 pointer to the second string
  102. * @return the difference between the value of the first unmatching character.
  103. */
  104. int lv_strcmp(const char * s1, const char * s2);
  105. /**
  106. * @brief Duplicate a string by allocating a new one and copying the content.
  107. * @param src Pointer to the source of data to be copied.
  108. * @return A pointer to the new allocated string. NULL if failed.
  109. */
  110. char * lv_strdup(const char * src);
  111. /**
  112. * @brief Copies the string pointed to by src, including the terminating null character,
  113. * to the end of the string pointed to by dst.
  114. * @param dst Pointer to the destination string where the content is to be appended.
  115. * @param src Pointer to the source of data to be copied.
  116. * @return A pointer to the destination string, which is dst.
  117. */
  118. char * lv_strcat(char * dst, const char * src);
  119. /**
  120. * @brief Copies up to src_len characters from the string pointed to by src
  121. * to the end of the string pointed to by dst.
  122. * A terminating null character is appended to dst even if no null character
  123. * was encountered in src after src_len characters were copied.
  124. * @param dst Pointer to the destination string where the content is to be appended.
  125. * @param src Pointer to the source of data to be copied.
  126. * @param src_len Maximum number of characters from src to be copied to the end of dst.
  127. * @return A pointer to the destination string, which is dst.
  128. */
  129. char * lv_strncat(char * dst, const char * src, size_t src_len);
  130. /**********************
  131. * MACROS
  132. **********************/
  133. #ifdef __cplusplus
  134. } /*extern "C"*/
  135. #endif
  136. #endif /*LV_STRING_H*/