Browse code

core: macro helper to trim zeros from str value

Daniel-Constantin Mierla authored on 06/09/2016 10:49:16
Showing 1 changed files
... ...
@@ -105,5 +105,19 @@ static inline void trim(str* _s)
105 105
 		for(;(_s_).s[0]==' ';(_s_).s=(_s_).s+1,(_s_).len--);			\
106 106
 																		\
107 107
 	} while(0);
108
-	
108
+
109
+/*
110
+ * right and left zero trimming
111
+ *
112
+ * WARNING: String structure will be modified !
113
+ *          Make a copy otherwise you might be
114
+ *          unable to free _s_->s for example !
115
+ */
116
+#define trim_zeros_lr(_s_)												\
117
+	do{																	\
118
+		for(;(_s_)->s[(_s_)->len-1]=='\0';(_s_)->s[--(_s_)->len]=0);	\
119
+		for(;(_s_)->s[0]=='\0';(_s_)->s=(_s_)->s+1,(_s_)->len--);		\
120
+																		\
121
+	} while(0);
122
+
109 123
 #endif /* TRIM_H */