cmcfarlen commented on code in PR #12167: URL: https://github.com/apache/trafficserver/pull/12167#discussion_r2079584283
########## include/tscore/ink_memory.h: ########## @@ -617,3 +618,45 @@ struct ats_unique_buf_deleter { }; using ats_unique_buf = std::unique_ptr<uint8_t[], ats_unique_buf_deleter>; ats_unique_buf ats_unique_malloc(size_t size); + +class c_str_view +{ +public: + using size_type = std::string_view::size_type; + + c_str_view() : c_str_view(nullptr, 0) {} + explicit c_str_view(const char *data, size_type length) + : c_str_view{ + std::string_view{data, length} + } + { + } + explicit c_str_view(std::string_view sv) : sv_{sv} + { + ink_assert(sv_.data() == nullptr ? sv_.length() == 0 : sv_.data()[sv_.length()] == '\0'); Review Comment: `sv_.data()[sv_.length()] == '\0'` could be considered UB if the string_view is not null terminated as this might be reading past a buffer, but since this is an assert anyway its fine if it crashes when called with a non-null terminated string_view. ########## include/tscore/ink_memory.h: ########## @@ -617,3 +618,45 @@ struct ats_unique_buf_deleter { }; using ats_unique_buf = std::unique_ptr<uint8_t[], ats_unique_buf_deleter>; ats_unique_buf ats_unique_malloc(size_t size); + +class c_str_view Review Comment: I think this is ok, BUT, please add a comment here that the purpose of this class is to transition between older code that uses `char *` and cleaned up code that uses `std::string_view` and it will be removed when it is not needed. We should convert the wks code to be more C++ and then remove this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@trafficserver.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org