From d5a0f1927d13e9b54ed33ab7839fc21b71a3d439 Mon Sep 17 00:00:00 2001 From: rexy712 Date: Sun, 19 Jun 2022 11:27:57 -0700 Subject: [PATCH] Add iterators to cx/string and fix including null terminator in length when created from an array --- include/rexy/cx/string.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/rexy/cx/string.hpp b/include/rexy/cx/string.hpp index cbac8c8..9e3b5b4 100644 --- a/include/rexy/cx/string.hpp +++ b/include/rexy/cx/string.hpp @@ -69,6 +69,9 @@ namespace rexy::cx{ for(size_type i = 0;i < M;++i){ m_data[i] = data[i]; } + if(m_data[m_length - 1] == 0){ + --m_length; //exclude null terminator in length + } } constexpr string(const_pointer data)noexcept: m_length(rexy::strlen(data)) @@ -132,6 +135,19 @@ namespace rexy::cx{ constexpr operator const_pointer(void)const noexcept {return m_data;} + constexpr iterator begin(void)noexcept + {return m_data;} + constexpr const_iterator begin(void)const noexcept + {return m_data;} + constexpr const_iterator cbegin(void)const noexcept + {return m_data;} + constexpr iterator end(void)noexcept + {return m_data+m_length;} + constexpr const_iterator end(void)const noexcept + {return m_data+m_length;} + constexpr const_iterator cend(void)const noexcept + {return m_data+m_length;} + constexpr bool valid(void)const noexcept {return m_length > 0;} constexpr reference operator[](size_type i)noexcept