diff options
| author | Phil Christensen <philc@microsoft.com> | 2019-08-23 10:20:18 -0700 |
|---|---|---|
| committer | Phil Christensen <philc@microsoft.com> | 2019-08-23 10:20:18 -0700 |
| commit | 13c95f16bfab4e516d088e15a1e77733b3f8745f (patch) | |
| tree | 32ae776badfc2eba8bed4689afbacb46eb63322f | |
| parent | 051a6fd5b3d83fedc83592236413c9b8c0015c6d (diff) | |
| download | vcpkg-13c95f16bfab4e516d088e15a1e77733b3f8745f.tar.gz vcpkg-13c95f16bfab4e516d088e15a1e77733b3f8745f.zip | |
clean up list parsing logic and add clear warnings
| -rw-r--r-- | ports/cpprestsdk/CONTROL | 11 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/parse.cpp | 88 |
2 files changed, 75 insertions, 24 deletions
diff --git a/ports/cpprestsdk/CONTROL b/ports/cpprestsdk/CONTROL index 877164673..6f6a2a307 100644 --- a/ports/cpprestsdk/CONTROL +++ b/ports/cpprestsdk/CONTROL @@ -1,13 +1,16 @@ Source: cpprestsdk 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 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. Default-Features: 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 Feature: compression @@ -15,9 +18,9 @@ Build-Depends: zlib Description: HTTP Compression support 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 Feature: brotli -Build-Depends: cpprestsdk[core], cpprestsdk[compression], brotli +Build-Depends: cpprestsdk[core,compression], brotli Description: Brotli compression support diff --git a/toolsrc/src/vcpkg/parse.cpp b/toolsrc/src/vcpkg/parse.cpp index 8f90aef15..91b2b2786 100644 --- a/toolsrc/src/vcpkg/parse.cpp +++ b/toolsrc/src/vcpkg/parse.cpp @@ -3,6 +3,7 @@ #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 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 - ++pos; - while (is_whitespace(str[pos])) - { - ++pos; - } - - cur = pos; - } while (cur != std::string::npos); + 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)) + { + // 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; } |
