Merge branch 'master' into add-fmt-lib

# Conflicts:
#	src/lammps.cpp
#	src/utils.cpp
This commit is contained in:
Axel Kohlmeyer
2020-05-31 09:45:54 -04:00
231 changed files with 9289 additions and 4270 deletions

View File

@ -16,6 +16,7 @@
#include <cstdlib>
#include "lammps.h"
#include "error.h"
#include "tokenizer.h"
#include "fmt/format.h"
#if defined(__linux__)
@ -341,6 +342,60 @@ tagint utils::tnumeric(const char *file, int line, const char *str,
return ATOTAGINT(str);
}
/* ----------------------------------------------------------------------
Return string without trailing # comment
------------------------------------------------------------------------- */
std::string utils::trim_comment(const std::string & line) {
auto end = line.find_first_of("#");
if (end != std::string::npos) {
return line.substr(0, end);
}
return std::string(line);
}
/* ----------------------------------------------------------------------
Trim comment from string and return number of words
------------------------------------------------------------------------- */
size_t utils::count_words(const std::string & text, const std::string & seperators) {
Tokenizer words(utils::trim_comment(text), seperators);
return words.count();
}
/* ----------------------------------------------------------------------
Return whether string is a valid integer number
------------------------------------------------------------------------- */
bool utils::is_integer(const std::string & str) {
if (str.size() == 0) {
return false;
}
for (auto c : str) {
if (isdigit(c) || c == '-' || c == '+') continue;
return false;
}
return true;
}
/* ----------------------------------------------------------------------
Return whether string is a valid floating-point number
------------------------------------------------------------------------- */
bool utils::is_double(const std::string & str) {
if (str.size() == 0) {
return false;
}
for (auto c : str) {
if (isdigit(c)) continue;
if (c == '-' || c == '+' || c == '.') continue;
if (c == 'e' || c == 'E') continue;
return false;
}
return true;
}
/* ------------------------------------------------------------------ */
@ -683,4 +738,5 @@ extern "C" {
return 0;
}
}