C++17 introduced std::string_view. It would be nice if OWLNext supported this type by defining owl::tstring_view as an alias for std::string_view or std::wstring_view, depending on the character set build mode (Unicode).
This type is a better fit for function signatures that need a string pointer and a size to be passed. Unfortunately, it is not universally applicable for replacing string pointer parameters, because it does not require null-termination. Hence, it cannot replace a single string pointer parameter which does not have an accompanying size parameter. Also, like std::string, initializing it with nullptr is undefined behaviour, so it cannot replace signatures, where the string pointer is allowed to be nullptr.
However, all functions that now have a string pointer plus a count as input parameters, such as TDC::ExtTextOut, should replace both by a single tstring_view parameter. With such a change a function will accept old-style string pointers as well as modern C++ string types. For example:
:::C++
auto TDC::ExtTextOut(const TPoint&, int options, const TRect*, const tstring_view&, const int* dx = 0);
const auto dc = TDC{};
const auto p = TPoint{};
const auto opt = int{};
const auto r = TRect{};
const auto v = tstring_view{};
const auto t = tstring{};
const auto ptr = LPCTSTR{};
const auto count = int{};
dc.ExtTextOut(p, opt, &r, v); // Trivial case, parameter type match.
dc.ExtTextOut(p, opt, &r, t); // Implicit conversion to tstring_view.
dc.ExtTextOut(p, opt, &r, _T("Hello")); // Implicit conversion to tstring_view.
dc.ExtTextOut(p, opt, &r, tstring_view{ptr, count}); // Explicit type.
dc.ExtTextOut(p, opt, &r, {ptr, count}); // Shorthand.
For current use of tstring in OWLNext, see Strings in OWLNext.
Bugs: #401
Feature Requests: #156
Feature Requests: #251
Feature Requests: #69
Wiki: OWLNext_Roadmap_and_Prereleases
Wiki: Strings_in_OWLNext
Anonymous
Support for std::string_view and std::wstring_view with the new type alias owl::tstring_view was added on the trunk in [r5004], and the support has been merged into Owlet [r5005].
Related
Commit: [r5004]
Commit: [r5005]
New owl::tstring_view is now used for TDC::GetTextExtentPoint32 [r5006] and TDC::GetGlyphIndices [r5010], with more usage to come.
Also see "Return owl::tstring or owl::tstring_view for functions currently returning LPCTSTR" [feature-requests:#69].
Related
Commit: [r5006]
Commit: [r5010]
Feature Requests: #69
Last edit: Vidar Hasfjord 2025-03-31
Related
Commit: [r7751]
Commit: [r7752]
Last edit: Vidar Hasfjord 2025-04-27