[lonetix/strlib] Add convenience function to reverse strings
This commit is contained in:
parent
62d3f846e6
commit
3b5b41bf54
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue