aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Christensen <philc@microsoft.com>2019-08-26 16:21:57 -0700
committerPhil Christensen <philc@microsoft.com>2019-08-26 16:21:57 -0700
commit6d8e66ff4fe40ef0937e33e809287476e2c04ee5 (patch)
treebb7acc7c2d5a2c33775501866f165c1a95112dc1
parentbd4678610b221ae6cd4911295e84808ea7924cc6 (diff)
downloadvcpkg-6d8e66ff4fe40ef0937e33e809287476e2c04ee5.tar.gz
vcpkg-6d8e66ff4fe40ef0937e33e809287476e2c04ee5.zip
Run clang-format and add more error messages
-rw-r--r--toolsrc/src/vcpkg/parse.cpp154
1 files changed, 82 insertions, 72 deletions
diff --git a/toolsrc/src/vcpkg/parse.cpp b/toolsrc/src/vcpkg/parse.cpp
index 91b2b2786..a3f4186fc 100644
--- a/toolsrc/src/vcpkg/parse.cpp
+++ b/toolsrc/src/vcpkg/parse.cpp
@@ -2,8 +2,8 @@
#include <vcpkg/parse.h>
-#include <vcpkg/base/util.h>
#include <vcpkg/base/system.print.h>
+#include <vcpkg/base/util.h>
namespace vcpkg::Parse
{
@@ -45,10 +45,7 @@ namespace vcpkg::Parse
return nullptr;
}
- static bool is_whitespace(char c)
- {
- return c == ' ' || c == '\t' || c == '\n' || c == '\r';
- }
+ static bool is_whitespace(char c) { return c == ' ' || c == '\t' || c == '\n' || c == '\r'; }
std::vector<std::string> parse_comma_list(const std::string& str)
{
@@ -59,73 +56,86 @@ namespace vcpkg::Parse
std::vector<std::string> out;
- 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());
+ 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 == '[')
+ {
+ Checks::check_exit(VCPKG_LINE_INFO,
+ !bracket_nesting,
+ "Lists do not support nested brackets, Did you forget a ']'?\n"
+ "> '%s'\n"
+ "> %s^\n",
+ str,
+ std::string(static_cast<int>(iter - str.cbegin()), ' '));
+ bracket_nesting = true;
+ }
+ else if (value == ']')
+ {
+ Checks::check_exit(VCPKG_LINE_INFO,
+ bracket_nesting,
+ "Found unmatched ']'. Did you forget a '['?\n"
+ "> '%s'\n"
+ "> %s^\n",
+ str,
+ std::string(static_cast<int>(iter - str.cbegin()), ' '));
+ 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;
+ }
+ }
+
+ Checks::check_exit(VCPKG_LINE_INFO,
+ element_begin != element_end,
+ "Empty element in list\n"
+ "> '%s'\n"
+ "> %s^\n",
+ str,
+ std::string(static_cast<int>(element_begin - str.cbegin()), ' '));
+
+ out.push_back({element_begin, element_end});
+
+ if (iter != str.cend())
+ {
+ Checks::check_exit(VCPKG_LINE_INFO, *iter == ',', "Internal parsing error - expected comma");
+
+ // Not at the end, must be at a comma that needs to be stepped over
+ ++iter;
+
+ Checks::check_exit(VCPKG_LINE_INFO,
+ iter != str.end(),
+ "Empty element in list\n"
+ "> '%s'\n"
+ "> %s^\n",
+ str,
+ std::string(str.length(), ' '));
+ }
+
+ } while (iter != str.cend());
return out;
}