mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-06-07 11:42:48 +08:00
Run clang-format and add more error messages
This commit is contained in:
parent
bd4678610b
commit
6d8e66ff4f
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <vcpkg/parse.h>
|
#include <vcpkg/parse.h>
|
||||||
|
|
||||||
#include <vcpkg/base/util.h>
|
|
||||||
#include <vcpkg/base/system.print.h>
|
#include <vcpkg/base/system.print.h>
|
||||||
|
#include <vcpkg/base/util.h>
|
||||||
|
|
||||||
namespace vcpkg::Parse
|
namespace vcpkg::Parse
|
||||||
{
|
{
|
||||||
@ -45,10 +45,7 @@ namespace vcpkg::Parse
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_whitespace(char c)
|
static bool is_whitespace(char c) { return c == ' ' || c == '\t' || c == '\n' || c == '\r'; }
|
||||||
{
|
|
||||||
return c == ' ' || c == '\t' || c == '\n' || c == '\r';
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> parse_comma_list(const std::string& str)
|
std::vector<std::string> parse_comma_list(const std::string& str)
|
||||||
{
|
{
|
||||||
@ -59,73 +56,86 @@ namespace vcpkg::Parse
|
|||||||
|
|
||||||
std::vector<std::string> out;
|
std::vector<std::string> out;
|
||||||
|
|
||||||
auto iter = str.cbegin();
|
auto iter = str.cbegin();
|
||||||
|
|
||||||
do {
|
do
|
||||||
// Trim leading whitespace of each element
|
{
|
||||||
while (iter != str.cend() && is_whitespace(*iter))
|
// Trim leading whitespace of each element
|
||||||
{
|
while (iter != str.cend() && is_whitespace(*iter))
|
||||||
++iter;
|
{
|
||||||
}
|
++iter;
|
||||||
|
}
|
||||||
|
|
||||||
// Allow commas inside of [].
|
// Allow commas inside of [].
|
||||||
bool bracket_nesting = false;
|
bool bracket_nesting = false;
|
||||||
|
|
||||||
auto element_begin = iter;
|
auto element_begin = iter;
|
||||||
auto element_end = iter;
|
auto element_end = iter;
|
||||||
while (iter != str.cend() && (*iter != ',' || bracket_nesting))
|
while (iter != str.cend() && (*iter != ',' || bracket_nesting))
|
||||||
{
|
{
|
||||||
char value = *iter;
|
char value = *iter;
|
||||||
|
|
||||||
// do not support nested []
|
// do not support nested []
|
||||||
if (value == '[')
|
if (value == '[')
|
||||||
{
|
{
|
||||||
bracket_nesting = true;
|
Checks::check_exit(VCPKG_LINE_INFO,
|
||||||
}
|
!bracket_nesting,
|
||||||
else if (value == ']')
|
"Lists do not support nested brackets, Did you forget a ']'?\n"
|
||||||
{
|
"> '%s'\n"
|
||||||
bracket_nesting = false;
|
"> %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;
|
++iter;
|
||||||
|
|
||||||
// Trim ending whitespace
|
// Trim ending whitespace
|
||||||
if (!is_whitespace(value))
|
if (!is_whitespace(value))
|
||||||
{
|
{
|
||||||
// Update element_end after iter is incremented so it will be one past.
|
// Update element_end after iter is incremented so it will be one past.
|
||||||
element_end = iter;
|
element_end = iter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element_begin == element_end)
|
Checks::check_exit(VCPKG_LINE_INFO,
|
||||||
{
|
element_begin != element_end,
|
||||||
System::print2( System::Color::warning,
|
"Empty element in list\n"
|
||||||
"Warning: empty element in list\n"
|
"> '%s'\n"
|
||||||
"> '", str, "'\n"
|
"> %s^\n",
|
||||||
"> ", std::string(static_cast<int>(element_begin - str.cbegin()), ' '), "^\n"
|
str,
|
||||||
);
|
std::string(static_cast<int>(element_begin - str.cbegin()), ' '));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
out.push_back({ element_begin, element_end });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iter != str.cend())
|
out.push_back({element_begin, element_end});
|
||||||
{
|
|
||||||
//Not at the end, must be at a comma that needs to be stepped over
|
|
||||||
++iter;
|
|
||||||
|
|
||||||
if (iter == str.end())
|
if (iter != str.cend())
|
||||||
{
|
{
|
||||||
System::print2(System::Color::warning,
|
Checks::check_exit(VCPKG_LINE_INFO, *iter == ',', "Internal parsing error - expected comma");
|
||||||
"Warning: empty element in list\n"
|
|
||||||
"> '", str, "'\n"
|
|
||||||
"> ", std::string(str.length(), ' '), "^\n"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (iter != str.cend());
|
// 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;
|
return out;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user