+static char *
+clean_string(char *dest, const unsigned char *src, size_t len)
+{
+ char *d = dest;
+ s_assert(0 != dest);
+ s_assert(0 != src);
+
+ if(dest == NULL || src == NULL)
+ return NULL;
+
+ while (*src && (len > 1))
+ {
+ if(*src & 0x80) /* if high bit is set */
+ {
+ *d++ = '.';
+ --len;
+ if(len <= 1)
+ break;
+ }
+ else if(!IsPrint(*src)) /* if NOT printable */
+ {
+ *d++ = '^';
+ --len;
+ if(len <= 1)
+ break;
+ *d++ = 0x40 + *src; /* turn it into a printable */
+ }
+ else
+ *d++ = *src;
+ ++src;
+ --len;
+ }
+ *d = '\0';
+ return dest;
+}