[utils] string_[rl]strip => string_[rl]trim, removing warning about allocation
This commit is contained in:
@@ -151,16 +151,7 @@ bool utf8_is_letter(int32_t ch) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Caution: this function does not make a copy of str. Keep original pointer and free that, e.g.
|
size_t string_rtrim(char *str) {
|
||||||
|
|
||||||
char *str = strdup("foobar");
|
|
||||||
// Use stripped for comparison, etc. but copy the string if you need to keep a pointer to it
|
|
||||||
char *stripped = string_strip_whitespace(str);
|
|
||||||
// Only free the original pointer to str
|
|
||||||
free(str);
|
|
||||||
*/
|
|
||||||
|
|
||||||
size_t string_rstrip(char *str) {
|
|
||||||
size_t spaces = 0;
|
size_t spaces = 0;
|
||||||
|
|
||||||
char *end = str + strlen(str) - 1;
|
char *end = str + strlen(str) - 1;
|
||||||
@@ -174,7 +165,7 @@ size_t string_rstrip(char *str) {
|
|||||||
return spaces;
|
return spaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t string_lstrip(char *str) {
|
size_t string_ltrim(char *str) {
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
size_t spaces = 0;
|
size_t spaces = 0;
|
||||||
@@ -193,7 +184,7 @@ size_t string_lstrip(char *str) {
|
|||||||
return spaces;
|
return spaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t string_strip(char *str) {
|
size_t string_trim(char *str) {
|
||||||
size_t spaces = string_lstrip(str);
|
size_t spaces = string_lstrip(str);
|
||||||
spaces += string_rstrip(str);
|
spaces += string_rstrip(str);
|
||||||
return spaces;
|
return spaces;
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ char *utf8_reversed_string(const char *s); // returns a copy, caller frees
|
|||||||
ssize_t utf8proc_iterate_reversed(const uint8_t *str, const uint8_t *start, int32_t *dst);
|
ssize_t utf8proc_iterate_reversed(const uint8_t *str, const uint8_t *start, int32_t *dst);
|
||||||
bool utf8_is_letter(int32_t ch);
|
bool utf8_is_letter(int32_t ch);
|
||||||
|
|
||||||
size_t string_lstrip(char *str);
|
size_t string_ltrim(char *str);
|
||||||
size_t string_rstrip(char *str);
|
size_t string_rtrim(char *str);
|
||||||
size_t string_strip(char *str);
|
size_t string_trim(char *str);
|
||||||
|
|
||||||
/* Caller has to free the original string,
|
/* Caller has to free the original string,
|
||||||
also keep in mind that after operating on a char array,
|
also keep in mind that after operating on a char array,
|
||||||
|
|||||||
Reference in New Issue
Block a user