aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.ucl/string.ccm
diff options
context:
space:
mode:
Diffstat (limited to 'nihil.ucl/string.ccm')
-rw-r--r--nihil.ucl/string.ccm48
1 files changed, 45 insertions, 3 deletions
diff --git a/nihil.ucl/string.ccm b/nihil.ucl/string.ccm
index 64f88dc..f92c82c 100644
--- a/nihil.ucl/string.ccm
+++ b/nihil.ucl/string.ccm
@@ -17,10 +17,16 @@ import :object;
namespace nihil::ucl {
export struct string final : object {
- using value_type = std::string_view;
-
+ using contained_type = std::string_view;
inline static constexpr object_type ucl_type = object_type::string;
+ using value_type = char const;
+ using size_type = std::size_t;
+ using difference_type = std::ptrdiff_t;
+ using reference = value_type &;
+ using pointer = value_type *;
+ using iterator = pointer;
+
// Create a new string from a UCL object.
string(ref_t, ::ucl_object_t const *uobj)
: object(nihil::ucl::ref, uobj)
@@ -71,7 +77,7 @@ export struct string final : object {
{}
// Return the value of this string.
- auto value(this string const &self) -> value_type
+ auto value(this string const &self) -> contained_type
{
char const *dptr{};
std::size_t dlen;
@@ -83,6 +89,42 @@ export struct string final : object {
// This should never fail.
std::abort();
}
+
+ // Return the size of this string.
+ auto size(this string const &self) -> size_type
+ {
+ return self.value().size();
+ }
+
+ // Test if this string is empty.
+ auto empty(this string const &self) -> bool
+ {
+ return self.size() == 0;
+ }
+
+ // Access this string's data
+ auto data(this string const &self) -> pointer
+ {
+ char const *dptr{};
+
+ auto const *uobj = self.get_ucl_object();
+ if (::ucl_object_tostring_safe(uobj, &dptr))
+ return dptr;
+
+ // This should never fail.
+ std::abort();
+ }
+
+ // Iterator access
+ auto begin(this string const &self) -> iterator
+ {
+ return self.data();
+ }
+
+ auto end(this string const &self) -> iterator
+ {
+ return self.data() + self.size();
+ }
};
/*