Skip to content

Commit

Permalink
libdnf5::utils::patterns: No inline API functions, mark noexcept
Browse files Browse the repository at this point in the history
  • Loading branch information
jrohel authored and kontura committed Oct 4, 2024
1 parent ac45377 commit 48cd6bb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
13 changes: 4 additions & 9 deletions include/libdnf5/utils/patterns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef LIBDNF5_UTILS_PATTERNS_HPP
#define LIBDNF5_UTILS_PATTERNS_HPP

#include <cstring>
#include "libdnf5/defs.h"

#include <string>

namespace libdnf5::utils {
Expand All @@ -29,19 +30,13 @@ namespace libdnf5::utils {
///
/// @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

0 comments on commit 48cd6bb

Please sign in to comment.