mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Refactor logic to remove trailing CR/LF characters from strings
b654714
has reworked the way trailing CR/LF characters are removed from
strings. This commit introduces a new routine in common/string.c and
refactors the code so as the logic is in a single place, mostly.
Author: Michael Paquier
Reviewed-by: Bruce Momjian
Discussion: https://postgr.es/m/20190801031820.GF29334@paquier.xyz
This commit is contained in:
@@ -90,3 +90,25 @@ pg_clean_ascii(char *str)
|
||||
*p = '?';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* pg_strip_crlf -- Remove any trailing newline and carriage return
|
||||
*
|
||||
* Removes any trailing newline and carriage return characters (\r on
|
||||
* Windows) in the input string, zero-terminating it.
|
||||
*
|
||||
* The passed in string must be zero-terminated. This function returns
|
||||
* the new length of the string.
|
||||
*/
|
||||
int
|
||||
pg_strip_crlf(char *str)
|
||||
{
|
||||
int len = strlen(str);
|
||||
|
||||
while (len > 0 && (str[len - 1] == '\n' ||
|
||||
str[len - 1] == '\r'))
|
||||
str[--len] = '\0';
|
||||
|
||||
return len;
|
||||
}
|
||||
|
Reference in New Issue
Block a user