MCPcopy Create free account
hub / github.com/Cantera/cantera / isFloat

Function isFloat

src/base/AnyMap.cpp:25–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23using namespace Cantera;
24
25bool isFloat(const string& val)
26{
27 // This function duplicates the logic of fpValueCheck, but doesn't throw
28 // exceptions if the string isn't a float
29 string str = ba::trim_copy(val);
30 if (str.empty()) {
31 return false;
32 }
33 int numDot = 0;
34 int numExp = 0;
35 int istart = 0;
36 int numDigit = 0;
37 char ch = str[0];
38 if (ch == '+' || ch == '-') {
39 istart = 1;
40 if (str.size() == 1) {
41 return false;
42 }
43 }
44 for (size_t i = istart; i < str.size(); i++) {
45 ch = str[i];
46 if (isdigit(ch)) {
47 numDigit++;
48 } else if (ch == '.') {
49 numDot++;
50 if (numDot > 1) {
51 return false;
52 }
53 if (numExp > 0) {
54 return false;
55 }
56 } else if (ch == 'e' || ch == 'E') {
57 numExp++;
58 if (numExp > 1 || numDigit == 0 || i == str.size() - 1) {
59 return false;
60 }
61 ch = str[i+1];
62 if (ch == '+' || ch == '-') {
63 if (i + 1 == str.size() - 1) {
64 return false;
65 }
66 i++;
67 }
68 } else {
69 return false;
70 }
71 }
72 return true;
73}
74
75bool isInt(const string& val)
76{

Callers 5

elementTypesFunction · 0.85
AnyMap.cppFile · 0.85
emitStringFunction · 0.85
emitFlowVectorFunction · 0.85
decodeMethod · 0.85

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected