[lonetix/strlib] Add convenience function to reverse strings

pull/2/head
Lorenzo Cogotti 3 years ago
parent 62d3f846e6
commit 3b5b41bf54

@ -195,4 +195,25 @@ INLINE size_t Df_strpadr(char *s, char c, size_t n)
return i; 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 #endif

Loading…
Cancel
Save