Skip to content

Commit 09a0f4e

Browse files
author
Julian LALU
committed
string impl
1 parent 87a0a58 commit 09a0f4e

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

interface/core/string/cstring_view.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ namespace hud
258258
return ptr_[i];
259259
}
260260

261-
private:
261+
[[nodiscard]]
262+
constexpr bool is_valid_c private :
262263
/**Pointer to the null-terminated C-style string. */
263264
char_type *ptr_;
264265
};

interface/core/string/string.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
#ifndef HD_INC_CORE_STRING_STRING_H
22
#define HD_INC_CORE_STRING_STRING_H
3+
#include "../containers/vector.h"
34

45
namespace hud
56
{
67
class string
78
{
9+
constexpr string() noexcept = default;
10+
constexpr string(const string &) noexcept = default;
11+
constexpr string(string &&) noexcept = default;
12+
constexpr string &operator=(const string &) noexcept = default;
13+
constexpr string &operator=(string &&) noexcept = default;
14+
815
private:
16+
hud::vector<char8> data_;
917
};
1018
} // namespace hud
1119

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef HD_INC_CORE_STRING_STRING_VIEW_H
2+
#define HD_INC_CORE_STRING_STRING_VIEW_H
3+
4+
namespace hud
5+
{
6+
/**
7+
* Valid UTF-8 string view
8+
*/
9+
template<typename char_t>
10+
struct cstring_view
11+
{
12+
13+
private:
14+
/** An UTF-8 valid string view. */
15+
char8 *ptr_;
16+
usize len;
17+
};
18+
19+
} // namespace hud
20+
21+
#endif // HD_INC_CORE_STRING_STRING_VIEW_H

src/string/cstring_view.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include <core/string/cstring_view.h>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#include <core/string.h>
3+
4+
GTEST_TEST(string, default_constructor_should_allocate_no_memory)
5+
{
6+
auto test = []() -> std::tuple<bool, usize, usize> {
7+
hud::string s;
8+
return std::tuple {
9+
s.data() == nullptr,
10+
s.count() == 0u,
11+
s.max_count() == 0u
12+
};
13+
};
14+
15+
// Non Constant
16+
{
17+
auto result = test();
18+
hud_assert_true(std::get<0>(result));
19+
hud_assert_eq(std::get<1>(result), 0u);
20+
hud_assert_eq(std::get<2>(result), 0u);
21+
}
22+
23+
// Constant
24+
{
25+
constexpr auto result = test();
26+
hud_assert_true(std::get<0>(result));
27+
hud_assert_eq(std::get<1>(result), 0u);
28+
hud_assert_eq(std::get<2>(result), 0u);
29+
}
30+
}

0 commit comments

Comments
 (0)