Split a string into a program name and command line arguments the string is assumed to contain a file name followed by other arguments the return value contains is a pair with the first argument containing the program name and the second everything else.
| 3131 | /// the return value contains is a pair with the first argument containing the program name and the second |
| 3132 | /// everything else. |
| 3133 | inline std::pair<std::string, std::string> split_program_name(std::string commandline) { |
| 3134 | // try to determine the programName |
| 3135 | std::pair<std::string, std::string> vals; |
| 3136 | trim(commandline); |
| 3137 | auto esp = commandline.find_first_of(' ', 1); |
| 3138 | while (detail::check_path(commandline.substr(0, esp).c_str()) != path_type::file) { |
| 3139 | esp = commandline.find_first_of(' ', esp + 1); |
| 3140 | if (esp == std::string::npos) { |
| 3141 | // if we have reached the end and haven't found a valid file just assume the first argument is the |
| 3142 | // program name |
| 3143 | esp = commandline.find_first_of(' ', 1); |
| 3144 | break; |
| 3145 | } |
| 3146 | } |
| 3147 | vals.first = commandline.substr(0, esp); |
| 3148 | rtrim(vals.first); |
| 3149 | // strip the program name |
| 3150 | vals.second = (esp != std::string::npos) ? commandline.substr(esp + 1) : std::string{}; |
| 3151 | ltrim(vals.second); |
| 3152 | return vals; |
| 3153 | } |
| 3154 | |
| 3155 | } // namespace detail |
| 3156 | /// @} |
no test coverage detected