X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e559d790fb102c4f97c19152dbcc76aae312d945..8cbc59fe84f046685b873cf58f6c56debe59de1c:/src/common/cmdline.cpp diff --git a/src/common/cmdline.cpp b/src/common/cmdline.cpp index 787e4df468..ce169ac95b 100644 --- a/src/common/cmdline.cpp +++ b/src/common/cmdline.cpp @@ -779,15 +779,15 @@ int wxCmdLineParser::Parse(bool showUsage) } else // it's an option. not a switch { - switch ( (*p).GetValue() ) + switch ( p == end ? '\0' : (*p).GetValue() ) { - case _T('='): - case _T(':'): + case '=': + case ':': // the value follows ++p; break; - case 0: + case '\0': // the value is in the next argument if ( ++n == count ) { @@ -1280,15 +1280,15 @@ static wxString GetLongOptionName(wxString::const_iterator p, */ /* static */ -wxArrayString wxCmdLineParser::ConvertStringToArgs(const wxString& cmdline) +wxArrayString +wxCmdLineParser::ConvertStringToArgs(const wxString& cmdline, + wxCmdLineSplitType type) { wxArrayString args; wxString arg; arg.reserve(1024); - bool isInsideQuotes = false; - const wxString::const_iterator end = cmdline.end(); wxString::const_iterator p = cmdline.begin(); @@ -1303,31 +1303,76 @@ wxArrayString wxCmdLineParser::ConvertStringToArgs(const wxString& cmdline) break; // parse this parameter - bool lastBS = false; + bool lastBS = false, + isInsideQuotes = false; + wxChar chDelim = '\0'; for ( arg.clear(); p != end; ++p ) { const wxChar ch = *p; - if ( ch == '"' ) + + if ( type == wxCMD_LINE_SPLIT_DOS ) { - if ( !lastBS ) + if ( ch == '"' ) { - isInsideQuotes = !isInsideQuotes; + if ( !lastBS ) + { + isInsideQuotes = !isInsideQuotes; - // don't put quote in arg - continue; + // don't put quote in arg + continue; + } + //else: quote has no special meaning but the backslash + // still remains -- makes no sense but this is what + // Windows does + } + // note that backslash does *not* quote the space, only quotes do + else if ( !isInsideQuotes && (ch == ' ' || ch == '\t') ) + { + ++p; // skip this space anyhow + break; } - //else: quote has no special meaning but the backslash - // still remains -- makes no sense but this is what - // Windows does + + lastBS = !lastBS && ch == '\\'; } - // note that backslash does *not* quote the space, only quotes do - else if ( !isInsideQuotes && (ch == ' ' || ch == '\t') ) + else // type == wxCMD_LINE_SPLIT_UNIX { - ++p; // skip this space anyhow - break; - } + if ( !lastBS ) + { + if ( isInsideQuotes ) + { + if ( ch == chDelim ) + { + isInsideQuotes = false; + + continue; // don't use the quote itself + } + } + else // not in quotes and not escaped + { + if ( ch == '\'' || ch == '"' ) + { + isInsideQuotes = true; + chDelim = ch; - lastBS = ch == '\\'; + continue; // don't use the quote itself + } + + if ( ch == ' ' || ch == '\t' ) + { + ++p; // skip this space anyhow + break; + } + } + + lastBS = ch == '\\'; + if ( lastBS ) + continue; + } + else // escaped by backslash, just use as is + { + lastBS = false; + } + } arg += ch; }