| 13 | namespace function { |
| 14 | |
| 15 | bool tryCastToBool(const char* input, uint64_t len, bool& result) { |
| 16 | StringUtils::removeCStringWhiteSpaces(input, len); |
| 17 | |
| 18 | switch (len) { |
| 19 | case 1: { |
| 20 | char c = std::tolower(*input); |
| 21 | if (c == 't' || c == '1') { |
| 22 | result = true; |
| 23 | return true; |
| 24 | } else if (c == 'f' || c == '0') { |
| 25 | result = false; |
| 26 | return true; |
| 27 | } |
| 28 | return false; |
| 29 | } |
| 30 | case 4: { |
| 31 | auto t = std::tolower(input[0]); |
| 32 | auto r = std::tolower(input[1]); |
| 33 | auto u = std::tolower(input[2]); |
| 34 | auto e = std::tolower(input[3]); |
| 35 | if (t == 't' && r == 'r' && u == 'u' && e == 'e') { |
| 36 | result = true; |
| 37 | return true; |
| 38 | } |
| 39 | return false; |
| 40 | } |
| 41 | case 5: { |
| 42 | auto f = std::tolower(input[0]); |
| 43 | auto a = std::tolower(input[1]); |
| 44 | auto l = std::tolower(input[2]); |
| 45 | auto s = std::tolower(input[3]); |
| 46 | auto e = std::tolower(input[4]); |
| 47 | if (f == 'f' && a == 'a' && l == 'l' && s == 's' && e == 'e') { |
| 48 | result = false; |
| 49 | return true; |
| 50 | } |
| 51 | return false; |
| 52 | } |
| 53 | default: |
| 54 | return false; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void castStringToBool(const char* input, uint64_t len, bool& result) { |
| 59 | if (!tryCastToBool(input, len, result)) { |
no outgoing calls
no test coverage detected