Allocate memory for a copy of given string
| 42 | |
| 43 | // Allocate memory for a copy of given string |
| 44 | char* copy_string(const char* s) { |
| 45 | |
| 46 | if (s == nullptr) { |
| 47 | return nullptr; |
| 48 | } |
| 49 | |
| 50 | const auto n = strlen(s); |
| 51 | auto s2 = static_cast<char*>(malloc(n + 1)); |
| 52 | strcpy(s2, s); |
| 53 | return s2; |
| 54 | } |
| 55 | |
| 56 | // Convert a string to lower case |
| 57 | const std::string lowercase(const std::string& str) { |