Skip to content

Commit

Permalink
core: macro helper to trim zeros from str value
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Sep 6, 2016
1 parent 0cec861 commit fe1fdba
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion trim.h
Expand Up @@ -105,5 +105,19 @@ static inline void trim(str* _s)
for(;(_s_).s[0]==' ';(_s_).s=(_s_).s+1,(_s_).len--); \
\
} while(0);


/*
* right and left zero trimming
*
* WARNING: String structure will be modified !
* Make a copy otherwise you might be
* unable to free _s_->s for example !
*/
#define trim_zeros_lr(_s_) \
do{ \
for(;(_s_)->s[(_s_)->len-1]=='\0';(_s_)->s[--(_s_)->len]=0); \
for(;(_s_)->s[0]=='\0';(_s_)->s=(_s_)->s+1,(_s_)->len--); \
\
} while(0);

#endif /* TRIM_H */

0 comments on commit fe1fdba

Please sign in to comment.