From d543d9cadfd69c01eff883cb2bab927d6a3c1564 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 8 Mar 2010 15:26:09 +0100 Subject: Adding a helper function that translates single characters in a string. --- src/libstrongswan/utils.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/libstrongswan/utils.c') diff --git a/src/libstrongswan/utils.c b/src/libstrongswan/utils.c index b1b860351..fd313843e 100644 --- a/src/libstrongswan/utils.c +++ b/src/libstrongswan/utils.c @@ -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. */ -- cgit v1.2.3