Commit ef3df0e8 authored by Laszlo Csomor's avatar Laszlo Csomor

Use C++11 enum class

parent 416872ef
...@@ -362,7 +362,7 @@ wstring testonly_utf8_to_winpath(const char* path) { ...@@ -362,7 +362,7 @@ wstring testonly_utf8_to_winpath(const char* path) {
return as_windows_path(path, &wpath) ? wpath : wstring(); return as_windows_path(path, &wpath) ? wpath : wstring();
} }
int ExpandWildcards( ExpandWildcardsResult ExpandWildcards(
const string& path, std::function<void(const string&)> consume) { const string& path, std::function<void(const string&)> consume) {
if (path.find_first_of("*?") == string::npos) { if (path.find_first_of("*?") == string::npos) {
// There are no wildcards in the path, we don't need to expand it. // There are no wildcards in the path, we don't need to expand it.
...@@ -392,7 +392,7 @@ int ExpandWildcards( ...@@ -392,7 +392,7 @@ int ExpandWildcards(
dirname = path.substr(0, pos + 1); dirname = path.substr(0, pos + 1);
} }
int matched = ExpandWildcardsResult::kErrorNoMatchingFile; ExpandWildcardsResult matched = ExpandWildcardsResult::kErrorNoMatchingFile;
do { do {
// Ignore ".", "..", and directories. // Ignore ".", "..", and directories.
if ((metadata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 if ((metadata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0
...@@ -430,7 +430,7 @@ int ExpandWildcards( ...@@ -430,7 +430,7 @@ int ExpandWildcards(
dirname = path.substr(0, pos + 1); dirname = path.substr(0, pos + 1);
} }
int matched = ExpandWildcardsResult::kErrorNoMatchingFile; ExpandWildcardsResult matched = ExpandWildcardsResult::kErrorNoMatchingFile;
do { do {
// Ignore ".", "..", and directories. // Ignore ".", "..", and directories.
if ((metadata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 if ((metadata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0
......
...@@ -76,13 +76,11 @@ PROTOBUF_EXPORT int stat(const char* path, struct _stat* buffer); ...@@ -76,13 +76,11 @@ PROTOBUF_EXPORT int stat(const char* path, struct _stat* buffer);
PROTOBUF_EXPORT int write(int fd, const void* buffer, size_t size); PROTOBUF_EXPORT int write(int fd, const void* buffer, size_t size);
PROTOBUF_EXPORT std::wstring testonly_utf8_to_winpath(const char* path); PROTOBUF_EXPORT std::wstring testonly_utf8_to_winpath(const char* path);
struct ExpandWildcardsResult { enum ExpandWildcardsResult {
enum { kSuccess = 0,
kSuccess = 0, kErrorNoMatchingFile = 1,
kErrorNoMatchingFile = 1, kErrorInputPathConversion = 2,
kErrorInputPathConversion = 2, kErrorOutputPathConversion = 3,
kErrorOutputPathConversion = 3,
};
}; };
// Expand wildcards in a path pattern, feed the result to a consumer function. // Expand wildcards in a path pattern, feed the result to a consumer function.
...@@ -93,7 +91,7 @@ struct ExpandWildcardsResult { ...@@ -93,7 +91,7 @@ struct ExpandWildcardsResult {
// `consume`. The resulting paths may not be absolute nor normalized. // `consume`. The resulting paths may not be absolute nor normalized.
// //
// The function returns a value from `ExpandWildcardsResult`. // The function returns a value from `ExpandWildcardsResult`.
LIBPROTOBUF_EXPORT int ExpandWildcards( LIBPROTOBUF_EXPORT ExpandWildcardsResult ExpandWildcards(
const std::string& path, std::function<void(const std::string&)> consume); const std::string& path, std::function<void(const std::string&)> consume);
namespace strings { namespace strings {
......
...@@ -429,7 +429,7 @@ TEST_F(IoWin32Test, ExpandWildcardsInRelativePathTest) { ...@@ -429,7 +429,7 @@ TEST_F(IoWin32Test, ExpandWildcardsInRelativePathTest) {
int found_b = 0; int found_b = 0;
vector<string> found_bad; vector<string> found_bad;
// Assert matching a relative path pattern. Results should also be relative. // Assert matching a relative path pattern. Results should also be relative.
int result = ExpandWildcardsResult result =
ExpandWildcards( ExpandWildcards(
string(kUtf8Text) + "\\foo*.proto", string(kUtf8Text) + "\\foo*.proto",
[&found_a, &found_b, &found_bad](const string& p) { [&found_a, &found_b, &found_bad](const string& p) {
...@@ -481,7 +481,7 @@ TEST_F(IoWin32Test, ExpandWildcardsInAbsolutePathTest) { ...@@ -481,7 +481,7 @@ TEST_F(IoWin32Test, ExpandWildcardsInAbsolutePathTest) {
vector<string> found_bad; vector<string> found_bad;
// Assert matching an absolute path. The results should also use absolute // Assert matching an absolute path. The results should also use absolute
// path. // path.
int result = ExpandWildcardsResult result =
ExpandWildcards( ExpandWildcards(
string(test_tmpdir) + "\\" + kUtf8Text + "\\foo*.proto", string(test_tmpdir) + "\\" + kUtf8Text + "\\foo*.proto",
[this, &found_a, &found_b, &found_bad](const string& p) { [this, &found_a, &found_b, &found_bad](const string& p) {
...@@ -544,7 +544,7 @@ TEST_F(IoWin32Test, ExpandWildcardsIgnoresDirectoriesTest) { ...@@ -544,7 +544,7 @@ TEST_F(IoWin32Test, ExpandWildcardsIgnoresDirectoriesTest) {
vector<string> found_bad; vector<string> found_bad;
// Assert that the pattern matches exactly the expected files, and using the // Assert that the pattern matches exactly the expected files, and using the
// absolute path as did the input pattern. // absolute path as did the input pattern.
int result = ExpandWildcardsResult result =
ExpandWildcards( ExpandWildcards(
string(kUtf8Text) + "\\foo*.proto", string(kUtf8Text) + "\\foo*.proto",
[&found_a, &found_c, &found_bad](const string& p) { [&found_a, &found_c, &found_bad](const string& p) {
...@@ -573,7 +573,7 @@ TEST_F(IoWin32Test, ExpandWildcardsFailsIfNoFileMatchesTest) { ...@@ -573,7 +573,7 @@ TEST_F(IoWin32Test, ExpandWildcardsFailsIfNoFileMatchesTest) {
EXPECT_TRUE(SetCurrentDirectoryW(wtest_tmpdir.c_str())); EXPECT_TRUE(SetCurrentDirectoryW(wtest_tmpdir.c_str()));
// Control test: should match foo*.proto // Control test: should match foo*.proto
int result = ExpandWildcards( ExpandWildcardsResult result = ExpandWildcards(
string(kUtf8Text) + "\\foo*.proto", [](const string&) {}); string(kUtf8Text) + "\\foo*.proto", [](const string&) {});
EXPECT_EQ(result, ExpandWildcardsResult::kSuccess); EXPECT_EQ(result, ExpandWildcardsResult::kSuccess);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment