Commit 995eadb4 authored by Alejandro Mery's avatar Alejandro Mery
Browse files

fex2bin: use ctype to make alltrim() easier to digest

parent 6f4f4f86
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*/ */
#include "fex2bin.h" #include "fex2bin.h"
#include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
...@@ -27,28 +28,22 @@ ...@@ -27,28 +28,22 @@
static inline char *alltrim(char *s, size_t *l) static inline char *alltrim(char *s, size_t *l)
{ {
char *p; char *p;
while (*s == ' ' || *s == '\t') while (isblank(*s))
s++; s++;
p = s; p = s;
while (*++p) while (*++p)
; /* seek \0 */ ; /* seek \0 */
if (p>s && p[-1] == '\n') { if (p>s+1 && p[-2] == '\r' && p[-1] == '\n')
if (p>s+1 && p[-2] == '\r') p -= 2;
p-=2; else if (p>s && p[-1] == '\n')
else p -= 1;
p-=1; *p-- = '\0';
}
while (p>s) { while (p>s && isblank(*p))
if (*p == ' ' || *p == '\t') *p-- = '\0';
p--;
else
break;
}
*p = '\0'; *l = p-s+1;
*l = p-s;
return s; return s;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment