Adding a helper function that translates single characters in a string.

This commit is contained in:
Tobias Brunner
2010-03-08 15:34:38 +01:00
parent d14203b009
commit d543d9cadf
3 changed files with 32 additions and 19 deletions
+22
View File
@@ -116,6 +116,28 @@ void *memstr(const void *haystack, const char *needle, size_t n)
return NULL;
}
/**
* Described in header.
*/
char* translate(char *str, const char *from, const char *to)
{
char *pos = str;
if (strlen(from) != strlen(to))
{
return str;
}
while (pos && *pos)
{
char *match;
if ((match = strchr(from, *pos)) != NULL)
{
*pos = to[match - from];
}
pos++;
}
return str;
}
/**
* Described in header.
*/