From 70a0244e04fbb3ebdfc1cf92e3ea85272673503d Mon Sep 17 00:00:00 2001 From: Daniel <74660769+SoulThy@users.noreply.github.com> Date: Sun, 11 Jun 2023 13:38:42 +0200 Subject: [PATCH] Rename `separator_get_first` and `word_get_first` ##refactor (#3559) --- librz/include/rz_util/rz_str.h | 2 +- librz/util/str.c | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/librz/include/rz_util/rz_str.h b/librz/include/rz_util/rz_str.h index c0f1691c20..f73706c8b1 100644 --- a/librz/include/rz_util/rz_str.h +++ b/librz/include/rz_util/rz_str.h @@ -155,7 +155,7 @@ static inline const char *rz_str_word_get_next0(const char *str) { return str + strlen(str) + 1; } RZ_API const char *rz_str_word_get0(const char *str, int idx); -RZ_API char *rz_str_word_get_first(const char *string); +RZ_API RZ_OWN char *rz_str_skip_separator_chars(RZ_NONNULL const char *string); RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str); RZ_API void rz_str_trim_char(RZ_NONNULL RZ_INOUT char *str, const char c); RZ_API char *rz_str_trim_dup(const char *str); diff --git a/librz/util/str.c b/librz/util/str.c index 4132610ce2..a20a007d92 100644 --- a/librz/util/str.c +++ b/librz/util/str.c @@ -618,35 +618,43 @@ RZ_API int rz_str_char_count(const char *string, char ch) { return count; } -static const char *separator_get_first(const char *text) { +static const char *skip_non_separator_chars(const char *text) { + rz_return_val_if_fail(text, NULL); for (; *text && !IS_SEPARATOR(*text); text++) ; - ; return text; } -static const char *word_get_first(const char *text) { +static const char *skip_separator_chars(const char *text) { + rz_return_val_if_fail(text, NULL); for (; *text && IS_SEPARATOR(*text); text++) ; - ; return text; } -RZ_API char *rz_str_word_get_first(const char *text) { - return strdup(word_get_first(text)); +/** + * \brief Skips over separator characters and moves to the first non-separator character in the string. + * \param text The string to process. + * \return A pointer to the first non-separator character in the string. + * + * This function iterates through the given string and skips over any separator characters until it reaches the first non-separator character. + */ +RZ_API RZ_OWN char *rz_str_skip_separator_chars(RZ_NONNULL const char *text) { + rz_return_val_if_fail(text, NULL); + return strdup(skip_separator_chars(text)); } // Counts the number of words (separated by separator characters: newlines, tabs, // return, space). See rz_util.h for more details of the IS_SEPARATOR macro. RZ_API int rz_str_word_count(const char *string) { int word; - const char *text = word_get_first(string); + const char *text = skip_separator_chars(string); for (word = 0; *text; word++) { - text = separator_get_first(text); - text = word_get_first(text); + text = skip_non_separator_chars(text); + text = skip_separator_chars(text); } return word;