// 判断是否为空白字符
inline bool is_padding(char ch)
{
return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r';
}
// 去除空白字符
char *strdepad(char *str)
{
char *temp;
size_t len;
if (!str)
return str;
if (!*str)
return str;
temp = str;
/* remove preceding spaces/tabs */
while (is_padding(*temp))
++temp;
len = strlen(temp);
if (temp != str)
memmove(str, temp, len + 1);
if (len) {
temp = str + (len - 1);
while (is_padding(*temp))
*(temp--) = 0;
}
return str;
}