Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortamasmeszaros <meszaros.q@gmail.com>2020-02-03 13:18:33 +0300
committertamasmeszaros <meszaros.q@gmail.com>2020-02-03 18:00:53 +0300
commit0c4797e92ed0581fddb23949dce3c0dea9c9b577 (patch)
treedcb00ce9ffcd85695964d12acf387577b064606b /src
parentf09bed32b6adbc9ed43a6f4efc07c720acfa153b (diff)
use vsnprintf instead of snprintf in string_printf function
Also, revert to old location: Utils.hpp and utils.cpp
Diffstat (limited to 'src')
-rw-r--r--src/libslic3r/Utils.hpp2
-rw-r--r--src/libslic3r/libslic3r.h17
-rw-r--r--src/libslic3r/utils.cpp21
3 files changed, 23 insertions, 17 deletions
diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp
index bc6aa20fc..06c435809 100644
--- a/src/libslic3r/Utils.hpp
+++ b/src/libslic3r/Utils.hpp
@@ -93,6 +93,8 @@ namespace PerlUtils {
extern std::string path_to_parent_path(const char *src);
};
+std::string string_printf(const char *format, ...);
+
// Standard "generated by Slic3r version xxx timestamp xxx" header string,
// to be placed at the top of Slic3r generated files.
std::string header_slic3r_generated();
diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h
index 7d9558f1e..d3e4992ce 100644
--- a/src/libslic3r/libslic3r.h
+++ b/src/libslic3r/libslic3r.h
@@ -230,23 +230,6 @@ static inline bool is_approx(Number value, Number test_value)
return std::fabs(double(value) - double(test_value)) < double(EPSILON);
}
-template<class...Args>
-std::string string_printf(const char *const _fmt, Args &&...args)
-{
- static const size_t INITIAL_LEN = 1024;
- std::vector<char> buffer(INITIAL_LEN, '\0');
-
- auto fmt = std::string("%s") + _fmt;
- int bufflen = snprintf(buffer.data(), INITIAL_LEN - 1, fmt.c_str(), "", std::forward<Args>(args)...);
-
- if (bufflen >= int(INITIAL_LEN)) {
- buffer.resize(size_t(bufflen) + 1);
- snprintf(buffer.data(), buffer.size(), fmt.c_str(), "", std::forward<Args>(args)...);
- }
-
- return std::string(buffer.begin(), buffer.begin() + bufflen);
-}
-
} // namespace Slic3r
#endif
diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp
index 9f0afa061..f78a2b54d 100644
--- a/src/libslic3r/utils.cpp
+++ b/src/libslic3r/utils.cpp
@@ -577,6 +577,27 @@ namespace PerlUtils {
std::string path_to_parent_path(const char *src) { return boost::filesystem::path(src).parent_path().string(); }
};
+
+std::string string_printf(const char *format, ...)
+{
+ va_list args1;
+ va_start(args1, format);
+ va_list args2;
+ va_copy(args2, args1);
+
+ static const size_t INITIAL_LEN = 1024;
+ std::vector<char> buffer(INITIAL_LEN, '\0');
+
+ int bufflen = ::vsnprintf(buffer.data(), INITIAL_LEN - 1, format, args1);
+
+ if (bufflen >= int(INITIAL_LEN)) {
+ buffer.resize(size_t(bufflen) + 1);
+ ::vsnprintf(buffer.data(), buffer.size(), format, args2);
+ }
+
+ return std::string(buffer.begin(), buffer.begin() + bufflen);
+}
+
std::string header_slic3r_generated()
{
return std::string("generated by " SLIC3R_APP_NAME " " SLIC3R_VERSION " on " ) + Utils::utc_timestamp();