| 34 | } |
| 35 | |
| 36 | void SplitCommandLineEx( |
| 37 | std::wstring const& CommandLine, |
| 38 | std::vector<std::wstring> const& OptionPrefixes, |
| 39 | std::vector<std::wstring> const& OptionParameterSeparators, |
| 40 | std::wstring& ApplicationName, |
| 41 | std::map<std::wstring, std::wstring>& OptionsAndParameters, |
| 42 | std::wstring& UnresolvedCommandLine) |
| 43 | { |
| 44 | ApplicationName.clear(); |
| 45 | OptionsAndParameters.clear(); |
| 46 | UnresolvedCommandLine.clear(); |
| 47 | |
| 48 | size_t arg_size = 0; |
| 49 | for (auto& SplitArgument : Mile::SplitCommandLineWideString(CommandLine)) |
| 50 | { |
| 51 | // We need to process the application name at the beginning. |
| 52 | if (ApplicationName.empty()) |
| 53 | { |
| 54 | // For getting the unresolved command line, we need to cumulate |
| 55 | // length which including spaces. |
| 56 | arg_size += SplitArgument.size() + 1; |
| 57 | |
| 58 | // Save |
| 59 | ApplicationName = SplitArgument; |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | bool IsOption = false; |
| 64 | size_t OptionPrefixLength = 0; |
| 65 | |
| 66 | for (auto& OptionPrefix : OptionPrefixes) |
| 67 | { |
| 68 | if (0 == ::_wcsnicmp( |
| 69 | SplitArgument.c_str(), |
| 70 | OptionPrefix.c_str(), |
| 71 | OptionPrefix.size())) |
| 72 | { |
| 73 | IsOption = true; |
| 74 | OptionPrefixLength = OptionPrefix.size(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | if (IsOption) |
| 79 | { |
| 80 | // For getting the unresolved command line, we need to cumulate |
| 81 | // length which including spaces. |
| 82 | arg_size += SplitArgument.size() + 1; |
| 83 | |
| 84 | // Get the option name and parameter. |
| 85 | |
| 86 | wchar_t* OptionStart = &SplitArgument[0] + OptionPrefixLength; |
| 87 | wchar_t* ParameterStart = nullptr; |
| 88 | |
| 89 | for (auto& OptionParameterSeparator |
| 90 | : OptionParameterSeparators) |
| 91 | { |
| 92 | wchar_t* Result = std::wcsstr( |
| 93 | OptionStart, |