Skip to content

Commit adeef0e

Browse files
chore: move helper function to detail namespace
1 parent c601afa commit adeef0e

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include(GNUInstallDirs)
66
add_library(${PROJECT_NAME} INTERFACE)
77
target_sources(${PROJECT_NAME} INTERFACE
88
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/cstringpp/core.hpp>"
9-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/cstringpp/helpers.hpp>"
9+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/cstringpp/detail.hpp>"
1010
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/cstringpp.hpp>")
1111
target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
1212

include/cstringpp.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#pragma once
22

33
#include "cstringpp/core.hpp"
4-
#include "cstringpp/helpers.hpp"
4+
#include "cstringpp/detail.hpp"

include/cstringpp/core.hpp

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
11
#pragma once
22

33
#include <cstddef>
4-
#include <cstring>
54
#include <array>
65
#include <compare>
76
#include <utility>
87

9-
#include "helpers.hpp"
8+
#include "detail.hpp"
109

1110
namespace cstringpp {
1211

13-
namespace detail {
14-
15-
template<size_t Length>
16-
constexpr size_t getPositiveIndex(int index) {
17-
while (index < 0) {
18-
index += Length;
19-
}
20-
while (index >= Length) {
21-
index -= Length;
22-
}
23-
return index;
24-
}
25-
26-
} // namespace detail
27-
2812
template<size_t Length>
2913
class String {
3014
public:
@@ -129,11 +113,11 @@ class String {
129113
}
130114

131115
[[nodiscard]] constexpr String<Length> toLower() const {
132-
return map(&cstringpp::toLower);
116+
return map(&cstringpp::detail::toLower);
133117
}
134118

135119
[[nodiscard]] constexpr String<Length> toUpper() const {
136-
return map(&cstringpp::toUpper);
120+
return map(&cstringpp::detail::toUpper);
137121
}
138122

139123
[[nodiscard]] constexpr String<Length> reverse() const {

include/cstringpp/helpers.hpp renamed to include/cstringpp/detail.hpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
namespace cstringpp {
3+
namespace cstringpp::detail {
44

55
[[nodiscard]] constexpr char toLower(char in) {
66
if (in >= 'A' && in <= 'Z') {
@@ -16,4 +16,15 @@ namespace cstringpp {
1616
return in;
1717
}
1818

19+
template<size_t Length>
20+
constexpr size_t getPositiveIndex(int index) {
21+
while (index < 0) {
22+
index += Length;
23+
}
24+
while (index >= Length) {
25+
index -= Length;
26+
}
27+
return index;
28+
}
29+
1930
} // namespace cstringpp

test/test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ TEST(String, slice) {
5454
}
5555

5656
TEST(String, map) {
57-
constexpr String str1 = String{"HElLo"}.map([](char c) { return cstringpp::toUpper(c); });
57+
constexpr String str1 = String{"HElLo"}.map([](char c) { return cstringpp::detail::toUpper(c); });
5858
EXPECT_STREQ(str1.toCString(), "HELLO");
5959

60-
constexpr String str2 = String{"HElLo"}.map(&cstringpp::toLower);
60+
constexpr String str2 = String{"HElLo"}.map(&cstringpp::detail::toLower);
6161
EXPECT_STREQ(str2.toCString(), "hello");
6262
}
6363

0 commit comments

Comments
 (0)