Looks short and compact, but requires static_cast<unsigned int> to cover T1
and T2 of different signess. Which doesn't look all that nice anymore.
However, typecasting would only hide the warning. We want the warning to
occur, to encourage us to sync types on template invocation instead.
Signed-off-by: Simon Rozman <simon@rozman.si>
Windows and Apple (NSString) are using UTF-16 wchar_t. All others use
UTF-32. This eliminates need for additional conversion should we need
UTF-32 on Windows&Apple or UTF-16 on others. Mind, UTF-16↔32 is not a
trivial conversion as it may change number of code units.
Signed-off-by: Simon Rozman <simon@rozman.si>
vsnprintf_l and vswprintf_l mutate va_list parameter on some versions of macOS (11.7 Big Sur).
This makes it impossible to call printf multiple times with a growing buffer.
Signed-off-by: Simon Rozman <simon@rozman.si>
strtoi() is complementary to strtoui() returning size_t. But, intptr_t
is complementary to uintptr_t, and ptrdiff_t is complementary to size_t.
I know it doesn't matter on flat-memory platforms, but nevertheless, we
try to keep things organized in a portable way.
Signed-off-by: Simon Rozman <simon@rozman.si>
The standard C++ approach is preferred over legacy C-style string
operations. Some helpers have clean standard C++ implementation on
std::string(_view) classes. All were just a simple .data() and .size()
wrappers for legacy C functions.
The main concern is the amount of helpers that require maintenance.
Signed-off-by: Simon Rozman <simon@rozman.si>
Unfortunately, MSVC cannot deduce template parameters properly where
`const std::basic_string_view<...>` is the parameter. It requires
explicit type cast or explicit template type specification. Which kind
of voids the whole purpose of using std::basic_string_view to make the
client code simpler.
Example: https://gist.github.com/rozmansi/493911be70bdac08dc6826c976c5bbe4
Signed-off-by: Simon Rozman <simon@rozman.si>
No need to use locale-specific character type detection when ASCII.
Locale-specific implementation on Windows is not that very fast.
Signed-off-by: Simon Rozman <simon@rozman.si>
"C"-locale is basically ASCII while (Microsoft) implementation is not
quite performant to our likes. We can do faster.
Signed-off-by: Simon Rozman <simon@rozman.si>
It requires libuuid-devel on Linux and since this function is optional, lets
not impose libuuid-devel dependency on anything that #include
<stdex/string.hpp>.
Signed-off-by: Simon Rozman <simon@rozman.si>
While runtime asserts also served as MSVC Code Analysis hints, the lack
of asserts in Release builds provides no hints to Code Analysis which
rises a lot of warnings then.
Maybe I should learn how to use SAL to annotate <ptr, len> parameter
pairs to allow ptr==nullptr when and only when len==0? 😇
Signed-off-by: Simon Rozman <simon@rozman.si>