79 Commits

Author SHA1 Message Date
5675f8b139 string: add recoding from UTF-16 to UTF-32
I know there are system functions for this (and libiconv), but this is
so trivial and quick in our implementation.
2024-09-27 14:11:11 +02:00
da11495282 string: fix high&low UTF-16 surrogate detection
U+D800 is a perfectly valid high surrogate. (Thou, not normal.)
While U+DC00 is a perfectly valid low surrogate.
2024-09-27 14:09:05 +02:00
e65eb35cc2 Cleanup precompiler directives
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-08-21 13:32:58 +02:00
98e8756808 string: add ispunct
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-08-19 09:25:23 +02:00
5503a0c339 string: add 8 and 16-bit string to binary conversions
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-06-18 16:31:03 +02:00
5c5197d80d string: remove dead code
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-05-28 10:35:47 +02:00
5436dda7f6 assert: initial version
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-05-28 10:22:24 +02:00
ea2f129577 string: stop abusing logical | to load operands and test for zero
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>
2024-05-27 14:37:25 +02:00
c20d9dbc09 sgml: upgrade to support UTF-16 and 32
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>
2024-02-21 17:33:00 +01:00
ae8ce7f9f0 string: cleanup
Templates are inline by default.

Signed-off-by: Simon Rozman <simon@rozman.si>
2024-02-21 15:21:45 +01:00
0a719e3081 Xcode: turn on and resolve all warnings 2024-02-14 15:05:41 +01:00
0560c7bce9 Add missing UTF-8 BOM
This is required on Windows with default charset set to Windows-1252 or
another non-UTF-8 charset.

Signed-off-by: Simon Rozman <simon@rozman.si>
2024-02-14 12:33:29 +01:00
8ac0efa85d Xcode: resolve -Wsign-compare
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-02-14 12:28:39 +01:00
5b80f24830 string: fix vsnprintf on macOS
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>
2024-02-08 14:16:36 +01:00
08a18d1519 macOS support
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-02-08 12:09:33 +01:00
59a53e10f4 string: update documentation
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-01-11 09:09:46 +01:00
c5feba2ed0 string: add unit test for sprintf
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-01-09 19:31:07 +01:00
38c6b40b21 Bump Copyright year
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-01-06 10:55:09 +01:00
114609274f string: address Code Analysis warnings
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-01-05 22:45:41 +01:00
293da738b9 string: upgrade sprintf to write directly into std::string buffer
This removes extra memory allocation.

Signed-off-by: Simon Rozman <simon@rozman.si>
2024-01-05 20:32:00 +01:00
1685cd3283 string: fix sprintf
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-01-05 17:01:43 +01:00
fdf16a65b6 string: add is7bit
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-23 08:19:26 +01:00
e1f53f31ad string: add glyphrlen
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 21:36:21 +01:00
024f3f7172 string: add strncpy for fixed-size buffers
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:10 +01:00
61bf25ac6a string: switch from intptr_t to ptrdiff_t at strtoi()
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>
2023-12-22 14:17:10 +01:00
ba38dad49d string: add strrcmp and strrncmp
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:10 +01:00
088dd86d63 string: add strtod
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:09 +01:00
a5193c9738 string: remove excessive std::string_view helpers
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>
2023-12-22 14:17:09 +01:00
37891e8a2a Simplify and unify template parameter naming
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:08 +01:00
f5bce32d06 Use std::string_view where possible
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>
2023-12-22 14:17:08 +01:00
475f05b6d2 string: add strrchr and stricmp variants 2023-12-07 18:42:52 +01:00
72bab6d6b2 string: add strlwr variants 2023-12-07 12:27:38 +01:00
b15ab697c2 string: add strnlen variant for known fixed-size buffers 2023-12-07 12:25:35 +01:00
e17fa1d8c2 parser: detect spaces, characters and newline faster where appropriate
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>
2023-11-28 13:48:54 +01:00
d44aed2cff string: add "C" locale function variants
"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>
2023-11-18 09:57:38 +01:00
06da717405 string: upgrade vappendf and appendf to return number of chars appended
This comes handy when concatenating strings and calculating mappings.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-17 15:14:53 +01:00
10791467d8 string: add isblank
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-17 15:14:53 +01:00
3dfcaf3f10 string: add std_locale_C
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-17 15:14:53 +01:00
2c45749f78 string, locale: make stdex::locale(_t) independent .hpp file
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-09 08:12:31 +01:00
4fb684ce75 Cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-08 18:35:59 +01:00
9ff15a27a1 string: move uuidtostr to a separate .hpp
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>
2023-11-08 13:41:50 +01:00
fedeef0bea string: fix strncat SAL
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-06 11:57:47 +01:00
16a86cf350 Add #include wrapper to fix min/max <Windows.h> mess
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-18 12:51:49 +02:00
856be3a0d8 Revise #include to make each .hpp individually compilable
Mind that min/max Windows.h mess is Microsoft's problem, not ours.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-18 09:12:06 +02:00
11e56f927f string: add missing #include to support uuid_t on Windows
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-18 08:14:28 +02:00
983891ec41 string: add crlf2nl
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:09 +02:00
913cbc104a string: add strcmp
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:09 +02:00
8a6462a40c string: add uuidtostr
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:08 +02:00
ab8d37ee75 Turn assert() into _Analysis_assume_ on Release builds
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>
2023-10-10 16:43:07 +02:00
9ba4b21cef Un-static global data
Otherwise, compiler generates instances for each compilation unit.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00