adds line comments for CONTROL
Adds line comments denoted by # within CONTROL files.
For the moment a comment must be start with # and is valid
until the end of the line. It's not possible to add a comment
at the end of usable lines.
MODIFY
src/Paragraphs.cpp
src/Paragraphs.cpp
@@ -32,6 +32,16 @@ namespace vcpkg::Paragraphs
}
}
+ void skip_comment(char& ch)
+ {
+ while (ch != '\r')
+ next(ch);
+ if (ch == '\r')
+ next(ch);
+ if (ch == '\n')
+ next(ch);
+ }
+
void skip_spaces(char& ch)
{
while (ch == ' ' || ch == '\t')
@@ -45,6 +55,11 @@ namespace vcpkg::Paragraphs
|| (ch >= '0' && ch <= '9');
}
+ static bool is_comment(char ch)
+ {
+ return (ch == '#');
+ }
+
static bool is_lineend(char ch)
{
return ch == '\r' || ch == '\n' || ch == 0;
@@ -68,7 +83,7 @@ namespace vcpkg::Paragraphs
if (ch == '\n')
next(ch);
- if (is_alphanum(ch))
+ if (is_alphanum(ch) || is_comment(ch))
{
// Line begins a new field.
return;
@@ -115,6 +130,12 @@ namespace vcpkg::Paragraphs
std::string fieldvalue;
do
{
+ if (is_comment(ch))
+ {
+ skip_comment(ch);
+ continue;
+ }
+
get_fieldname(ch, fieldname);
auto it = fields.find(fieldname);

MODIFY
src/tests_paragraph.cpp
src/tests_paragraph.cpp
@@ -267,6 +267,28 @@ namespace UnitTest1
Assert::AreEqual("v4", pghs[1]["f4"].c_str());
}
+ TEST_METHOD(parse_paragraphs_comment)
+ {
+ const char* str =
+ "f1: v1\r\n"
+ "#comment\r\n"
+ "f2: v2\r\n"
+ "#comment\r\n"
+ "\r\n"
+ "#comment\r\n"
+ "f3: v3\r\n"
+ "#comment\r\n"
+ "f4: v4";
+ auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).value_or_exit(VCPKG_LINE_INFO);
+ Assert::AreEqual(size_t(2), pghs.size());
+ Assert::AreEqual(size_t(2), pghs[0].size());
+ Assert::AreEqual("v1", pghs[0]["f1"].c_str());
+ Assert::AreEqual("v2", pghs[0]["f2"].c_str());
+ Assert::AreEqual(size_t(2), pghs[1].size());
+ Assert::AreEqual("v3", pghs[1]["f3"].c_str());
+ Assert::AreEqual("v4", pghs[1]["f4"].c_str());
+ }
+
TEST_METHOD(BinaryParagraph_serialize_min)
{
std::stringstream ss;
@@ -361,7 +383,5 @@ namespace UnitTest1
}
};
- TEST_CLASS(Metrics)
- {
- };
+ TEST_CLASS(Metrics) { };
}

adds line comments for CONTROL

Adds line comments denoted by # within CONTROL files.
For the moment a comment must be start with # and is valid
until the end of the line. It's not possible to add a comment
at the end of usable lines.

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>