VirtualBox

Changeset 56002 in vbox for trunk/src


Ignore:
Timestamp:
May 21, 2015 12:19:28 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
100513
Message:

RTGetOptArgvFromString/MS_CRT: Implemented undocumented doubledouble quotes, current CRT style.

Location:
trunk/src/VBox/Runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/getoptargv.cpp

    r55673 r56002  
    334334                    break;
    335335                if (Cp == '"')
    336                     fInQuote = !fInQuote;
     336                {
     337                    /* Two double quotes insides a quoted string in an escape
     338                       sequence and we output one double quote char.
     339                       See http://www.daviddeley.com/autohotkey/parameters/parameters.htm */
     340                    if (!fInQuote)
     341                        fInQuote = true;
     342                    else if (*pszSrc != '"')
     343                        fInQuote = false;
     344                    else
     345                    {
     346                        pszDst = RTStrPutCp(pszDst, '"');
     347                        pszSrc++;
     348                    }
     349                }
    337350                else if (!fInQuote && rtGetOptIsCpInSet(Cp, pszSeparators, cchSeparators))
    338351                    break;
     
    343356                    /* A backslash sequence is only relevant if followed by
    344357                       a double quote, then it will work like an escape char. */
    345                     size_t cQuotes = 1;
     358                    size_t cSlashes = 1;
    346359                    while (*pszSrc == '\\')
    347360                    {
    348                         cQuotes++;
     361                        cSlashes++;
    349362                        pszSrc++;
    350363                    }
    351364                    if (*pszSrc != '"')
    352365                        /* Not an escape sequence.  */
    353                         while (cQuotes-- > 0)
     366                        while (cSlashes-- > 0)
    354367                            pszDst = RTStrPutCp(pszDst, '\\');
    355368                    else
     
    357370                        /* Escape sequence.  Output half of the slashes.  If odd
    358371                           number, output the escaped double quote . */
    359                         while (cQuotes >= 2)
     372                        while (cSlashes >= 2)
    360373                        {
    361374                            pszDst = RTStrPutCp(pszDst, '\\');
    362                             cQuotes -= 2;
     375                            cSlashes -= 2;
    363376                        }
    364                         if (!cQuotes)
    365                             fInQuote = !fInQuote;
    366                         else
     377                        if (cSlashes)
     378                        {
    367379                            pszDst = RTStrPutCp(pszDst, '"');
    368                         pszSrc++;
     380                            pszSrc++;
     381                        }
    369382                    }
    370383                }
  • trunk/src/VBox/Runtime/testcase/tstRTGetOptArgv.cpp

    r55671 r56002  
    6161    {
    6262        "0 1 \"\"2'' '3' 4 5 '''''6' 7 8 9 10 11",
    63         "0 1 \"\"2 3 4 5 \"6\" 7 8 \"\"\"\"\"\"9\"\"\"\" 10 11",
     63        "0 1 \"\"2 3 4 5 \"6\" 7 8 \"\"9\"\" 10 11",
    6464        NULL,
    6565        12,
     
    8383    },
    8484    {
    85         "\t\" asdf \"  '\"'xyz  \"\t\"  '\n'  '\"'  \"'\"\n\r ",
    86         "\t\" asdf \"  \\\"xyz  \"\t\"  \"\n\"  \"\\\"\"  '\n\r ",
     85        "\t\" asdf \"  '\"'xyz  \"\t\"  '\n'    '\"'    \"'\"\n\r  \\\"xyz",
     86        /* Note! Two things here to make CommandLineArgW happy. First, it doesn't use IFS including newline/return, so
     87                 we skip that bit of the test.  Second, it uses pre-2008 doubledouble quoting rules, unlike the CRT and IPRT
     88                 which uses the post-2008 rules. We work around that by putting that test last.
     89                 See http://www.daviddeley.com/autohotkey/parameters/parameters.htm */
     90        "\t\" asdf \"  \\\"xyz  \"\t\"  \"\n\"  \"\\\"\"  '  \"\"\"xyz\"",
    8791        NULL,
    88         6,
     92        7,
    8993        {
    9094            " asdf ",
     
    9498            "\"",
    9599            "\'",
    96             NULL, NULL,
     100            "\"xyz",
     101            NULL,
    97102            NULL, NULL, NULL, NULL,  NULL, NULL, NULL, NULL,
    98103        },
    99         "' asdf ' '\"xyz' '\t' '\n' '\"' ''\"'\"''",
    100         "\" asdf \" \"\\\"xyz\" \"\t\" \"\n\" \"\\\"\" '"
     104        "' asdf ' '\"xyz' '\t' '\n' '\"' ''\"'\"'' '\"xyz'",
     105        "\" asdf \" \"\\\"xyz\" \"\t\" \"\n\" \"\\\"\" ' \"\\\"xyz\""
    101106    },
    102107    {
     
    286291                                  g_aTests[i].pszInMsCrt, g_aTests[i].pszSeparators);
    287292            RTTESTI_CHECK_RETV(papszArgs1[cArgs1] == NULL);
    288             tstCheckNativeMsCrtToArgv(g_aTests[i].pszInMsCrt, g_aTests[i].cArgs, g_aTests[i].apszArgs);
     293            if (g_aTests[i].pszSeparators == NULL)
     294                tstCheckNativeMsCrtToArgv(g_aTests[i].pszInMsCrt, g_aTests[i].cArgs, g_aTests[i].apszArgs);
    289295
    290296            /* Second */
     
    311317                                          i, iArg, papszArgs3[iArg], g_aTests[i].apszArgs[iArg], pszArgs2);
    312318                    RTTESTI_CHECK_RETV(papszArgs3[cArgs3] == NULL);
    313                     tstCheckNativeMsCrtToArgv(pszArgs2, g_aTests[i].cArgs, g_aTests[i].apszArgs);
     319                    if (g_aTests[i].pszSeparators == NULL)
     320                        tstCheckNativeMsCrtToArgv(pszArgs2, g_aTests[i].cArgs, g_aTests[i].apszArgs);
    314321
    315322                    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette