[Xorp-hackers] [PATCH 5/5] xorp: policy: common: Strip ws from string when creating list of strings

igorm at etf.rs igorm at etf.rs
Wed Apr 11 09:26:21 PDT 2012


From: Igor Maravic <igorm at etf.rs>

Strip ws from string, so in export/import statements we could write ws betwen "," and policy name.

Signed-off-by: Igor Maravic <igorm at etf.rs>
---
 xorp/policy/common/policy_utils.cc |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/xorp/policy/common/policy_utils.cc b/xorp/policy/common/policy_utils.cc
index 92d105f..2536868 100644
--- a/xorp/policy/common/policy_utils.cc
+++ b/xorp/policy/common/policy_utils.cc
@@ -39,28 +39,38 @@
 namespace policy_utils {
 
 void
+strip_ws(string& in)
+{
+    in.erase(std::remove_if(in.begin(), in.end(), (int(*)(int))isspace), in.end());
+}
+
+void
 str_to_list(const string& in, list<string>& out)
 {
     string::size_type pos1 = 0;	// beginning of token
-    string::size_type pos2 = 0;  // end of token
-    string::size_type len = in.length();
+    string::size_type pos2 = 0;	// end of token
+
+    string in_copy(in);
+    strip_ws(in_copy);
+
+    string::size_type len = in_copy.length();
     string token;
 
     while(pos1 < len) {
 
 	// find delimiter
-        pos2 = in.find(",",pos1);
+        pos2 = in_copy.find(",",pos1);
 
 	// none found, so treat end of string as delim
         if(pos2 == string::npos) {
-                token = in.substr(pos1,len-pos1);
+                token = in_copy.substr(pos1,len-pos1);
 
                 out.push_back(token);
                 return;
         }
 
 	// grab token [delimiter found].
-        token = in.substr(pos1,pos2-pos1);
+        token = in_copy.substr(pos1,pos2-pos1);
         out.push_back(token);
         pos1 = pos2+1;
     }
-- 
1.7.5.4



More information about the Xorp-hackers mailing list