Fix 1818856: External application render targets seem to be broken. We can't use...
[synfig.git] / ETL / trunk / ETL / _stringf.h
index b702689..aaa87fd 100644 (file)
 #define ETL_STRPRINTF_MAX_LENGTH       (800)
 #endif
 
+#ifdef WIN32
+#define POPEN_BINARY_WRITE_TYPE "wb"
+#else
+#define POPEN_BINARY_WRITE_TYPE "w"
+#endif
+
 /* === T Y P E D E F S ===================================================== */
 
 _ETL_BEGIN_CDECLS
@@ -198,6 +204,28 @@ dirname(const std::string &str)
        return std::string(str.begin(),iter);
 }
 
+// filename_extension("/f.e/d.c") => ".c"
+inline std::string
+filename_extension(const std::string &str)
+{
+       std::string base = basename(str);
+       std::string::size_type pos = base.find_last_of('.');
+       if (pos == std::string::npos) return std::string();
+       return base.substr(pos);
+}
+
+// filename_sans_extension("/f.e/d.c") => "/f.e/d"
+inline std::string
+filename_sans_extension(const std::string &str)
+{
+       std::string base = basename(str);
+       std::string::size_type pos = base.find_last_of('.');
+       if (pos == std::string::npos) return str;
+       std::string dir = dirname(str);
+       if (dir == ".") return base.substr(0,pos);
+       return dir + ETL_DIRECTORY_SEPARATOR + base.substr(0,pos);
+}
+
 inline bool
 is_absolute_path(const std::string &path)
 {