mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Improve trim() function
Did not cope well with trailing spaces or entirely blank strings.
This commit is contained in:
@@ -413,12 +413,16 @@ trim(char *s)
|
||||
--s2;
|
||||
*(s2 + 1) = '\0';
|
||||
|
||||
/* String is all whitespace - no need for further processing */
|
||||
if (s2 + 1 == s1)
|
||||
return s;
|
||||
|
||||
/* Trim left side */
|
||||
while ((isspace(*s1)) && (s1 < s2))
|
||||
++s1;
|
||||
|
||||
/* Copy finished string */
|
||||
memmove(s, s1, s2 - s1);
|
||||
memmove(s, s1, (s2 - s1) + 1);
|
||||
s[s2 - s1 + 1] = '\0';
|
||||
|
||||
return s;
|
||||
|
||||
Reference in New Issue
Block a user