add const

This commit is contained in:
stavrolia 2019-08-30 18:19:05 +03:00
parent f51901bb3f
commit 974789d379
2 changed files with 25 additions and 25 deletions

View File

@ -54,36 +54,36 @@ namespace
std::vector<std::string> LSWithRegexpMatching(const std::string & path_for_ls, const std::string & for_match) std::vector<std::string> LSWithRegexpMatching(const std::string & path_for_ls, const std::string & for_match)
{ {
size_t first_glob = for_match.find_first_of("*?{"); const size_t first_glob = for_match.find_first_of("*?{");
size_t end_of_path_without_globs = for_match.substr(0, first_glob).rfind('/'); const size_t end_of_path_without_globs = for_match.substr(0, first_glob).rfind('/');
std::string suffix_with_globs = for_match.substr(end_of_path_without_globs); /// begin with '/' const std::string suffix_with_globs = for_match.substr(end_of_path_without_globs); /// begin with '/'
size_t next_slash = suffix_with_globs.find('/', 1); const size_t next_slash = suffix_with_globs.find('/', 1);
re2::RE2 matcher(makeRegexpPatternFromGlobs(suffix_with_globs.substr(0, next_slash))); re2::RE2 matcher(makeRegexpPatternFromGlobs(suffix_with_globs.substr(0, next_slash)));
std::vector<std::string> result; std::vector<std::string> result;
std::string preffix_without_globs = path_for_ls + for_match.substr(1, end_of_path_without_globs); const std::string prefix_without_globs = path_for_ls + for_match.substr(1, end_of_path_without_globs);
if (!fs::exists(fs::path(preffix_without_globs.data()))) if (!fs::exists(fs::path(prefix_without_globs.data())))
{ {
return result; return result;
} }
fs::directory_iterator end; const fs::directory_iterator end;
for (fs::directory_iterator it(preffix_without_globs); it != end; ++it) for (fs::directory_iterator it(prefix_without_globs); it != end; ++it)
{ {
std::string full_path = it->path().string(); const std::string full_path = it->path().string();
size_t last_slash = full_path.rfind('/'); const size_t last_slash = full_path.rfind('/');
String file_name = full_path.substr(last_slash); const String file_name = full_path.substr(last_slash);
/// Condition with next_slash means what we are looking for (it is from current position in psttern of path) const bool looking_for_directory = next_slash != std::string::npos;
/// Condition is_directory means what kind of path is it in current iteration of ls /// Condition is_directory means what kind of path is it in current iteration of ls
if ((!fs::is_directory(it->path())) && (next_slash == std::string::npos)) if (!fs::is_directory(it->path()) && !looking_for_directory)
{ {
if (re2::RE2::FullMatch(file_name, matcher)) if (re2::RE2::FullMatch(file_name, matcher))
{ {
result.push_back(it->path().string()); result.push_back(it->path().string());
} }
} }
else if ((fs::is_directory(it->path())) && (next_slash != std::string::npos)) else if (fs::is_directory(it->path()) && looking_for_directory)
{ {
if (re2::RE2::FullMatch(file_name, matcher)) if (re2::RE2::FullMatch(file_name, matcher))
{ {

View File

@ -137,13 +137,13 @@ private:
*/ */
Strings LSWithRegexpMatching(const String & path_for_ls, const HDFSFSPtr & fs, const String & for_match) Strings LSWithRegexpMatching(const String & path_for_ls, const HDFSFSPtr & fs, const String & for_match)
{ {
size_t first_glob = for_match.find_first_of("*?{"); const size_t first_glob = for_match.find_first_of("*?{");
size_t end_of_path_without_globs = for_match.substr(0, first_glob).rfind('/'); const size_t end_of_path_without_globs = for_match.substr(0, first_glob).rfind('/');
String suffix_with_globs = for_match.substr(end_of_path_without_globs); /// begin with '/' const String suffix_with_globs = for_match.substr(end_of_path_without_globs); /// begin with '/'
String prefix_without_globs = path_for_ls + for_match.substr(1, end_of_path_without_globs); /// ends with '/' const String prefix_without_globs = path_for_ls + for_match.substr(1, end_of_path_without_globs); /// ends with '/'
size_t next_slash = suffix_with_globs.find('/', 1); const size_t next_slash = suffix_with_globs.find('/', 1);
re2::RE2 matcher(makeRegexpPatternFromGlobs(suffix_with_globs.substr(0, next_slash))); re2::RE2 matcher(makeRegexpPatternFromGlobs(suffix_with_globs.substr(0, next_slash)));
HDFSFileInfo ls; HDFSFileInfo ls;
@ -151,19 +151,19 @@ Strings LSWithRegexpMatching(const String & path_for_ls, const HDFSFSPtr & fs, c
Strings result; Strings result;
for (int i = 0; i < ls.length; ++i) for (int i = 0; i < ls.length; ++i)
{ {
String full_path = String(ls.file_info[i].mName); const String full_path = String(ls.file_info[i].mName);
size_t last_slash = full_path.rfind('/'); const size_t last_slash = full_path.rfind('/');
String file_name = full_path.substr(last_slash); const String file_name = full_path.substr(last_slash);
/// Condition with next_slash means what we are looking for (it is from current position in psttern of path) const bool looking_for_directory = next_slash != std::string::npos;
/// Condition with type of current file_info means what kind of path is it in current iteration of ls /// Condition with type of current file_info means what kind of path is it in current iteration of ls
if ((ls.file_info[i].mKind == 'F') && (next_slash == std::string::npos)) if ((ls.file_info[i].mKind == 'F') && !looking_for_directory)
{ {
if (re2::RE2::FullMatch(file_name, matcher)) if (re2::RE2::FullMatch(file_name, matcher))
{ {
result.push_back(String(ls.file_info[i].mName)); result.push_back(String(ls.file_info[i].mName));
} }
} }
else if ((ls.file_info[i].mKind == 'D') && (next_slash != std::string::npos)) else if ((ls.file_info[i].mKind == 'D') && looking_for_directory)
{ {
if (re2::RE2::FullMatch(file_name, matcher)) if (re2::RE2::FullMatch(file_name, matcher))
{ {