47 for (
auto [k,v] : map)
48 res.insert(std::make_pair(k,
split(v, delimiters)));
56 res.reserve(vec.size());
58 res.push_back(
split(s, delimiters));
80 size_t posBegin = s.find_first_not_of(
" \t");
81 size_t posEnd = s.find_last_not_of (
" \t")+1;
90 str.erase(std::remove_if(str.begin(),str.end(),isspace), str.end());
98 size_t pos = out.find(toErase);
99 while (pos != CepsString::npos)
101 out.erase(pos, toErase.length());
102 pos = out.find(toErase);
113 size_t pos = out.find(e);
114 while (pos != CepsString::npos)
116 out.erase(pos, e.length());
150 for (uint i=0U; i<words.size()-1; i++)
151 if (not words[i].ends_with (
"\\"))
161 str.erase(std::remove(str.begin(),str.end(),
'"'),str.end());
171 out.reserve(vec.size());
189 return (val ==
"YES" or val ==
"TRUE" or val ==
"1" or val ==
"ON");
201 CEPS_ABORT(
"Cannot convert \"" << s <<
"\" into a real number");
221 CEPS_ABORT_IF(vec.size() not_eq 1,
"vector must be of size 1");
229 CEPS_ABORT_IF(vec.size () not_eq 3,
"vector must be of size 3");
243 else if (vec.size()==3)
246 else if (vec.size()==6)
258 else if (vec.size()==9)
265 CEPS_ABORT(
"vector must be of size 1, 3, 6 or 9");
278 CEPS_ABORT(
"cannot convert \"" << s <<
"\" into an integer");
290 out.insert(
toInt(ss));
304 CEPS_ABORT (
"Cannot convert \"" << s <<
"\" into an unsigned integer");
344 std::size_t n_str = s .length();
345 std::size_t n_comp = comp.length();
347 return (0 == s.compare(0,n_comp,comp));
365 std::size_t n_str = s .length();
366 std::size_t n_comp = comp.length();
368 return (0 == s.compare (n_str - n_comp, n_comp, comp));
389 std::set<CepsString> TAGS = {};
391 TAGS.insert (
toKey(tag));
398 for (uint wpos = 0U; wpos < vec.size(); wpos++)
400 word =
toKey(vec[wpos]);
401 if (TAGS.contains(word))
403 if (not currentKey.empty())
404 res[currentKey] = currentWords;
406 currentWords.clear();
409 currentWords.push_back(vec[wpos]);
412 if (not currentKey.empty())
413 res[currentKey] = currentWords;
431 swords[0].push_back(words[i]);
433 swords[1].push_back(words[i]);
435 res[0] =
join(swords[0],delim);
436 res[1] =
join(swords[1],delim);
458 delims2.erase(std::remove(delims2.begin(),delims2.end(),
' ' ),delims2.end());
459 delims2.erase(std::remove(delims2.begin(),delims2.end(),
'\t'),delims2.end());
462 if (delimiters.find(s2.front()) != delimiters.npos)
463 elements.push_back(
"");
465 posBegin = s2.find_first_not_of(delimiters.c_str());
467 while ((posBegin!=s2.npos) and (counter!=n))
469 size_t posEnd = s2.find_first_of(delimiters.c_str(), posBegin);
470 if (posEnd > posBegin)
471 elements.push_back(
trim(s2.substr(posBegin, posEnd-posBegin)));
472 posBegin = s2.find_first_not_of(delimiters.c_str(), posEnd);
475 if (posBegin != s2.npos)
476 for (
size_t posT = posEnd + 1; posT < posBegin; posT++)
477 if (delims2.find(s2[posT]) != delims2.npos)
478 elements.push_back(
"");
484 if (delimiters.find(s2.back()) != delimiters.npos)
485 elements.push_back(
"");
488 if (posBegin != s2.npos)
489 elements.push_back(
trim(s2.substr(posBegin,s2.size())));
503 auto it =
std::find(scope.begin(),scope.end(),tag);
504 if (it + pad < scope.end())
515 if (not word.empty())
516 clean.push_back(word);
517 return join(clean,
'/');
526 CepsChar* path = realpath(
".", buf);
532 if (s.find(
'/')!=s.npos)
535 CepsString res = s.substr(0,s.find_last_of(
'/')+1);
539 res.replace(0,2,pwd);
545 "ceps::getDir: trying to access parent directory from / "
547 pwd = pwd.substr(0,pwd.find_last_of(
'/')+1);
548 res.replace (0,3,pwd);
558 CepsUInt last = s.find_last_of(
"/\\");
559 return (s.substr(last + 1));
565 size_t firstChar, lastDot, lastSlash;
566 lastSlash = fileName.find_last_of(
'/');
567 if (lastSlash != fileName.npos)
568 firstChar = lastSlash + 1;
571 lastDot = fileName.find_last_of(
'.');
572 if (lastDot > firstChar)
573 return fileName.substr(firstChar, lastDot - firstChar);
574 if (lastDot < lastSlash)
575 return fileName.substr(firstChar, fileName.npos);
582 CepsInt lastDot = s.find_last_of(
'.');
583 CepsInt lastSlash = s.find_last_of(
'/');
584 return (lastDot > lastSlash) ? (s.substr(lastDot+1)) :
"";
604 DIR *dir = opendir (directory.c_str());
615 while ((dp = readdir(dir)) !=
nullptr)
618 if (cutFile.compare(file) == 0)
651 auto f = [] (std::string
const &s) {
652 return s.empty() or s==
" ";
655 out.erase(std::remove_if(out.begin(),out.end(),f),out.end());
667 res = std::stod(buf);
683 res = std::stoi(buf);
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::basic_string< CepsChar > CepsString
C++ format string.
CepsScalar CepsMathScalar
Real numbers.
std::map< _Key, _Tp, _Compare, _Alloc > CepsMap
C++ map.
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Eigen::Matrix< CepsScalar, 3, 3 > CepsMathTensor
Tensor, eigen format.
CepsArray< _Type, 2U > CepsArray2
C++ array, 2 elements.
std::vector< _Type, _Alloc > CepsVector
C++ vector.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
float CepsReal
Need single precision floating point.
Eigen::Matrix< CepsScalar, 3, 1 > CepsMathVertex
Vertex, eigen format.
CepsArray3< CepsReal > CepsReal3D
Three real scalars, used like this for compatibility in polynomials.
int32_t CepsInt
Need 32 bit integer.
CepsString toString(CepsCellType cat, CepsUInt order)
Converts inputs into a string ("P1", "P2", "Q1", "Q2", etc)
CepsString getDir(const CepsString &str)
Get a substring of s, from beginning of s to the last '/' character. Example: "/home/someone/file....
CepsVector< CepsString > cleanup(const CepsVector< CepsString > &vec)
Clean a vector of string, remove empty and " " string.
CepsMathTensor toMathTensor(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathTensor.
CepsString getFilename(const CepsString &str)
Returns a substring corresponding to the string after the last '/' character. Example: "/home/someone...
CepsString toKey(const CepsString &s)
Transform to key type a std::string, upper case and no spaces.
CepsBool endsWith(const CepsString &s, const CepsString &comp)
Check if the string 'str' ends with 'comp'.
CepsString join(const CepsVector< CepsString > &vec, const CepsChar &delimeter=' ')
Join multiple strings into one.
CepsSet< CepsInt > toInts(const CepsString &s)
Cast CepsString to a set of CepsInt.
CepsBool toBool(const CepsString &s)
Cast CepsString to CepsBool.
CepsMap< CepsString, CepsVector< CepsString > > splitByKeyword(const CepsString &s, const CepsSet< CepsString > &tags)
Extract parameters in the CepsString given by tags. Builds a map of keywords and parameter words acco...
CepsVector< _Type, _Alloc >::iterator find(CepsVector< _Type, _Alloc > &vec, const _Type &value)
Returns the result of find in the whole vector.
CepsMathScalar toMathScalar(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathScalar same effect as ceps::toReal(vec[0])
const _Type & min(const CepsVector< _Type, _Alloc > &vec)
Returns the minimum of the vector, const version.
CepsSet< CepsUInt > toUInts(const CepsString &s)
Cast CepsString to a set of CepsUInt.
CepsString substract(const CepsString &s, const CepsString &toErase)
Substract all occurences of another CepsString.
void toKeyInPlace(CepsVector< CepsString > &vec)
Transform to key type a vector of std::string, upper case and no spaces.
CepsBool startsWith(const CepsString &s, const CepsString &comp)
Check if the string 'str' starts with 'comp'.
CepsSet< CepsReal > toReals(const CepsString &s)
Cast CepsString to a set of CepsReal.
CepsString toLower(const CepsString &s)
Switches all characters to lower case.
CepsString readParams(const CepsVector< CepsString > &scope, const CepsString &tag, const CepsString &def="", const CepsUInt &pad=1)
Read parameters into a map.
CepsBool startsWithOneOf(const CepsString &s, const CepsVector< CepsString > &comps)
Check if the string 'str' starts with one of 'comps'.
CepsString removeSpaces(const CepsString &s)
Removes spaces and tabs.
CepsReal3D readVertex(std::istream &file, const CepsString &errorMessage="")
Reads an integral number from an istream, aborts if conversion fails advances the stream by 1 word.
CepsInt readInt(std::istream &file, const CepsString &errorMessage="")
Reads an integral number from an istream, aborts if conversion fails advances the stream by 1 word.
CepsBool endsWithOneOf(const CepsString &s, const CepsVector< CepsString > &comps)
Check if the string 'str' ends with one of 'comps'.
CepsBool isNullPtr(_Type *ptr)
Tells if passed pointer is null.
CepsString getExtension(const CepsString &str)
Returns the extension of a file, if any.
CepsString removeDoubleSlashes(const CepsString &path)
Replaces double slashes in a string with a single slash. Used for clean paths.
CepsVector< CepsString > splitAtNthDelimiter(const CepsString &s, CepsUInt n, CepsString delimiters=CepsString(" \t"))
Split a string a the n-th delimeter. This ignores the doubled delimiter (eg multiple spaces count as ...
CepsVector< CepsString > split(const CepsString &s, const CepsString &delimiters=CepsString(" \t"))
Splits a string using mulitple delimiters in a single string.
CepsUInt toUInt(const CepsString &s)
Cast CepsString to CepsUInt.
CepsBool isSameFile(const CepsString &f1, const CepsString &f2)
Tells if given paths refer to the same file.
CepsInt toInt(const CepsString &s)
Cast CepsString to CepsInt.
CepsString toUpper(const CepsString &s)
Switches all characters to upper case.
CepsBool isNumber(const CepsString &s)
Check if the string contains only digit numbers.
CepsMathVertex toMathVertex(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathVertex.
CepsVector< CepsString > splitUntilNthDelimiter(const CepsString &s, const CepsUInt &n, CepsString delimiters=CepsString(" \t"))
Split a string for the first n delimeters.
CepsString changeExtension(const CepsString &str, const CepsString &ext)
Change the extension of a file name (does not check if file exists).
CepsString getBaseName(const CepsString &str)
Extracts the base of a file name, without path, nor extension. Ex: getBaseName("/path/to/myfile....
CepsMathTensor readTensor(std::istream &file, const CepsString &errorMessage="")
Reads 9 floating point numbers from an istream, aborts if conversion fails advances the stream by 9 w...
CepsBool isPathInOneWord(const CepsString &s)
Checks if given path is in one word (it may not exist yet)
CepsString trim(const CepsString &s)
Removes trailing and preceeding spaces.
CepsBool fileExists(const CepsString &fileName, const CepsString &directory)
CepsReal toReal(const CepsString &s)
Cast CepsString to CepsReal.
CepsReal readReal(std::istream &file, const CepsString &errorMessage="")
Reads a floating point number from an istream, aborts if conversion fails advances the stream by 1 wo...