[sr-dev] git:master:fe1fdbaf: core: macro helper to trim zeros from str value

Daniel-Constantin Mierla miconda at gmail.com
Tue Sep 6 12:52:05 CEST 2016


Module: kamailio
Branch: master
Commit: fe1fdbaf24ac0e4e18527e0bdfd2f2e1b217dc1b
URL: https://github.com/kamailio/kamailio/commit/fe1fdbaf24ac0e4e18527e0bdfd2f2e1b217dc1b

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2016-09-06T12:51:45+02:00

core: macro helper to trim zeros from str value

---

Modified: trim.h

---

Diff:  https://github.com/kamailio/kamailio/commit/fe1fdbaf24ac0e4e18527e0bdfd2f2e1b217dc1b.diff
Patch: https://github.com/kamailio/kamailio/commit/fe1fdbaf24ac0e4e18527e0bdfd2f2e1b217dc1b.patch

---

diff --git a/trim.h b/trim.h
index 4989075..baee6a0 100644
--- a/trim.h
+++ b/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 */




More information about the sr-dev mailing list