-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Hampus Adolfsson <[email protected]>
- Loading branch information
1 parent
830f954
commit 7ab135b
Showing
5 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Generated by re2c 1.3 */ | ||
// Copyright 2011 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "dynout_parser.h" | ||
|
||
#include "metrics.h" | ||
#include "string_piece.h" | ||
|
||
bool DynoutParser::Parse(const std::string& content, | ||
std::vector<StringPiece>& result, std::string* err) { | ||
METRIC_RECORD("dynout parse"); | ||
/// Split `content` into a series of individual text lines, without trailing | ||
/// newlines, and remove empty lines | ||
const char* input = content.c_str(); | ||
const char* start = input; | ||
const char* limit = input + content.size(); | ||
while (start < limit) { | ||
const char* end = start; | ||
// Note: \r\n will be treated as a line end + an empty line, | ||
// the latter will be ignored. This simplifies the logic in this | ||
// loop to reduce its code and speed it up. | ||
while (end < limit && (*end != '\n' && *end != '\r')) | ||
++end; | ||
if (end > start) | ||
result.push_back(StringPiece(start, end - start)); | ||
start = end + 1; | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2011 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef NINJA_DYNOUT_PARSER_H_ | ||
#define NINJA_DYNOUT_PARSER_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "string_piece.h" | ||
|
||
/// Parser for dynout file. | ||
struct DynoutParser { | ||
|
||
/// Parse a dynout file, placing each listed output into `result`. | ||
/// The resulting StringPieces point into `content`. | ||
static bool Parse(const std::string& content, | ||
std::vector<StringPiece>& result, std::string* err); | ||
}; | ||
|
||
#endif // NINJA_DYNOUT_PARSER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2011 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "dynout_parser.h" | ||
|
||
#include "test.h" | ||
|
||
using namespace std; | ||
|
||
struct DynoutParserTest : public testing::Test { | ||
|
||
VirtualFileSystem fs_; | ||
}; | ||
|
||
TEST_F(DynoutParserTest, Empty) { | ||
std::string input = ""; | ||
string err; | ||
std::vector<StringPiece> result; | ||
EXPECT_TRUE(DynoutParser::Parse(input, result, &err)); | ||
ASSERT_EQ(err, ""); | ||
ASSERT_TRUE(result.empty()); | ||
} | ||
|
||
TEST_F(DynoutParserTest, MultipleEntries) { | ||
std::string input = "file1\nfile2\nfile3"; | ||
string err; | ||
std::vector<StringPiece> result; | ||
EXPECT_TRUE(DynoutParser::Parse(input, result, &err)); | ||
ASSERT_EQ(err, ""); | ||
ASSERT_EQ(result[0], "file1"); | ||
ASSERT_EQ(result[1], "file2"); | ||
ASSERT_EQ(result[2], "file3"); | ||
} | ||
|
||
TEST_F(DynoutParserTest, EmptyLines) { | ||
std::string input = "\nfile1\n\n\nfile2\n\n"; | ||
string err; | ||
std::vector<StringPiece> result; | ||
EXPECT_TRUE(DynoutParser::Parse(input, result, &err)); | ||
ASSERT_EQ(err, ""); | ||
ASSERT_EQ(result[0], "file1"); | ||
ASSERT_EQ(result[1], "file2"); | ||
} | ||
|
||
TEST_F(DynoutParserTest, CRLF) { | ||
std::string input = "\r\nfile1\r\n\r\nfile2\r\n"; | ||
string err; | ||
std::vector<StringPiece> result; | ||
EXPECT_TRUE(DynoutParser::Parse(input, result, &err)); | ||
ASSERT_EQ(err, ""); | ||
ASSERT_EQ(result[0], "file1"); | ||
ASSERT_EQ(result[1], "file2"); | ||
} |