MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / tryCastToBool

Function tryCastToBool

src/function/cast_string_non_nested_functions.cpp:15–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13namespace function {
14
15bool 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
58void castStringToBool(const char* input, uint64_t len, bool& result) {
59 if (!tryCastToBool(input, len, result)) {

Callers 2

castStringToBoolFunction · 0.85
tryCastUnionFieldFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected