浏览代码

core: macro helper to trim zeros from str value

Daniel-Constantin Mierla 9 年之前
父节点
当前提交
fe1fdbaf24
共有 1 个文件被更改,包括 15 次插入1 次删除
  1. 15 1
      trim.h

+ 15 - 1
trim.h

@@ -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 */