FEDEM Solver  R8.0
Source code of the dynamics solver
FFaStringExt.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
13 #ifndef FFA_STRING_EXT_H
14 #define FFA_STRING_EXT_H
15 
16 #include <string>
17 #include <cstdio>
18 #include <cctype>
19 
20 
25 class FFaNumStr : public std::string
26 {
27 public:
29  FFaNumStr(const char* format, int val)
30  {
31  char buf[128];
32  snprintf(buf,128,format,val);
33  append(buf);
34  }
35 
37  FFaNumStr(const char* format, size_t val)
38  {
39  char buf[128];
40  snprintf(buf,128,format,val);
41  append(buf);
42  }
43 
45  FFaNumStr(const char* format, float val)
46  {
47  char buf[128];
48  snprintf(buf,128,format,val);
49  append(buf);
50  }
51 
53  FFaNumStr(const char* format, double val)
54  {
55  char buf[128];
56  snprintf(buf,128,format,val);
57  append(buf);
58  }
59 
61  FFaNumStr(int val) { this->append(std::to_string(val)); }
63  FFaNumStr(unsigned int val) { this->append(std::to_string(val)); }
65  FFaNumStr(long int val) { this->append(std::to_string(val)); }
66 
67  // These two constructors are documented in the C-file.
68  FFaNumStr(double val, char f = 'g', int precision = 6);
69  FFaNumStr(double val, int integerDigits, int precision = 12,
70  double ceiling = 1.0e+7, double floor = 1.0e-5,
71  bool useDigitGrouping = false);
72 };
73 
74 
79 class FFaLowerCaseString : public std::string
80 {
81 public:
83  FFaLowerCaseString(const std::string& s)
84  {
85  this->reserve(s.length());
86  for (size_t i = 0; i < s.length(); i++)
87  this->operator+=(tolower(s[i]));
88  }
89 };
90 
91 
96 class FFaUpperCaseString : public std::string
97 {
98 public:
100  FFaUpperCaseString(const std::string& s)
101  {
102  this->reserve(s.length());
103  for (size_t i = 0; i < s.length(); i++)
104  this->operator+=(toupper(s[i]));
105  }
106 };
107 
108 
114 class FFaString : public std::string
115 {
116 public:
118  FFaString(const std::string& s) : std::string(s) {}
120  bool hasSubString(const char*) const;
122  int getIntAfter(const char*) const;
124  double getDoubleAfter(const char*) const;
126  int getIntsAfter(const char*, const int, int*) const;
128  int getDoublesAfter(const char*, const int, double*) const;
130  std::string getTextAfter(const char*, const char* end = NULL) const;
131 
132 private:
134  size_t getPosAfterString(const char*) const;
135 };
136 
137 #endif
Extension of the STL string class for lower-case strings only.
Definition: FFaStringExt.H:80
FFaLowerCaseString(const std::string &s)
The copy constructor converts the string to lower case.
Definition: FFaStringExt.H:83
Extension of the STL string class converting numbers to a text string.
Definition: FFaStringExt.H:26
FFaNumStr(int val)
Constructor converting an integer value.
Definition: FFaStringExt.H:61
FFaNumStr(unsigned int val)
Constructor converting an unsigned integer value.
Definition: FFaStringExt.H:63
FFaNumStr(const char *format, size_t val)
Constructor converting an integer value with a format string.
Definition: FFaStringExt.H:37
FFaNumStr(long int val)
Constructor converting a long integer value.
Definition: FFaStringExt.H:65
FFaNumStr(const char *format, float val)
Constructor converting a float value with a format string.
Definition: FFaStringExt.H:45
FFaNumStr(const char *format, int val)
Constructor converting an integer value with a format string.
Definition: FFaStringExt.H:29
FFaNumStr(const char *format, double val)
Constructor converting a double value with a format string.
Definition: FFaStringExt.H:53
Extension of the STL string class with some parsing methods.
Definition: FFaStringExt.H:115
int getIntAfter(const char *) const
Parses an integer after the specified substring.
Definition: FFaStringExt.C:130
int getIntsAfter(const char *, const int, int *) const
Parses a list of integers after the specified substring.
Definition: FFaStringExt.C:148
size_t getPosAfterString(const char *) const
Returns the position of the specified substring.
Definition: FFaStringExt.C:107
std::string getTextAfter(const char *, const char *end=NULL) const
Parses a text string after the specified substring.
Definition: FFaStringExt.C:196
int getDoublesAfter(const char *, const int, double *) const
Parses a list of doubles after the specified substring.
Definition: FFaStringExt.C:172
double getDoubleAfter(const char *) const
Parses a double after the specified substring.
Definition: FFaStringExt.C:139
FFaString(const std::string &s)
Copy constructor.
Definition: FFaStringExt.H:118
bool hasSubString(const char *) const
Checks if the string contains the specified substring.
Definition: FFaStringExt.C:124
Extension of the STL string class for upper-case strings only.
Definition: FFaStringExt.H:97
FFaUpperCaseString(const std::string &s)
The copy constructor converts the string to upper case.
Definition: FFaStringExt.H:100