]> code.citadel.org Git - citadel.git/blobdiff - citadel/tools.c
* strip blanks / whitespaces more effectively
[citadel.git] / citadel / tools.c
index 4e1129a731a72ca39e0a68af74b9f32f0d5622d8..4a5e4cac0fa0a24305fcdf9469e38e1840be7654 100644 (file)
@@ -440,12 +440,18 @@ char *rfc2047encode(char *line, long length)
  */
 void striplt(char *buf)
 {
+       size_t len;
+       int a;
        if (IsEmptyStr(buf)) return;
-        while ((!IsEmptyStr(buf)) && (isspace(buf[0])))
-                strcpy(buf, &buf[1]);
+       len = strlen(buf);
+        while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
+                buf[--len] = 0;
        if (IsEmptyStr(buf)) return;
-        while ((!IsEmptyStr(buf)) && (isspace(buf[strlen(buf) - 1])))
-                buf[strlen(buf) - 1] = 0;
+       a = 0;
+        while ((!IsEmptyStr(buf)) && (isspace(buf[a])))
+               a++;
+       if (a > 0)
+                memmove(buf, &buf[a], len - a + 1);
 }