diff options
| author | 2025-02-28 02:00:57 +0000 | |
|---|---|---|
| committer | 2025-02-28 02:00:57 +0000 | |
| commit | 7ca99a5a00ffe943e23ca870fb22694f560b48e2 (patch) | |
| tree | 510800ed124f7d0497e1fba15c05280867184431 | |
| parent | Merge branch 'insp4' into master. (diff) | |
Replace insp::substring_view with the C++20 iterator constructor.
| -rw-r--r-- | include/utility/string.h | 14 | ||||
| -rw-r--r-- | modules/core/core_message.cpp | 10 |
2 files changed, 5 insertions, 19 deletions
diff --git a/include/utility/string.h b/include/utility/string.h index 8ed918474..dc432b0f2 100644 --- a/include/utility/string.h +++ b/include/utility/string.h @@ -44,20 +44,6 @@ namespace insp return joined; } - /** Creates a view of a subsection of a string. - * @param str The string to create a view of. - * @param begin The position within the string to start the view at. - * @param end The position within the string to end the view at. - */ - template <typename Iterator> - std::string_view substring_view(const std::string& str, Iterator begin, Iterator end) - { - std::string_view sv = str; - sv.remove_prefix(std::distance(str.begin(), begin)); - sv.remove_suffix(std::distance(end, str.end())); - return sv; - } - /** Get underlying C string of the string passed as parameter. Useful in template functions. * @param str A `const char*` string. */ diff --git a/modules/core/core_message.cpp b/modules/core/core_message.cpp index e6d92857f..6cd1ea8c8 100644 --- a/modules/core/core_message.cpp +++ b/modules/core/core_message.cpp @@ -47,13 +47,13 @@ public: if (end_of_name == std::string::npos) { // The CTCP only contains a name. - name = insp::substring_view(text, text.begin() + 1, text.end() - end_of_ctcp); + name = std::string_view(text.begin() + 1, text.end() - end_of_ctcp); body = std::string_view(); return true; } // The CTCP contains a name and a body. - name = insp::substring_view(text, text.begin() + 1, text.begin() + end_of_name); + name = std::string_view(text.begin() + 1, text.begin() + end_of_name); size_t start_of_body = text.find_first_not_of(' ', end_of_name + 1); if (start_of_body == std::string::npos) @@ -64,7 +64,7 @@ public: } // The CTCP body provided was non-empty. - body = insp::substring_view(text, text.begin() + start_of_body, text.end() - end_of_ctcp); + body = std::string_view(text.begin() + start_of_body, text.end() - end_of_ctcp); return true; } @@ -78,12 +78,12 @@ public: { // The CTCP only contains a name. size_t end_of_ctcp = text.back() == '\x1' ? 1 : 0; - name = insp::substring_view(text, text.begin() + 1, text.end() - end_of_ctcp); + name = std::string_view(text.begin() + 1, text.end() - end_of_ctcp); return true; } // The CTCP contains a name and a body. - name = insp::substring_view(text, text.begin() + 1, text.begin() + end_of_name); + name = std::string_view(text.begin() + 1, text.begin() + end_of_name); return true; } |
