Adding a helper function that translates single characters in a string.
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user