[lonetix/strlib] Add convenience function to reverse strings

This commit is contained in:
Lorenzo Cogotti 2021-10-15 12:13:01 +02:00
parent 62d3f846e6
commit 3b5b41bf54
1 changed files with 21 additions and 0 deletions

View File

@ -195,4 +195,25 @@ INLINE size_t Df_strpadr(char *s, char c, size_t n)
return i;
}
/**
* \brief Reverse string in place.
*
* \return String length.
*/
INLINE size_t Df_strrev(char *s)
{
EXTERNC size_t strlen(const char *);
size_t n = strlen(s);
char *e = s + n - 1;
while (e > s) {
char c = *s;
*s++ = *e;
*e-- = c;
}
return n;
}
#endif