Merge branch 'master' into parse-logical-keyword

This commit is contained in:
Axel Kohlmeyer
2021-09-20 20:41:48 -04:00
414 changed files with 2159 additions and 2576 deletions

View File

@ -18,6 +18,7 @@
#include "compute.h"
#include "error.h"
#include "fix.h"
#include "fmt/chrono.h"
#include "memory.h"
#include "modify.h"
#include "text_file_reader.h"
@ -28,6 +29,7 @@
#include <cctype>
#include <cerrno>
#include <cstring>
#include <ctime>
#if defined(__linux__)
#include <unistd.h> // for readlink
@ -165,7 +167,7 @@ std::string utils::getsyserror()
/** On Linux the folder /proc/self/fd holds symbolic links to the actual
* pathnames associated with each open file descriptor of the current process.
* On macOS the same kind of information can be obtained using ``fcntl(fd,F_GETPATH,buf)``.
* On MacOS the same kind of information can be obtained using ``fcntl(fd,F_GETPATH,buf)``.
* On Windows we use ``GetFinalPathNameByHandleA()`` which is available with
* Windows Vista and later.
*
@ -545,7 +547,7 @@ void utils::bounds(const char *file, int line, const std::string &str,
return;
}
found = str.find_first_of("*");
found = str.find_first_of('*');
if (found == std::string::npos) { // contains no '*'
nlo = nhi = strtol(str.c_str(), nullptr, 10);
} else if (str.size() == 1) { // is only '*'
@ -626,8 +628,8 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
// split off the compute/fix/property ID, the wildcard and trailing text
size_t first = word.find("[");
size_t second = word.find("]", first + 1);
size_t first = word.find('[');
size_t second = word.find(']', first + 1);
if (word[1] == '2')
id = word.substr(3, first - 3);
else
@ -770,7 +772,7 @@ std::string utils::trim(const std::string &line)
std::string utils::trim_comment(const std::string &line)
{
auto end = line.find_first_of("#");
auto end = line.find_first_of('#');
if (end != std::string::npos) { return line.substr(0, end); }
return std::string(line);
}
@ -1073,7 +1075,7 @@ std::string utils::path_basename(const std::string &path)
#if defined(_WIN32)
size_t start = path.find_last_of("/\\");
#else
size_t start = path.find_last_of("/");
size_t start = path.find_last_of('/');
#endif
if (start == std::string::npos) {
@ -1094,7 +1096,7 @@ std::string utils::path_dirname(const std::string &path)
#if defined(_WIN32)
size_t start = path.find_last_of("/\\");
#else
size_t start = path.find_last_of("/");
size_t start = path.find_last_of('/');
#endif
if (start == std::string::npos) return ".";
@ -1359,7 +1361,21 @@ int utils::date2num(const std::string &date)
return num;
}
/* binary search in vector of ascending doubles */
/* ----------------------------------------------------------------------
get formatted string of current date from fmtlib
------------------------------------------------------------------------- */
std::string utils::current_date()
{
time_t tv = time(nullptr);
std::tm today = fmt::localtime(tv);
return fmt::format("{:%Y-%m-%d}", today);
}
/* ----------------------------------------------------------------------
binary search in vector of ascending doubles
------------------------------------------------------------------------- */
int utils::binary_search(const double needle, const int n, const double *haystack)
{
int lo = 0;