Ver Fonte

2009-06-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added strjoin function template. Use it in pathJoin()
	* src/Util.h
	* src/a2functional.h
Tatsuhiro Tsujikawa há 16 anos atrás
pai
commit
a8c278d026
3 ficheiros alterados com 24 adições e 17 exclusões
  1. 6 0
      ChangeLog
  2. 1 5
      src/Util.h
  3. 17 12
      src/a2functional.h

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2009-06-06  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added strjoin function template. Use it in pathJoin()
+	* src/Util.h
+	* src/a2functional.h
+
 2009-06-06  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Avoid intermediate object during string concatenation.  Replaced

+ 1 - 5
src/Util.h

@@ -299,11 +299,7 @@ public:
 	elements.push_back(*first);
       }
     }
-    if(elements.empty()) {
-      return "";
-    }
-    return std::accumulate(elements.begin()+1, elements.end(), elements[0],
-			   Concat("/"));
+    return strjoin(elements.begin(), elements.end(), "/");
   }
 
   // Parses INDEX=PATH format string. INDEX must be an unsigned

+ 17 - 12
src/a2functional.h

@@ -165,18 +165,6 @@ public:
   }
 };
 
-class Concat {
-private:
-  std::string _delim;
-public:
-  Concat(const std::string& delim = A2STR::NIL):_delim(delim) {}
-
-  std::string operator()(const std::string& s1, const std::string& s2) const
-  {
-    return s1+_delim+s2;
-  }
-};
-
 class Deleter {
 public:
   template<class T>
@@ -216,6 +204,23 @@ public:
   }
 };
 
+template<typename InputIterator, typename DelimiterType>
+std::string strjoin(InputIterator first, InputIterator last,
+		    const DelimiterType& delim)
+{
+  std::string result;
+  if(first == last) {
+    return result;
+  }
+  InputIterator beforeLast = last-1;
+  for(; first != beforeLast; ++first) {
+    result += *first;
+    result += delim;
+  }
+  result += *beforeLast;
+  return result;
+}
+
 template<typename T1, typename T2>
 inline std::string strconcat(const T1& a1, const T2& a2)
 {