message: clean up list parsing logic and add clear warnings
diff: #include <vcpkg/parse.h>
  #include <vcpkg/base/util.h>
  +#include <vcpkg/base/system.print.h>
  namespace vcpkg::Parse
  {
  @@ -58,26 +59,73 @@ namespace vcpkg::Parse
  std::vector<std::string> out;
  - size_t cur = 0;
  - do
  + auto iter = str.cbegin();
  +
  + do {
  + // Trim leading whitespace of each element
  + while (iter != str.cend() && is_whitespace(*iter))
  + {
  + ++iter;
  + }
  +
  + // Allow commas inside of [].
  + bool bracket_nesting = false;
  +
  + auto element_begin = iter;
  + auto element_end = iter;
  + while (iter != str.cend() && (*iter != ',' || bracket_nesting))
  + {
  + char value = *iter;
  +
  + // do not support nested []
  + if (value == '[')
  + {
  + bracket_nesting = true;
  + }
  + else if (value == ']')
  + {
  + bracket_nesting = false;
  + }
  +
  + ++iter;
  +
  + // Trim ending whitespace
  + if (!is_whitespace(value))
  {
  - auto pos = str.find(',', cur);
  - if (pos == std::string::npos)
  + // Update element_end after iter is incremented so it will be one past.
  + element_end = iter;
  + }
  + }
  +
  + if (element_begin == element_end)
  {
  - out.push_back(str.substr(cur));
  - break;
  + System::print2( System::Color::warning,
  + "Warning: empty element in list\n"
  + "> '", str, "'\n"
  + "> ", std::string(static_cast<int>(element_begin - str.cbegin()), ' '), "^\n"
  + );
  + }
  + else
  + {
  + out.push_back({ element_begin, element_end });
  }
  - out.push_back(str.substr(cur, pos - cur));
  - // skip comma and space
  - ++pos;
  - while (is_whitespace(str[pos]))
  + if (iter != str.cend())
  {
  - ++pos;
  + //Not at the end, must be at a comma that needs to be stepped over
  + ++iter;
  +
  + if (iter == str.end())
  + {
  + System::print2(System::Color::warning,
  + "Warning: empty element in list\n"
  + "> '", str, "'\n"
  + "> ", std::string(str.length(), ' '), "^\n"
  + );
  + }
  }
  - cur = pos;
  - } while (cur != std::string::npos);
  + } while (iter != str.cend());
  return out;
  }
  