Generalize string trunctation util function
Add an additional argument to let the client pass the possible end chars.
This commit is contained in:
@@ -293,9 +293,9 @@ error:
|
||||
}
|
||||
|
||||
size_t
|
||||
sc_str_truncate_first_line(char *data, size_t len) {
|
||||
sc_str_truncate(char *data, size_t len, const char *endchars) {
|
||||
data[len - 1] = '\0';
|
||||
char *eol = strpbrk(data, "\r\n");
|
||||
char *eol = strpbrk(data, endchars);
|
||||
if (eol) {
|
||||
*eol = '\0';
|
||||
len = eol - data;
|
||||
|
||||
@@ -104,7 +104,7 @@ char *
|
||||
sc_str_wrap_lines(const char *input, unsigned columns, unsigned indent);
|
||||
|
||||
/**
|
||||
* Truncate the data after the first line
|
||||
* Truncate the data after any of the characters from `endchars`
|
||||
*
|
||||
* An '\0' is always written at the end of the data, even if no newline
|
||||
* character is encountered.
|
||||
@@ -112,6 +112,6 @@ sc_str_wrap_lines(const char *input, unsigned columns, unsigned indent);
|
||||
* Return the size of the resulting line.
|
||||
*/
|
||||
size_t
|
||||
sc_str_truncate_first_line(char *data, size_t len);
|
||||
sc_str_truncate(char *data, size_t len, const char *endchars);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user