mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-01-21 03:48:08 -05:00
Lint: use automated tooling to reformat C++ and CMakeLists files (#2103)
* Add initial clang tidy / clang format config files * Clang format the entire codebase ``` find ./src -regextype posix-extended -regex '.*\.(cpp|hpp|c|h|cxx|hxx)$' | xargs clang-format-12 -style=file -i -fallback-style=none find ./include -regextype posix-extended -regex '.*\.(cpp|hpp|c|h|cxx|hxx)$' | xargs clang-format-12 -style=file -i -fallback-style=none find ./Web -regextype posix-extended -regex '.*\.(cpp|hpp|c|h|cxx|hxx)$' | xargs clang-format-12 -style=file -i -fallback-style=none find ./dev -regextype posix-extended -regex '.*\.(cpp|hpp|c|h|cxx|hxx)$' | xargs clang-format-12 -style=file -i -fallback-style=none find ./wrappers -regextype posix-extended -regex '.*\.(cpp|hpp|c|h|cxx|hxx)$' | xargs clang-format-12 -style=file -i -fallback-style=none ``` * Add a .cmake-format file and reformat CmakeLists.txt with it https://github.com/cheshirekow/cmake_format * Add a clang-format workflow only runs on PRs, only on touched files
This commit is contained in:
@@ -4,45 +4,47 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
std::string strjoin(const std::vector<std::string> &strings, const std::string &delim)
|
||||
{
|
||||
std::string strjoin(const std::vector<std::string>& strings, const std::string& delim) {
|
||||
// Empty input vector
|
||||
if (strings.empty()){return "";}
|
||||
if (strings.empty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string output = strings[0];
|
||||
for (unsigned int i = 1; i < strings.size(); i++)
|
||||
{
|
||||
output += format("%s%s",delim.c_str(),strings[i].c_str());
|
||||
for (unsigned int i = 1; i < strings.size(); i++) {
|
||||
output += format("%s%s", delim.c_str(), strings[i].c_str());
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::vector<std::string> strsplit(const std::string &s, char del)
|
||||
{
|
||||
std::vector<std::string> strsplit(const std::string& s, char del) {
|
||||
std::vector<std::string> v;
|
||||
std::string::const_iterator i1 = s.begin(), i2;
|
||||
while (true){
|
||||
while (true) {
|
||||
i2 = std::find(i1, s.end(), del);
|
||||
v.push_back(std::string(i1, i2));
|
||||
if (i2 == s.end())
|
||||
break;
|
||||
i1 = i2+1;
|
||||
if (i2 == s.end()) break;
|
||||
i1 = i2 + 1;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
#if defined(NO_FMTLIB)
|
||||
std::string format(const char* fmt, ...)
|
||||
{
|
||||
std::string format(const char* fmt, ...) {
|
||||
const int size = 512;
|
||||
struct deleter{ static void delarray(char* p) { delete[] p; } }; // to use delete[]
|
||||
shared_ptr<char> buffer(new char[size], deleter::delarray); // I'd prefer unique_ptr, but it's only available since c++11
|
||||
struct deleter
|
||||
{
|
||||
static void delarray(char* p) {
|
||||
delete[] p;
|
||||
}
|
||||
}; // to use delete[]
|
||||
shared_ptr<char> buffer(new char[size], deleter::delarray); // I'd prefer unique_ptr, but it's only available since c++11
|
||||
va_list vl;
|
||||
va_start(vl,fmt);
|
||||
int nsize = vsnprintf(buffer.get(),size,fmt,vl);
|
||||
if(size<=nsize){//fail delete buffer and try again
|
||||
buffer.reset(new char[++nsize], deleter::delarray);//+1 for /0
|
||||
nsize = vsnprintf(buffer.get(),nsize,fmt,vl);
|
||||
va_start(vl, fmt);
|
||||
int nsize = vsnprintf(buffer.get(), size, fmt, vl);
|
||||
if (size <= nsize) { //fail delete buffer and try again
|
||||
buffer.reset(new char[++nsize], deleter::delarray); //+1 for /0
|
||||
nsize = vsnprintf(buffer.get(), nsize, fmt, vl);
|
||||
}
|
||||
va_end(vl);
|
||||
return buffer.get();
|
||||
@@ -51,17 +53,16 @@ std::string format(const char* fmt, ...)
|
||||
|
||||
#if defined(ENABLE_CATCH)
|
||||
|
||||
#include "crossplatform_shared_ptr.h"
|
||||
#include "catch.hpp"
|
||||
#include "CoolPropTools.h"
|
||||
#include "CoolProp.h"
|
||||
# include "crossplatform_shared_ptr.h"
|
||||
# include "catch.hpp"
|
||||
# include "CoolPropTools.h"
|
||||
# include "CoolProp.h"
|
||||
|
||||
TEST_CASE("Test endswith function", "[endswith]")
|
||||
{
|
||||
REQUIRE(endswith("aaa","-PengRobinson") == false);
|
||||
REQUIRE(endswith("Ethylbenzene","-PengRobinson") == false);
|
||||
REQUIRE(endswith("Ethylbenzene-PengRobinson","-PengRobinson") == true);
|
||||
REQUIRE(endswith("Ethylbenzene","Ethylbenzene") == true);
|
||||
TEST_CASE("Test endswith function", "[endswith]") {
|
||||
REQUIRE(endswith("aaa", "-PengRobinson") == false);
|
||||
REQUIRE(endswith("Ethylbenzene", "-PengRobinson") == false);
|
||||
REQUIRE(endswith("Ethylbenzene-PengRobinson", "-PengRobinson") == true);
|
||||
REQUIRE(endswith("Ethylbenzene", "Ethylbenzene") == true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user