Closed rept1d closed 9 months ago
Name | Link |
---|---|
Latest commit | 64c2b72dfb4afcd6f688ec59f75dbed29821e1f1 |
Latest deploy log | https://app.netlify.com/sites/dpp-dev/deploys/6581dd432dc51700082b40f5 |
Deploy Preview | https://deploy-preview-1045--dpp-dev.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
This PR solves the following problems:
dpp::utf8substr
is just broken:dpp::utf8substr("abcdefg", 2, 2)
returns"cdef"
. Probably unnoticed due to very limited variety of usage scenarios.dpp::utf8substr
anddpp::utf8len
claim to have a specific result (empty string or zero, respectively) if the supplied string is not a valid UTF-8 sequence. In reality though, not only do they not verify if the string is valid UTF-8, they actually invoke UB for some inputs (e.g.dpp::utf8len("\xC0\xC0")
) due to reading past the end of the string.goto
, defining lots of variables in one line etc.)std::string
's and notstd::string_view
s. In particular,dp::utf8substr
returns a newstd::string
, which causes allocations and copies that could be avoided in some cases.What I did:
utf8subview
which returnsstd::string_view
instead ofstd::string
, and made use of it in several places across the code base, where applicable.const std::string&
withstd::string_view
in parameter declarations of these functions.std::string::size_type
withsize_t
in parameter declarations of these functions because IMO it only makes everything unnecessarily verbose, especially if we assume thatstd::string::size_type
might be different fromstd::string_view::size_type
. It's almost never used in other places anyway, so why bother in this one in particular?std::string_view
s are not guaranteed to be null-terminated.Code change checklist