Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix libdnf5::utils::patterns: Include missing headers, no inline API funcs, mark noexcept #1742

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions include/libdnf5/utils/patterns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,23 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef LIBDNF5_UTILS_PATTERNS_HPP
#define LIBDNF5_UTILS_PATTERNS_HPP

#include "libdnf5/defs.h"

#include <string>

namespace libdnf5::utils {

/// @brief Check if a given pattern is a GLOB.
///
/// @param pattern Text pattern to be test
/// @return True if a given pattern is a GLOB
inline bool is_glob_pattern(const char * pattern) {
return strpbrk(pattern, "*[?") != nullptr;
}

/// Return true if given pattern is a file path
LIBDNF_API bool is_glob_pattern(const char * pattern) noexcept;

/// @brief Check if a given pattern is a file path.
///
/// @param pattern Text pattern to be test
/// @return True if a given pattern is a file path
inline bool is_file_pattern(const std::string & pattern) {
return pattern[0] == '/' || (pattern[0] == '*' && pattern[1] == '/');
}
LIBDNF_API bool is_file_pattern(const std::string & pattern) noexcept;

} // namespace libdnf5::utils

Expand Down
34 changes: 34 additions & 0 deletions libdnf5/utils/patterns.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright Contributors to the libdnf project.

This file is part of libdnf: https://github.com/rpm-software-management/libdnf/

Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.

Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#include "libdnf5/utils/patterns.hpp"

#include <cstring>

namespace libdnf5::utils {

bool is_glob_pattern(const char * pattern) noexcept {
return strpbrk(pattern, "*[?") != nullptr;
}

bool is_file_pattern(const std::string & pattern) noexcept {
return pattern[0] == '/' || (pattern[0] == '*' && pattern[1] == '/');
}

} // namespace libdnf5::utils
Loading