Skip to content

Commit

Permalink
fix string
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrulich committed Aug 16, 2024
1 parent b2d8706 commit edf06da
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion nautilus/include/nautilus/std/string.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "nautilus/val_ptr.hpp"
#include "nautilus/std/string_view.hpp"
#include <string>

namespace nautilus {
Expand Down Expand Up @@ -55,7 +56,7 @@ class val<std::basic_string<CharT, Traits>> {
* is valid and the values in it correspond to the values stored in the string with an additional null
* character after the last position.
*/
val<const CharT*> c_str() {
val<const CharT*> c_str() const {
return invoke(+[](base_type* ptr) -> const CharT* { return ptr->c_str(); }, data_ptr);
}

Expand Down
16 changes: 8 additions & 8 deletions nautilus/include/nautilus/std/string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ class val<std::basic_string_view<CharT, Traits>> {
return invoke(+[](std::basic_string_view<CharT, Traits>* ptr) { return ptr->cend(); }, data_ptr);
}

val<const_reference> operator[](val<size_type> pos) const {
val<value_type> operator[](val<size_type> pos) const {
return invoke(
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos) -> const_reference {
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos) -> value_type {
return ptr->operator[](pos);
},
data_ptr, pos);
}

const val<const_reference> at(val<size_type> index) const {
const val<value_type> at(val<size_type> index) const {
return invoke(
+[](std::basic_string_view<CharT, Traits>* ptr, size_type index) -> const_reference {
+[](std::basic_string_view<CharT, Traits>* ptr, size_type index) -> value_type {
return ptr->at(index);
},
data_ptr, index);
Expand All @@ -89,14 +89,14 @@ class val<std::basic_string_view<CharT, Traits>> {
return invoke(+[](std::basic_string_view<CharT, Traits>* ptr) { return ptr->empty(); }, data_ptr);
}

val<const_reference> front() const {
val<value_type> front() const {
return invoke(
+[](std::basic_string_view<CharT, Traits>* ptr) -> const_reference { return ptr->front(); }, data_ptr);
+[](std::basic_string_view<CharT, Traits>* ptr) -> value_type { return ptr->front(); }, data_ptr);
}

val<const_reference> back() const {
val<value_type> back() const {
return invoke(
+[](std::basic_string_view<CharT, Traits>* ptr) -> const_reference { return ptr->back(); }, data_ptr);
+[](std::basic_string_view<CharT, Traits>* ptr) -> value_type { return ptr->back(); }, data_ptr);
}

val<const_pointer> data() const {
Expand Down
4 changes: 3 additions & 1 deletion nautilus/src/nautilus/api/std/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ add_source_files(nautilus
cstring.cpp
cmath.cpp
cstdlib.cpp
iostream.cpp)
iostream.cpp
string.cpp
string_view.cpp)
9 changes: 9 additions & 0 deletions nautilus/src/nautilus/api/std/string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "nautilus/std/string.hpp"
#include "nautilus/function.hpp"

namespace nautilus {
template class val<std::basic_string<char, std::char_traits<char>>>;
template class val<std::basic_string<char16_t, std::char_traits<char16_t>>>;
template class val<std::basic_string<char32_t, std::char_traits<char32_t>>>;
template class val<std::basic_string<wchar_t, std::char_traits<wchar_t>>>;
} // namespace nautilus

0 comments on commit edf06da

Please sign in to comment.