CEPS  24.01
Cardiac ElectroPhysiology Simulator
CepsString.cpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
34 
35 #include <dirent.h>
36 
38 ceps::split(const CepsString& s, const CepsString& delimiters)
39 {
40  return splitUntilNthDelimiter(s, static_cast<CepsUInt>(-1), delimiters);
41 }
42 
45 {
47  for (auto [k,v] : map)
48  res.insert(std::make_pair(k, split(v, delimiters)));
49  return res;
50 }
51 
53 ceps::split(const CepsVector<CepsString>& vec, const CepsString& delimiters)
54 {
56  res.reserve(vec.size());
57  for (auto s : vec)
58  res.push_back(split(s, delimiters));
59  return res;
60 }
61 
63 ceps::join(const CepsVector<CepsString>& vec, const CepsChar& delimeter)
64 {
66  CepsString out = "";
67  const CepsUInt& n = clean.size();
68  for (CepsUInt i = 0; i < n; ++i)
69  {
70  out += clean[i];
71  if (i < n-1)
72  out += delimeter;
73  }
74  return out;
75 }
76 
79 {
80  size_t posBegin = s.find_first_not_of(" \t");
81  size_t posEnd = s.find_last_not_of (" \t")+1;
82  CepsString str = (posEnd>posBegin) ? s.substr(posBegin,posEnd-posBegin) : CepsString("");
83  return str;
84 }
85 
88 {
89  CepsString str = s;
90  str.erase(std::remove_if(str.begin(),str.end(),isspace), str.end());
91  return str;
92 }
93 
95 ceps::substract(const CepsString& s, const CepsString& toErase)
96 {
97  CepsString out = s;
98  size_t pos = out.find(toErase);
99  while (pos != CepsString::npos)
100  {
101  out.erase(pos, toErase.length());
102  pos = out.find(toErase);
103  }
104  return out;
105 }
106 
109 {
110  CepsString out = s;
111  for (CepsString e : toErase)
112  {
113  size_t pos = out.find(e);
114  while (pos != CepsString::npos)
115  {
116  out.erase(pos, e.length());
117  pos = out.find(e);
118  }
119  }
120  return out;
121 }
122 
125 {
126  CepsString str = s;
127 
128  for (char& c : str)
129  c = toupper(c);
130  return str;
131 }
132 
135 {
136  CepsString str = s;
137 
138  for (auto& c : str)
139  c = tolower(c);
140  return str;
141 }
142 
143 CepsBool
145 {
146  CepsVector<CepsString> words = split(s, " ");
147 
148  // If there is only one word,
149  // this loop does not exist
150  for (uint i=0U; i<words.size()-1; i++)
151  if (not words[i].ends_with ("\\"))
152  return false;
153  return true;
154 }
155 
158 {
159  CepsString str = s;
160 
161  str.erase(std::remove(str.begin(),str.end(),'"'),str.end());
162  str = toUpper(str);
163  str = removeSpaces(str);
164  return str;
165 }
166 
169 {
170  CepsVector<CepsString> out = {};
171  out.reserve(vec.size());
172  for (auto& s : vec)
173  out.push_back(ceps::toKey(s));
174  return out;
175 }
176 
177 void
179 {
180  for (auto& s : vec)
181  s = ceps::toKey(s);
182  return;
183 }
184 
185 CepsBool
187 {
188  CepsString val = toKey(s);
189  return (val == "YES" or val == "TRUE" or val == "1" or val == "ON");
190 }
191 
192 CepsReal
194 {
195  try
196  {
197  return (CepsReal) std::stod(trim(s));
198  }
199  catch (...)
200  {
201  CEPS_ABORT("Cannot convert \"" << s << "\" into a real number");
202  return 0x0;
203  }
204 }
205 
208 {
209  auto l = split(s);
210  CepsSet<CepsReal> out = {};
211 
212  for (auto ss: l)
213  out.insert(toReal(ss));
214 
215  return out;
216 }
217 
220 {
221  CEPS_ABORT_IF(vec.size() not_eq 1,"vector must be of size 1");
222  CepsMathScalar value = ceps::toReal (vec[0]);
223  return value;
224 }
225 
228 {
229  CEPS_ABORT_IF(vec.size () not_eq 3,"vector must be of size 3");
230  CepsMathVertex value;
231  for (CepsUInt i = 0U; i < 3; ++i)
232  value(i) = ceps::toReal(vec[i]);
233  return value;
234 }
235 
238 {
239  CepsMathTensor value = CepsMathTensor::Zero();
240  if (vec.size()==1)
241  for (CepsUInt i = 0U; i < 3; ++i)
242  value(i,i) = ceps::toReal(vec[0]);
243  else if (vec.size()==3)
244  for (CepsUInt i = 0U; i < 3; ++i)
245  value(i,i) = ceps::toReal(vec[i]);
246  else if (vec.size()==6) // Symmetric
247  {
248  value(0,0) = ceps::toReal(vec[0]);
249  value(0,1) = ceps::toReal(vec[1]);
250  value(0,2) = ceps::toReal(vec[2]);
251  value(1,0) = ceps::toReal(vec[1]);
252  value(1,1) = ceps::toReal(vec[3]);
253  value(1,2) = ceps::toReal(vec[4]);
254  value(2,0) = ceps::toReal(vec[2]);
255  value(2,1) = ceps::toReal(vec[4]);
256  value(2,2) = ceps::toReal(vec[5]);
257  }
258  else if (vec.size()==9)
259  {
260  for (CepsUInt i = 0U; i < 3; ++i)
261  for (CepsUInt j = 0U; j < 3; ++j)
262  value (i,j) = ceps::toReal(vec[i*3+j]);
263  }
264  else
265  CEPS_ABORT("vector must be of size 1, 3, 6 or 9");
266  return value;
267 }
268 
269 CepsInt
271 {
272  try
273  {
274  return (CepsInt) std::stoi(trim(s));
275  }
276  catch(...)
277  {
278  CEPS_ABORT("cannot convert \"" << s << "\" into an integer");
279  return 0x0;
280  }
281 }
282 
285 {
286  auto l = split(s);
287  CepsSet<CepsInt> out = {};
288 
289  for (auto ss: l)
290  out.insert(toInt(ss));
291 
292  return out;
293 }
294 
295 CepsUInt
297 {
298  try
299  {
300  return (CepsUInt) std::stoi(trim(s));
301  }
302  catch(...)
303  {
304  CEPS_ABORT ("Cannot convert \"" << s << "\" into an unsigned integer");
305  return 0x0;
306  }
307 }
308 
311 {
312  auto l = split(s);
313  CepsSet<CepsUInt> out = {};
314 
315  for (auto ss : l)
316  out.insert(toUInt(ss));
317 
318  return out;
319 }
320 
321 CepsBool
323 {
324  try
325  {
326  std::stod(trim(s));
327  return true;
328  }
329  catch (...)
330  {
331  }
332  return false;
333 
334  // const CepsString& other = trim(s);
335  // std::string::const_iterator it = other.begin ();
336  // while (it != other.end () and (std::isdigit (*it) or std::isspace(*it)))
337  // ++it;
338  // return not other.empty () and it == other.end ();
339 }
340 
341 CepsBool
342 ceps::startsWith(const CepsString& s, const CepsString& comp)
343 {
344  std::size_t n_str = s .length();
345  std::size_t n_comp = comp.length();
346  if (n_str >= n_comp)
347  return (0 == s.compare(0,n_comp,comp));
348 
349  return false;
350 }
351 
352 CepsBool
354 {
355  for (const CepsString& comp : comps)
356  if (startsWith(s,comp))
357  return true;
358 
359  return false;
360 }
361 
362 CepsBool
363 ceps::endsWith(const CepsString& s, const CepsString& comp)
364 {
365  std::size_t n_str = s .length();
366  std::size_t n_comp = comp.length();
367  if (n_str >= n_comp)
368  return (0 == s.compare (n_str - n_comp, n_comp, comp));
369 
370  return false;
371 }
372 
373 CepsBool
375 {
376  for (const CepsString &comp : comps)
377  if (endsWith (s, comp))
378  return true;
379 
380  return false;
381 }
382 
385 {
387 
388  // Prepare tags and split input string
389  std::set<CepsString> TAGS = {};
390  for (CepsString tag: tags)
391  TAGS.insert (toKey(tag));
392 
393  CepsVector<CepsString> vec = split(s);
394 
395  CepsString currentKey = "", word;
396  CepsVector<CepsString> currentWords;
397 
398  for (uint wpos = 0U; wpos < vec.size(); wpos++)
399  {
400  word = toKey(vec[wpos]);
401  if (TAGS.contains(word))
402  {
403  if (not currentKey.empty())
404  res[currentKey] = currentWords;
405  currentKey = word;
406  currentWords.clear();
407  }
408  else
409  currentWords.push_back(vec[wpos]);
410  }
411  // Put last read key into map
412  if (not currentKey.empty())
413  res[currentKey] = currentWords;
414 
415  return res;
416 }
417 
420  const CepsString &s,
421  CepsUInt n,
422  CepsString delimiters
423 )
424 {
425  CepsVector<CepsString> res(2);
426  CepsVector<CepsString> words = split(s,delimiters);
428  CepsUInt i,nw=words.size();
429 
430  for (i=0;i<std::min(n,nw);i++)
431  swords[0].push_back(words[i]);
432  for (;i<nw;i++)
433  swords[1].push_back(words[i]);
434  CepsChar delim(delimiters[0]);
435  res[0] = join(swords[0],delim);
436  res[1] = join(swords[1],delim);
437  return res;
438 }
439 
442  const CepsString &s,
443  const CepsUInt &n,
444  CepsString delimiters
445 )
446 {
447  CepsVector<CepsString> elements = {};
448  CepsUInt counter = 0;
449 
450  if (s.length() != 0)
451  {
452  CepsString s2 = trim(s);
453  size_t posBegin;
454  // Build a string of non space delimiters
455  // (that can be occuring several times, e.g:
456  // " data1 ,,, data4, ... "
457  CepsString delims2(delimiters);
458  delims2.erase(std::remove(delims2.begin(),delims2.end(),' ' ),delims2.end());
459  delims2.erase(std::remove(delims2.begin(),delims2.end(),'\t'),delims2.end());
460 
461  // CepsString starting with delimiters...
462  if (delimiters.find(s2.front()) != delimiters.npos)
463  elements.push_back("");
464 
465  posBegin = s2.find_first_not_of(delimiters.c_str());
466 
467  while ((posBegin!=s2.npos) and (counter!=n))
468  {
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);
473 
474  // In case there was several successive non space delimiters
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("");
479 
480  counter++;
481  }
482 
483  // CepsString ending with a delimiter...
484  if (delimiters.find(s2.back()) != delimiters.npos)
485  elements.push_back("");
486 
487  // we stoped because of counter
488  if (posBegin != s2.npos)
489  elements.push_back(trim(s2.substr(posBegin,s2.size())));
490  }
491 
492  return cleanup(elements);
493 }
494 
497  const CepsVector<CepsString>& scope,
498  const CepsString& tag,
499  const CepsString& def,
500  const CepsUInt& pad
501 )
502 {
503  auto it = std::find(scope.begin(),scope.end(),tag);
504  if (it + pad < scope.end())
505  return *(it+pad);
506  return def;
507 }
508 
511 {
512  CepsVector<CepsString> words = split(path,"/");
514  for (CepsString word:words)
515  if (not word.empty())
516  clean.push_back(word);
517  return join(clean,'/');
518 }
519 
522 {
523  // Get execution directory
524  CepsString pwd;
525  CepsChar* buf = nullptr;
526  CepsChar* path = realpath(".", buf);
527  free(buf);
528  pwd = CepsString(path) + "/";
529  free(path);
530 
531  // if there is a / in the filename
532  if (s.find('/')!=s.npos)
533  {
534  // Remove end from string
535  CepsString res = s.substr(0,s.find_last_of('/')+1);
536  // Transform relative to absolute paths
537  // ./foo
538  if (startsWith(s,"./"))
539  res.replace(0,2,pwd);
540  // ../bar
541  else if (startsWith(s,"../"))
542  {
543  pwd.pop_back();
544  CEPS_ABORT_IF(pwd.size()==0,
545  "ceps::getDir: trying to access parent directory from / "
546  );
547  pwd = pwd.substr(0,pwd.find_last_of('/')+1);
548  res.replace (0,3,pwd);
549  }
550  return res;
551  }
552  return pwd;
553 }
554 
557 {
558  CepsUInt last = s.find_last_of("/\\");
559  return (s.substr(last + 1));
560 }
561 
564 {
565  size_t firstChar, lastDot, lastSlash;
566  lastSlash = fileName.find_last_of('/');
567  if (lastSlash != fileName.npos)
568  firstChar = lastSlash + 1;
569  else
570  firstChar = 0;
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);
576  return CepsString("");
577 }
578 
581 {
582  CepsInt lastDot = s.find_last_of('.');
583  CepsInt lastSlash = s.find_last_of('/');
584  return (lastDot > lastSlash) ? (s.substr(lastDot+1)) : "";
585 }
586 
589 {
590  return getDir(s) + getBaseName(s) + "." + ext;
591 }
592 
593 // WARNING: This may not be cross-platform !!
594 CepsBool
595 ceps::fileExists(const CepsString& fileName, const CepsString& directory)
596 {
597 
598  // Remove the directory from the file name if it was given
599  CepsString cutFile = ceps::getBaseName(fileName);
600  if (not ceps::getExtension(fileName).empty())
601  cutFile += "." + ceps::getExtension(fileName);
602 
603  // Open specified directory
604  DIR *dir = opendir (directory.c_str());
605  if (ceps::isNullPtr(dir))
606  {
607  // std::cerr<<"CepsIo: unable to open directory \'"<<directory.c_str()<<"\'"<<endl;
608  return false;
609  // exit(EXIT_FAILURE);
610  }
611  // The file structure
612  struct dirent *dp;
613 
614  // While there are files to read
615  while ((dp = readdir(dir)) != nullptr)
616  {
617  CepsString file(dp->d_name);
618  if (cutFile.compare(file) == 0)
619  {
620  // We found the file
621  closedir(dir);
622  return true;
623  }
624  }
625  // Not found
626  closedir(dir);
627  return false;
628 }
629 
630 CepsBool
631 ceps::fileExists(const CepsString& fileName)
632 {
633  return ceps::fileExists(fileName,ceps::getDir(fileName));
634 }
635 
636 CepsBool
638 {
639 
640  CepsString ff1 = ceps::getDir(f1)+"/"+ceps::getFilename(f1);
641  CepsString ff2 = ceps::getDir(f2)+"/"+ceps::getFilename(f2);
642 
644 }
645 
648 {
649  CepsVector<CepsString> out = vec;
650 
651  auto f = [] (std::string const &s) {
652  return s.empty() or s==" ";
653  };
654 
655  out.erase(std::remove_if(out.begin(),out.end(),f),out.end());
656 
657  return out;
658 }
659 
660 CepsReal
661 ceps::readReal(std::istream& file, const CepsString& message)
662 {
663  CepsReal res = 0.;
664  try {
665  CepsString buf;
666  file >> buf;
667  res = std::stod(buf);
668  }
669  catch (...)
670  {
671  CEPS_ABORT(message);
672  }
673  return res;
674 }
675 
676 CepsInt
677 ceps::readInt(std::istream& file, const CepsString& message)
678 {
679  CepsInt res = 0.;
680  try {
681  CepsString buf;
682  file >> buf;
683  res = std::stoi(buf);
684  }
685  catch (...)
686  {
687  CEPS_ABORT(message);
688  }
689  return res;
690 }
691 
693 ceps::readVertex(std::istream& file, const CepsString& message)
694 {
695  CepsReal3D res;
696  for (CepsUInt i=0;i<3;i++)
697  {
698  res[i] = readReal(file,message+"("+toString(i)+")");
699  }
700  return res;
701 }
702 
704 ceps::readTensor(std::istream& file, const CepsString& message)
705 {
706  CepsMathTensor res;
707  for (CepsUInt i=0;i<3;i++)
708  for (CepsUInt j=0;j<3;j++)
709  {
710  res(i,j) = readReal(file,message+"("+toString(i)+","+toString(j)+")");
711  }
712  return res;
713 }
#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.
Definition: CepsTypes.hpp:128
CepsScalar CepsMathScalar
Real numbers.
Definition: CepsTypes.hpp:133
std::map< _Key, _Tp, _Compare, _Alloc > CepsMap
C++ map.
Definition: CepsTypes.hpp:196
char CepsChar
Char.
Definition: CepsTypes.hpp:125
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
Eigen::Matrix< CepsScalar, 3, 3 > CepsMathTensor
Tensor, eigen format.
Definition: CepsTypes.hpp:137
CepsArray< _Type, 2U > CepsArray2
C++ array, 2 elements.
Definition: CepsTypes.hpp:162
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
Eigen::Matrix< CepsScalar, 3, 1 > CepsMathVertex
Vertex, eigen format.
Definition: CepsTypes.hpp:135
CepsArray3< CepsReal > CepsReal3D
Three real scalars, used like this for compatibility in polynomials.
Definition: CepsTypes.hpp:178
int32_t CepsInt
Need 32 bit integer.
Definition: CepsTypes.hpp:106
CepsString toString(CepsCellType cat, CepsUInt order)
Converts inputs into a string ("P1", "P2", "Q1", "Q2", etc)
Definition: FEType.hpp:39
CepsString getDir(const CepsString &str)
Get a substring of s, from beginning of s to the last '/' character. Example: "/home/someone/file....
Definition: CepsString.cpp:521
CepsVector< CepsString > cleanup(const CepsVector< CepsString > &vec)
Clean a vector of string, remove empty and " " string.
Definition: CepsString.cpp:647
CepsMathTensor toMathTensor(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathTensor.
Definition: CepsString.cpp:237
CepsString getFilename(const CepsString &str)
Returns a substring corresponding to the string after the last '/' character. Example: "/home/someone...
Definition: CepsString.cpp:556
CepsString toKey(const CepsString &s)
Transform to key type a std::string, upper case and no spaces.
Definition: CepsString.cpp:157
CepsBool endsWith(const CepsString &s, const CepsString &comp)
Check if the string 'str' ends with 'comp'.
Definition: CepsString.cpp:363
CepsString join(const CepsVector< CepsString > &vec, const CepsChar &delimeter=' ')
Join multiple strings into one.
Definition: CepsString.cpp:63
CepsSet< CepsInt > toInts(const CepsString &s)
Cast CepsString to a set of CepsInt.
Definition: CepsString.cpp:284
CepsBool toBool(const CepsString &s)
Cast CepsString to CepsBool.
Definition: CepsString.cpp:186
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...
Definition: CepsString.cpp:384
CepsVector< _Type, _Alloc >::iterator find(CepsVector< _Type, _Alloc > &vec, const _Type &value)
Returns the result of find in the whole vector.
Definition: CepsVector.hpp:173
CepsMathScalar toMathScalar(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathScalar same effect as ceps::toReal(vec[0])
Definition: CepsString.cpp:219
const _Type & min(const CepsVector< _Type, _Alloc > &vec)
Returns the minimum of the vector, const version.
Definition: CepsVector.hpp:448
CepsSet< CepsUInt > toUInts(const CepsString &s)
Cast CepsString to a set of CepsUInt.
Definition: CepsString.cpp:310
CepsString substract(const CepsString &s, const CepsString &toErase)
Substract all occurences of another CepsString.
Definition: CepsString.cpp:95
void toKeyInPlace(CepsVector< CepsString > &vec)
Transform to key type a vector of std::string, upper case and no spaces.
Definition: CepsString.cpp:178
CepsBool startsWith(const CepsString &s, const CepsString &comp)
Check if the string 'str' starts with 'comp'.
Definition: CepsString.cpp:342
CepsSet< CepsReal > toReals(const CepsString &s)
Cast CepsString to a set of CepsReal.
Definition: CepsString.cpp:207
CepsString toLower(const CepsString &s)
Switches all characters to lower case.
Definition: CepsString.cpp:134
CepsString readParams(const CepsVector< CepsString > &scope, const CepsString &tag, const CepsString &def="", const CepsUInt &pad=1)
Read parameters into a map.
Definition: CepsString.cpp:496
CepsBool startsWithOneOf(const CepsString &s, const CepsVector< CepsString > &comps)
Check if the string 'str' starts with one of 'comps'.
Definition: CepsString.cpp:353
CepsString removeSpaces(const CepsString &s)
Removes spaces and tabs.
Definition: CepsString.cpp:87
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.
Definition: CepsString.cpp:693
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.
Definition: CepsString.cpp:677
CepsBool endsWithOneOf(const CepsString &s, const CepsVector< CepsString > &comps)
Check if the string 'str' ends with one of 'comps'.
Definition: CepsString.cpp:374
CepsBool isNullPtr(_Type *ptr)
Tells if passed pointer is null.
Definition: CepsMemory.hpp:45
CepsString getExtension(const CepsString &str)
Returns the extension of a file, if any.
Definition: CepsString.cpp:580
CepsString removeDoubleSlashes(const CepsString &path)
Replaces double slashes in a string with a single slash. Used for clean paths.
Definition: CepsString.cpp:510
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 ...
Definition: CepsString.cpp:419
CepsVector< CepsString > split(const CepsString &s, const CepsString &delimiters=CepsString(" \t"))
Splits a string using mulitple delimiters in a single string.
Definition: CepsString.cpp:38
CepsUInt toUInt(const CepsString &s)
Cast CepsString to CepsUInt.
Definition: CepsString.cpp:296
CepsBool isSameFile(const CepsString &f1, const CepsString &f2)
Tells if given paths refer to the same file.
Definition: CepsString.cpp:637
CepsInt toInt(const CepsString &s)
Cast CepsString to CepsInt.
Definition: CepsString.cpp:270
CepsString toUpper(const CepsString &s)
Switches all characters to upper case.
Definition: CepsString.cpp:124
CepsBool isNumber(const CepsString &s)
Check if the string contains only digit numbers.
Definition: CepsString.cpp:322
CepsMathVertex toMathVertex(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathVertex.
Definition: CepsString.cpp:227
CepsVector< CepsString > splitUntilNthDelimiter(const CepsString &s, const CepsUInt &n, CepsString delimiters=CepsString(" \t"))
Split a string for the first n delimeters.
Definition: CepsString.cpp:441
CepsString changeExtension(const CepsString &str, const CepsString &ext)
Change the extension of a file name (does not check if file exists).
Definition: CepsString.cpp:588
CepsString getBaseName(const CepsString &str)
Extracts the base of a file name, without path, nor extension. Ex: getBaseName("/path/to/myfile....
Definition: CepsString.cpp:563
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...
Definition: CepsString.cpp:704
CepsBool isPathInOneWord(const CepsString &s)
Checks if given path is in one word (it may not exist yet)
Definition: CepsString.cpp:144
CepsString trim(const CepsString &s)
Removes trailing and preceeding spaces.
Definition: CepsString.cpp:78
CepsBool fileExists(const CepsString &fileName, const CepsString &directory)
Definition: CepsString.cpp:595
CepsReal toReal(const CepsString &s)
Cast CepsString to CepsReal.
Definition: CepsString.cpp:193
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...
Definition: CepsString.cpp:661