Strange behavior in StringArray::fromTokens()

I’m using StringArray::fromTokens() to parse command-line options to my app. I want something like

This is what I have:

This is the strange part. Here’s three instances of command-line input and the contents of cmdparams afterwards.

> software.exe --open=C:\filename_without_spaces.txt --other-parameter
cmdparams[0] = --open=C:\filename_without_spaces.txt
cmdparams[1] = --other-parameter
-------------------------------
> software.exe --open="C:\filename_without_spaces.txt" --other-parameter
cmdparams[0] = --open=C:\filename_without_spaces.txt
cmdparams[1] = --other-parameter
-------------------------------
> software.exe --open="C:\filename with spaces.txt" --other-parameter
cmdparams[0] = "--open=C:\filename with spaces.txt"
cmdparams[1] = --other-parameter

It always keeps the right parameters together, which is good. In the second instance, it gets rid of the quotes, which is okay but a little strange. But in the third instance, it gets rid of the quotes around the filename, and adds them around the whole parameter! Then comparing the first characters to “–open=” fails, and it doesn’t recognize the command-line parameters.

Right now I have the workaround of using cmdparams[0].unquoted(), which works fine. But I was wondering if this was intentional behavior of StringArray::fromTokens() or a bug (there’s nothing about this in the API documentation). Thanks!

I don't think this is any kind of problem in StringArray::fromTokens, it's more that the command-line arguments are already tokenised in a way you can't achieve by trying to tokenise the whole command-line. If you use JUCEApplicationBase::getCommandLineParameterArray() then it'll handle quotes correctly.

Didn't know that existed, thanks!