From 3a86c9c221ad688bcc81222114ac4c619fb5e5f2 Mon Sep 17 00:00:00 2001 From: Aleksandr Orefkov Date: Sat, 27 Dec 2025 16:34:35 +0300 Subject: [PATCH] =?UTF-8?q?-=20=D0=9C=D0=B5=D1=82=D0=BE=D0=B4=20c=5Fstr=20?= =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BD=20=D0=B8=D0=B7=20simple=5Fstr.?= =?UTF-8?q?=20-=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=20simple=5Fstr=20=D0=B8=D0=B7=20std::basic=5Fstring=20?= =?UTF-8?q?=D0=B8=20std::basic=5Fstring=5Fview.=20-=20=D0=98=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=20=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- docs/Doxyfile | 2 +- docs/Doxyfile_ru | 2 +- include/simstr/sstring.h | 75 +++++++++++++++++++++++++++++----------- include/simstr/strexpr.h | 2 +- readme.md | 2 +- readme_ru.md | 2 +- 7 files changed, 61 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b5a2f3..c635ea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ include(FetchContent) project( simstr - VERSION 1.2.9 + VERSION 1.3.0 DESCRIPTION "Yet another modern C++ string library" HOMEPAGE_URL "https://github.com/orefkov/simstr" LANGUAGES CXX diff --git a/docs/Doxyfile b/docs/Doxyfile index c2e821b..eaa3f45 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -48,7 +48,7 @@ PROJECT_NAME = "simstr" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.2.9 +PROJECT_NUMBER = 1.3.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewers a diff --git a/docs/Doxyfile_ru b/docs/Doxyfile_ru index 74efc00..39f5166 100644 --- a/docs/Doxyfile_ru +++ b/docs/Doxyfile_ru @@ -48,7 +48,7 @@ PROJECT_NAME = "simstr" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.2.9 +PROJECT_NUMBER = 1.3.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewers a diff --git a/include/simstr/sstring.h b/include/simstr/sstring.h index e51a529..5b68dfa 100644 --- a/include/simstr/sstring.h +++ b/include/simstr/sstring.h @@ -1,9 +1,9 @@ /* * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com - * ver. 1.2.4 + * ver. 1.3.0 * Классы для работы со строками * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com -* ver. 1.2.4 +* ver. 1.3.0 * Classes for working with strings */ @@ -490,6 +490,18 @@ SIMSTR_API std::optional impl_to_double(const K* start, const K* end); template class Splitter; +template +class null_terminated { +public: + /*! + * @ru @brief Получить указатель на константный буфер символов строки + * @return const K* - указатель на константный буфер символов строки + * @en @brief Get a pointer to a constant character buffer of a string + * @return const K* - pointer to a constant string character buffer + */ + const K* c_str() const { return static_cast(this)->symbols(); } +}; + template class buffer_pointers; /*! @@ -504,13 +516,6 @@ template class buffer_pointers { const Impl& d() const { return *static_cast(this); } public: - /*! - * @ru @brief Получить указатель на константный буфер символов строки - * @return const K* - указатель на константный буфер символов строки - * @en @brief Get a pointer to a constant character buffer of a string - * @return const K* - pointer to a constant string character buffer - */ - const K* c_str() const { return d().symbols(); } /*! * @ru @brief Получить указатель на константный буфер символов строки. * @return const K* - указатель на константный буфер символов строки. @@ -532,6 +537,20 @@ public: * @return const K* - end of line. */ const K* end() const { return d().symbols() + d().length(); } + /*! + * @ru @brief Получить указатель на константный буфер символов строки. + * @return const K* - указатель на константный буфер символов строки. + * @en @brief Get a pointer to a constant character buffer of a string. + * @return const K* - pointer to a constant buffer of string characters. + */ + const K* cbegin() const { return d().symbols(); } + /*! + * @ru @brief Указатель на константный символ после после последнего символа строки. + * @return const K* - конец строки. + * @en @brief Pointer to a constant character after the last character of the string. + * @return const K* - end of line. + */ + const K* cend() const { return d().symbols() + d().length(); } }; template @@ -560,6 +579,20 @@ public: * @return const K* - end of line. */ const K* end() const { return base::end(); } + /*! + * @ru @brief Получить указатель на константный буфер символов строки. + * @return const K* - указатель на константный буфер символов строки. + * @en @brief Get a pointer to a constant character buffer of a string. + * @return const K* - pointer to a constant buffer of string characters. + */ + const K* cbegin() const { return base::cbegin(); } + /*! + * @ru @brief Указатель на константный символ после после последнего символа строки. + * @return const K* - конец строки. + * @en @brief Pointer to a constant character after the last character of the string. + * @return const K* - end of line. + */ + const K* cend() const { return base::cend(); } /*! * @ru @brief Получить указатель на буфер символов строки. * @return K* - указатель на буфер символов строки. @@ -2225,8 +2258,8 @@ struct simple_str : str_algs, simple_str, false> { * provided that they are lvalue, that is, not temporary. */ template - requires(std::is_same_v || std::is_same_v - || std::is_same_v || std::is_same_v) + requires(std::is_same_v&> || std::is_same_v&> + || std::is_same_v&> || std::is_same_v&>) constexpr simple_str(S&& s) noexcept : str(s.data()), len(s.length()) {} /*! * @ru @brief Получить длину строки. @@ -2326,7 +2359,7 @@ struct simple_str : str_algs, simple_str, false> { * during compilation, or classes that store strings. */ template -struct simple_str_nt : simple_str { +struct simple_str_nt : simple_str, null_terminated> { using symb_type = K; using my_type = simple_str_nt; using base = simple_str; @@ -2704,9 +2737,9 @@ struct utf_convert_selector { * `wchar_t` - in Windows UTF-16, in Linux - UTF-32. */ template -class from_utf_convertable { +class from_utf_convertible { protected: - from_utf_convertable() = default; + from_utf_convertible() = default; using my_type = Impl; /* Эти методы должен реализовать класс-наследник. @@ -2717,7 +2750,7 @@ protected: public: template requires(!std::is_same_v) - from_utf_convertable(simple_str init) { + from_utf_convertible(simple_str init) { using worker = utf_convert_selector; Impl* d = static_cast(this); size_t len = init.length(); @@ -2732,7 +2765,7 @@ public: } template requires(!std::is_same_v) - from_utf_convertable(const str_algs, I, M>& init) : from_utf_convertable(init.to_str()) {} + from_utf_convertible(const str_algs, I, M>& init) : from_utf_convertible(init.to_str()) {} }; /*! @@ -4633,7 +4666,8 @@ class decl_empty_bases lstring : public str_algs, lstring, true>, public str_mutable>, public str_storable, Allocator>, - public from_utf_convertable> { + public null_terminated>, + public from_utf_convertible> { public: using symb_type = K; using my_type = lstring; @@ -4652,7 +4686,7 @@ protected: using base_algs = str_algs, my_type, true>; using base_storable = str_storable; using base_mutable = str_mutable; - using base_utf = from_utf_convertable; + using base_utf = from_utf_convertible; using traits = ch_traits; friend base_storable; @@ -5187,7 +5221,8 @@ template class decl_empty_bases sstring : public str_algs, sstring, false>, public str_storable, Allocator>, - public from_utf_convertable> { + public null_terminated>, + public from_utf_convertible> { public: using symb_type = K; using uns_type = std::make_unsigned_t; @@ -5199,7 +5234,7 @@ public: protected: using base_algs = str_algs, my_type, false>; using base_storable = str_storable; - using base_utf = from_utf_convertable; + using base_utf = from_utf_convertible; using traits = ch_traits; using uni = unicode_traits; diff --git a/include/simstr/strexpr.h b/include/simstr/strexpr.h index 4efa2f0..51f207c 100644 --- a/include/simstr/strexpr.h +++ b/include/simstr/strexpr.h @@ -1,5 +1,5 @@ /* - * ver. 1.2.4 + * ver. 1.3.0 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * База для строковых конкатенаций через выражения времени компиляции * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com diff --git a/readme.md b/readme.md index d36035c..33432cd 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ # simstr - String object and function library [![CMake on multiple platforms](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml/badge.svg)](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml) -Version 1.2.9. +Version 1.3.0. On Russian | По-русски diff --git a/readme_ru.md b/readme_ru.md index 2439807..f4e5efd 100644 --- a/readme_ru.md +++ b/readme_ru.md @@ -1,7 +1,7 @@ # simstr - библиотека строковых объектов и функций [![CMake on multiple platforms](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml/badge.svg)](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml) -Версия 1.2.9. +Версия 1.3.0. On English | По-английски