clean up list parsing logic and add clear warnings

This commit is contained in:
Phil Christensen 2019-08-23 10:20:18 -07:00
parent 051a6fd5b3
commit 13c95f16bf
2 changed files with 73 additions and 22 deletions

View File

@ -1,13 +1,16 @@
Source: cpprestsdk Source: cpprestsdk
Version: 2.10.14-1 Version: 2.10.14-1
Build-Depends: openssl (!uwp&!windows), boost-system (!uwp&!windows), boost-date-time (!uwp&!windows), boost-regex (!uwp&!windows), boost-thread (!uwp&!windows), boost-filesystem (!uwp&!windows), boost-random (!uwp&!windows), boost-chrono (!uwp&!windows), boost-asio (!uwp&!windows) Build-Depends: openssl (!uwp&!windows), boost-system (!uwp&!windows),
boost-date-time (!uwp&!windows), boost-regex (!uwp&!windows), boost-thread (!uwp&!windows),
boost-filesystem (!uwp&!windows), boost-random (!uwp&!windows), boost-chrono (!uwp&!windows),
boost-asio (!uwp&!windows)
Homepage: https://github.com/Microsoft/cpprestsdk Homepage: https://github.com/Microsoft/cpprestsdk
Description: C++11 JSON, REST, and OAuth library Description: C++11 JSON, REST, and OAuth library
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services. The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Default-Features: default-features Default-Features: default-features
Feature: default-features Feature: default-features
Build-Depends: cpprestsdk[brotli] (windows), cpprestsdk[core], cpprestsdk[compression], cpprestsdk[websockets] Build-Depends: cpprestsdk[brotli] (windows), cpprestsdk[core,compression,websockets]
Description: Features installed by default Description: Features installed by default
Feature: compression Feature: compression
@ -15,9 +18,9 @@ Build-Depends: zlib
Description: HTTP Compression support Description: HTTP Compression support
Feature: websockets Feature: websockets
Build-Depends: cpprestsdk[core], cpprestsdk[compression], websocketpp (!uwp), openssl (!uwp), boost-system (!uwp), boost-date-time (!uwp), boost-regex (!uwp) Build-Depends: cpprestsdk[core,compression], websocketpp (!uwp), openssl (!uwp), boost-system (!uwp), boost-date-time (!uwp), boost-regex (!uwp)
Description: Websockets support Description: Websockets support
Feature: brotli Feature: brotli
Build-Depends: cpprestsdk[core], cpprestsdk[compression], brotli Build-Depends: cpprestsdk[core,compression], brotli
Description: Brotli compression support Description: Brotli compression support

View File

@ -3,6 +3,7 @@
#include <vcpkg/parse.h> #include <vcpkg/parse.h>
#include <vcpkg/base/util.h> #include <vcpkg/base/util.h>
#include <vcpkg/base/system.print.h>
namespace vcpkg::Parse namespace vcpkg::Parse
{ {
@ -58,26 +59,73 @@ namespace vcpkg::Parse
std::vector<std::string> out; std::vector<std::string> out;
size_t cur = 0; auto iter = str.cbegin();
do
{
auto pos = str.find(',', cur);
if (pos == std::string::npos)
{
out.push_back(str.substr(cur));
break;
}
out.push_back(str.substr(cur, pos - cur));
// skip comma and space do {
++pos; // Trim leading whitespace of each element
while (is_whitespace(str[pos])) while (iter != str.cend() && is_whitespace(*iter))
{ {
++pos; ++iter;
} }
cur = pos; // Allow commas inside of [].
} while (cur != std::string::npos); 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))
{
// Update element_end after iter is incremented so it will be one past.
element_end = iter;
}
}
if (element_begin == element_end)
{
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 });
}
if (iter != str.cend())
{
//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"
);
}
}
} while (iter != str.cend());
return out; return out;
} }