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

github.com/FormerLurker/ArcWelderLib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'GcodeProcessorLib/utilities.cpp')
-rw-r--r--GcodeProcessorLib/utilities.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/GcodeProcessorLib/utilities.cpp b/GcodeProcessorLib/utilities.cpp
index c0cc6c8..d16f8f4 100644
--- a/GcodeProcessorLib/utilities.cpp
+++ b/GcodeProcessorLib/utilities.cpp
@@ -291,6 +291,11 @@ std::string utilities::join(const std::vector<std::string> strings, std::string
}
return output;
}
+/* Might need this later
+bool utilities::contains(const std::string source, const std::string substring)
+{
+ return source.find(substring, 0) != std::string::npos;
+}*/
std::istream& utilities::safe_get_line(std::istream& is, std::string& t)
{
@@ -471,6 +476,16 @@ bool utilities::get_temp_file_path_for_file(const std::string& file_path, std::s
return true;
}
+bool utilities::does_file_exist(const std::string& file_path)
+{
+ FILE* file;
+ if (file = fopen(file_path.c_str(), "r")) {
+ fclose(file);
+ return true;
+ }
+ return false;
+}
+
double utilities::hypot(double x, double y)
{
if (x < 0) x = -x;
@@ -703,10 +718,13 @@ bool case_insensitive_compare(std::string& str1, std::string& str2)
*/
std::string utilities::replace(std::string subject, const std::string& search, const std::string& replace) {
- size_t pos = 0;
- while ((pos = subject.find(search, pos)) != std::string::npos) {
- subject.replace(pos, search.length(), replace);
- pos += replace.length();
+ if (search.length() > 0)
+ {
+ size_t pos = 0;
+ while ((pos = subject.find(search, pos)) != std::string::npos) {
+ subject.replace(pos, search.length(), replace);
+ pos += replace.length();
+ }
}
return subject;
}