diff options
author | FormerLurker <hochgebe@gmail.com> | 2021-11-25 22:36:18 +0300 |
---|---|---|
committer | FormerLurker <hochgebe@gmail.com> | 2021-11-25 22:36:18 +0300 |
commit | 9d1d644013ea74e89ac81f42006b115474cf955e (patch) | |
tree | b35b72771f470e3af304cc60d3558957180eb162 /GcodeProcessorLib | |
parent | 274b33a225485571a012471e997738e437607fcc (diff) |
Clean up error correction and debug parameters for the console applications. Update readme.md.
Diffstat (limited to 'GcodeProcessorLib')
-rw-r--r-- | GcodeProcessorLib/fpconv.h | 3 | ||||
-rw-r--r-- | GcodeProcessorLib/utilities.cpp | 26 | ||||
-rw-r--r-- | GcodeProcessorLib/utilities.h | 4 |
3 files changed, 28 insertions, 5 deletions
diff --git a/GcodeProcessorLib/fpconv.h b/GcodeProcessorLib/fpconv.h index 8afcb21..29af997 100644 --- a/GcodeProcessorLib/fpconv.h +++ b/GcodeProcessorLib/fpconv.h @@ -52,6 +52,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef FPCONV_H #define FPCONV_H + +#define FPCONV_COPYRIGHT_STRING "Fpconv is an algorithm for producing fast floating point strings, which was added with the following notice: Copyright (C) 2014 Milo Yip. The original fpconv algorithm provides the following notice: Copyright(c) 2013 Andreas Samoljuk." + /* Fast and accurate double to string conversion based on Florian Loitsch's * Grisu-algorithm[1]. * 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; } diff --git a/GcodeProcessorLib/utilities.h b/GcodeProcessorLib/utilities.h index 7aa45b0..a71a36e 100644 --- a/GcodeProcessorLib/utilities.h +++ b/GcodeProcessorLib/utilities.h @@ -86,7 +86,7 @@ namespace utilities{ std::string join(const std::string* strings, size_t length, std::string sep); std::string join(const std::vector<std::string> strings, std::string sep); - + // bool contains(const std::string source, const std::string substring); // Might need this later std::istream& safe_get_line(std::istream& is, std::string& t); std::string center(std::string input, int width); @@ -105,6 +105,8 @@ namespace utilities{ std::string create_uuid(); + bool does_file_exist(const std::string& file_path); + bool get_temp_file_path_for_file(const std::string& file_path, std::string& temp_file_path); double hypot(double x, double y); |