diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-23 00:32:38 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-23 00:32:38 +0100 |
| commit | 0fa623093366351ad47583f47add6e51f56a56d8 (patch) | |
| tree | 3eaaa64f5c9b88798d2b971d2810f85cc3e06cd6 /nihil.ucl/string.ccm | |
| parent | 8cbb82a1f6eb6605a4615d30922b777e7bf1e4d8 (diff) | |
| download | nihil-0fa623093366351ad47583f47add6e51f56a56d8.tar.gz nihil-0fa623093366351ad47583f47add6e51f56a56d8.tar.bz2 | |
nihil.ucl: improve tests
Diffstat (limited to 'nihil.ucl/string.ccm')
| -rw-r--r-- | nihil.ucl/string.ccm | 48 |
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(); + } }; /* |
