65 Commits

Author SHA1 Message Date
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
838dfabbda string: add trim
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:06 +02:00
82a16ef579 string: add strftime
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:06 +02:00
a888731c39 string: extend strupr
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:06 +02:00
02c531e2a8 string: fix strncpy and strncat buffer limit check
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:06 +02:00
d7a44c2929 string: add strncmp
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:06 +02:00
dcfc4752b5 stream: add stdex::sstring method variants 2023-09-20 12:09:58 +02:00
b5984ea8f2 Port to macOS
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-19 18:02:18 +02:00
bffb48c87d string: streamline C locale management across platforms
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-15 15:31:18 +02:00
66f8a6c3b7 Re-add UTF-8 BOM XCode is removing
Visual Studio IDE really needs it on non-UTF-8 PCs.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-14 09:13:04 +02:00
83d7fd844d Port to macOS
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-12 16:55:16 +02:00
5558bd6ccc string: add strchr, strstr and stristr
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-08 17:54:20 +02:00
0848056487 string: fix strnlen parameter validation assert
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-04 10:10:03 +02:00
e1f27662a1 string: streamline locale_t experience
Not that we would like to promote the use of C locale_t over C++
std::locale, but we need former for sprintf and we need decent support
for it.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-25 04:45:32 +02:00
fb48db73c1 string: add strdup and strndup
I know this is a step backward to C, but we need this in AJT for
backward compatibility.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-24 14:07:28 +02:00