| 23 | using namespace Cantera; |
| 24 | |
| 25 | bool 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 | |
| 75 | bool isInt(const string& val) |
| 76 | { |
no test coverage detected