[glibmm/glibmm-2-64] Glib::build_filename(): Fix the template overload



commit 54a5d391f4107bff58b5e1d9cb248975968ea074
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Mar 20 18:58:17 2020 +0100

    Glib::build_filename(): Fix the template overload
    
    and add some tests to tests/glibmm_buildfilename/main.cc.
    
    Fixes #71

 README                             |  2 +-
 glib/src/miscutils.hg              | 15 ++++++++++-----
 tests/glibmm_buildfilename/main.cc | 25 +++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/README b/README
index b6417674..51f662ee 100644
--- a/README
+++ b/README
@@ -33,7 +33,7 @@ files used by Autotools.
   $ cd your_builddir
 
 If the tarball was made with Autotools, you must enable maintainer-mode:
-  $ meson configure -Dmaintainer-mode=yes
+  $ meson configure -Dmaintainer-mode=true
 
 Then, regardless of how the tarball was made:
   $ ninja
diff --git a/glib/src/miscutils.hg b/glib/src/miscutils.hg
index f4742542..9fe6ea7d 100644
--- a/glib/src/miscutils.hg
+++ b/glib/src/miscutils.hg
@@ -389,20 +389,25 @@ std::string canonicalize_filename(StdStringView filename, StdStringView relative
 GLIBMM_API
 std::string build_filename(const Glib::ArrayHandle<std::string>& elements);
 
-/** Creates a filename from one or more elements using the correct separator for filenames.
+/** Creates a filename from two or more elements using the correct separator for filenames.
  * No attempt is made to force the resulting filename to be an absolute path.
  * If the first element is a relative path, the result will be a relative path.
+ * @tparam String1 std::string or const char*.
+ * @tparam String2 std::string or const char*.
  * @tparam Strings std::string or const char*.
- * @param strings The path elements.
+ * @param elem1 First path element.
+ * @param elem2 Second path element.
+ * @param strings The following path elements, if any.
  * @return The resulting path.
  *
  * @newin{2,64}
  */
-template <typename... Strings>
-std::string build_filename(const Strings&... strings)
+template <typename String1, typename String2, typename... Strings>
+std::string build_filename(const String1& elem1, const String2& elem2, const Strings&... strings)
 {
   return Glib::convert_return_gchar_ptr_to_stdstring(
-    g_build_filename(StdStringView(strings).c_str()..., nullptr));
+    g_build_filename(StdStringView(elem1).c_str(), StdStringView(elem2).c_str(),
+      StdStringView(strings).c_str()..., nullptr));
 }
 
 // When the templated build_filename() overload was added, the following
diff --git a/tests/glibmm_buildfilename/main.cc b/tests/glibmm_buildfilename/main.cc
index 2460622b..c72f2066 100644
--- a/tests/glibmm_buildfilename/main.cc
+++ b/tests/glibmm_buildfilename/main.cc
@@ -1,6 +1,7 @@
 #include <glibmm.h>
 #include <iostream>
 #include <string.h>
+#include <vector>
 
 // Use this line if you want debug output:
 // std::ostream& ostr = std::cout;
@@ -39,5 +40,29 @@ main(int, char**)
   path = Glib::build_filename(dir_1, dir_2, dir_1, dir_3, dir_2, dir_3, dir_1, dir_2, file_2);
   ostr << "Path 5: " << path << std::endl;
 
+  path = Glib::build_filename(dir_2, file_2);
+  ostr << "Path 6: " << path << std::endl;
+
+  path = Glib::build_filename(dir_2, file_3);
+  ostr << "Path 7: " << path << std::endl;
+
+  path = Glib::build_filename(dir_3, file_3);
+  ostr << "Path 8: " << path << std::endl;
+
+//  path = Glib::build_filename(dir_1);
+//  ostr << "Path 9: " << path << std::endl;
+
+//  path = Glib::build_filename(nullptr);
+//  ostr << "Path 10: " << path << std::endl;
+
+  std::vector<std::string> pathv;
+  pathv.push_back("vdir1");
+  path = Glib::build_filename(pathv);
+  ostr << "Path v1: " << path << std::endl;
+
+  pathv.push_back("vdir2");
+  path = Glib::build_filename(pathv);
+  ostr << "Path v2: " << path << std::endl;
+
   return EXIT_SUCCESS;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]