mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
Add str_clean_whitespaces_simple and str_skip_to_whitespace_const
This commit is contained in:
parent
8e8e05c4f3
commit
3d787ceada
|
@ -1913,6 +1913,38 @@ void str_clean_whitespaces(char *str_in)
|
|||
}
|
||||
}
|
||||
|
||||
/* removes leading and trailing spaces */
|
||||
void str_clean_whitespaces_simple(char *str_in)
|
||||
{
|
||||
char *read = str_in;
|
||||
char *write = str_in;
|
||||
|
||||
/* skip initial whitespace */
|
||||
while(*read == ' ')
|
||||
read++;
|
||||
|
||||
/* end of read string is detected in the loop */
|
||||
while(1)
|
||||
{
|
||||
/* skip whitespace */
|
||||
int found_whitespace = 0;
|
||||
for(; *read == ' ' && !found_whitespace; read++)
|
||||
found_whitespace = 1;
|
||||
/* if not at the end of the string, put a found whitespace here */
|
||||
if(*read)
|
||||
{
|
||||
if(found_whitespace)
|
||||
*write++ = ' ';
|
||||
*write++ = *read++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*write = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *str_skip_to_whitespace(char *str)
|
||||
{
|
||||
while(*str && (*str != ' ' && *str != '\t' && *str != '\n'))
|
||||
|
@ -1920,6 +1952,13 @@ char *str_skip_to_whitespace(char *str)
|
|||
return str;
|
||||
}
|
||||
|
||||
const char *str_skip_to_whitespace_const(const char *str)
|
||||
{
|
||||
while(*str && (*str != ' ' && *str != '\t' && *str != '\n'))
|
||||
str++;
|
||||
return str;
|
||||
}
|
||||
|
||||
char *str_skip_whitespaces(char *str)
|
||||
{
|
||||
while(*str && (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r'))
|
||||
|
|
|
@ -912,6 +912,18 @@ int str_check_pathname(const char* str);
|
|||
*/
|
||||
void str_clean_whitespaces(char *str);
|
||||
|
||||
/*
|
||||
Function: str_clean_whitespaces_simple
|
||||
Removes leading and trailing spaces
|
||||
|
||||
Parameters:
|
||||
str - String to clean up
|
||||
|
||||
Remarks:
|
||||
- The strings are treated as zero-terminated strings.
|
||||
*/
|
||||
void str_clean_whitespaces_simple(char *str);
|
||||
|
||||
/*
|
||||
Function: str_skip_to_whitespace
|
||||
Skips leading non-whitespace characters(all but ' ', '\t', '\n', '\r').
|
||||
|
@ -928,6 +940,12 @@ void str_clean_whitespaces(char *str);
|
|||
*/
|
||||
char *str_skip_to_whitespace(char *str);
|
||||
|
||||
/*
|
||||
Function: str_skip_to_whitespace_const
|
||||
See str_skip_to_whitespace.
|
||||
*/
|
||||
const char *str_skip_to_whitespace_const(const char *str);
|
||||
|
||||
/*
|
||||
Function: str_skip_whitespaces
|
||||
Skips leading whitespace characters(' ', '\t', '\n', '\r').
|
||||
|
|
Loading…
Reference in a new issue