Skip to content

Commit

Permalink
[utils] use string utils when gcc >=12
Browse files Browse the repository at this point in the history
  • Loading branch information
yangli committed Sep 23, 2022
1 parent f20a579 commit d0c7f36
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ jobs:
cc: "gcc-11"
build: standalone
build_type: Release
# - name: "standalone gcc10"
# cxx: "g++-10"
# cc: "gcc-10"
# build: standalone
# build_type: Release
- name: "standalone gcc10"
cxx: "g++-10"
cc: "gcc-10"
build: standalone
build_type: Release
- name: "Unit Test gcc11"
cxx: "g++-11"
cc: "gcc-11"
build: test
build_type: Debug
# - name: "Unit Test gcc10"
# cxx: "g++-10"
# cc: "gcc-10"
# build: test
# build_type: Release
- name: "Unit Test gcc10"
cxx: "g++-10"
cc: "gcc-10"
build: test
build_type: Release
- name: "Unit Test gcc12"
cxx: "g++-12"
cc: "gcc-12"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![c++20](https://img.shields.io/badge/C++-c%2B%2B20-green)](https://en.cppreference.com/w/cpp/20)
[![CodeQL](https://github.com/ylab-hi/BINARY/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ylab-hi/BINARY/actions/workflows/codeql-analysis.yml)
[![License](https://img.shields.io/github/license/ylab-hi/BINARY)](https://github.com/ylab-hi/BINARY/blob/main/LICENSE)
![compiler](https://img.shields.io/badge/Compiler-GCC11%20%7C%20GCC12-green)
![compiler](https://img.shields.io/badge/Compiler-GCC10%20%7C%20GCC11%20%7C%20GCC12-green)

# **BI**oi**N**formatics **A**lgorithms lib**R**ar**Y** aka **BINARY**

Expand Down
11 changes: 7 additions & 4 deletions library/include/binary/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,21 @@ namespace binary::utils {
[[maybe_unused]] inline void set_trace() { spdlog::set_level(spdlog::level::trace); }
[[maybe_unused]] inline void set_info() { spdlog::set_level(spdlog::level::info); }

#ifdef __GNUC__
# if __GNUC__ >= 12
// trim from left
inline constexpr auto trim_front = std::ranges::views::drop_while(::isspace);
inline constexpr auto trim_front = std::views::drop_while(::isspace);

inline constexpr auto trim_back = std::ranges::views::reverse
| std::ranges::views::drop_while(::isspace)
| std::ranges::views::reverse;
inline constexpr auto trim_back
= std::views::reverse | std::views::drop_while(::isspace) | std::views::reverse;

inline constexpr auto trim = trim_front | trim_back;

auto split_str(std::string_view str, char delim) -> std::vector<std::string>;

std::string trim_str(std::string_view str);
# endif
#endif

} // namespace binary::utils

Expand Down
4 changes: 4 additions & 0 deletions library/source/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace binary::utils {
return std::filesystem::exists(file_path);
}

#ifdef __GNUC__
# if __GNUC__ >= 12
std::string trim_str(std::string_view str) {
auto temp = str | trim;
return {temp.begin(), temp.end()};
Expand All @@ -34,5 +36,7 @@ namespace binary::utils {
}
return result;
}
# endif
#endif

} // namespace binary::utils
4 changes: 4 additions & 0 deletions test/source/test_utils/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ TEST_SUITE("test binary utils") {
CHECK_NOTHROW(binary::utils::print_tuple(t1));
}

#ifdef __GNUC__
# if __GNUC__ >= 12
TEST_CASE("test trim view") {
using namespace binary::utils;

Expand All @@ -111,4 +113,6 @@ TEST_SUITE("test binary utils") {
CHECK_EQ(temp2.size(), 3);
CHECK_EQ(temp2[0], " test1 ");
}
# endif
#endif
}

0 comments on commit d0c7f36

Please sign in to comment.