345 Commits

Author SHA1 Message Date
e1f53f31ad string: add glyphrlen
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 21:36:21 +01:00
9c9fd9d05a math: add muldiv
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 21:35:56 +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
09b59e698d Refactor
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:09 +01:00
c212e68bb5 debug: add
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:09 +01:00
088dd86d63 string: add strtod
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:09 +01:00
441a2ae9d5 compat: add _Verify_
This eases porting of legacy code.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:09 +01:00
2020fa2eec locale: add UTF8 and ACP/OCP locales
Those are frequently used:

- UTF8: for exception message formatting
- ACP(OCP): for generic (console) output

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
da9dcc9c1a parser: move virtual match() to do_match() and provide frontend
This allows to call match() method equally by using char T* or
std::basic_string_view<T>.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:08 +01:00
bce104d97b locale: redesign locale to behave like locale_t on demand
This avoids painful `.get()` in every `stdex::sprintf()` call. We could
use C++ polymorphism to add other sprintf variants, but the argument
combinations would explode.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:08 +01:00
2610547137 Cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-21 09:21:32 +01:00
2e65d0351c Trim excessive inline
Methods and templates are implicitly marked as inline already.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-11 11:33:27 +01:00
7eba65813e stream: fix cache::read() to return state_t::eof correctly
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-11 09:55:20 +01:00
91ffe3f633 wav: cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-08 18:53:08 +01:00
bdd76b302d wav: fix cue loading
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-08 18:53:07 +01:00
6fc378ff61 idrec: fix reading from limited streams
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-08 18:53:04 +01:00
0ec86f6161 idrec: cleanup 2023-12-08 18:47:05 +01:00
d5bf60447b Cleanup 2023-12-08 16:22:09 +01:00
bb9988933e unicode: add unit test for normalize
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-08 14:21:52 +01:00
6d1d9bd1b8 sgml: fix unit tests 2023-12-08 14:21:20 +01:00
5d7e44a3cd parser: address Code Analysis warning
Nice catch: when calling with basic_bol::match(nullptr, 5, 5), the
method addresses null[4].

Turned this condition into debug assert, as (nullptr, 5, 5) is invalid
input parameter combination.
2023-12-08 14:20:56 +01:00
8ba5a06379 parser: update SAL
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-08 14:03:26 +01:00
5215d5e6dc unicode: add normalize
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-07 18:43:14 +01:00
475f05b6d2 string: add strrchr and stricmp variants 2023-12-07 18:42:52 +01:00
2440e5baca Cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-07 18:41:55 +01:00
72bab6d6b2 string: add strlwr variants 2023-12-07 12:27:38 +01:00
0d3785850b html: add (un)escaping function variants 2023-12-07 12:26:41 +01:00
b15ab697c2 string: add strnlen variant for known fixed-size buffers 2023-12-07 12:25:35 +01:00
8fc9a7e56b stream: allow invalid handle detection in cached_file
Otherwise one cannot distinguish between file open but in failed state
and file not open.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-06 15:25:48 +01:00
9967b41eae stream: make memory_file properly copyable and movable
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-06 11:02:12 +01:00
5a4194c9ba wav: add 2023-12-01 19:06:20 +01:00
c69b79c0f2 idrec: cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-01 19:06:10 +01:00
976662415b stream: unify size method and make it const
diag_file::size() was setting the m_state and returning 0 on error,
which violated original size() convention not to change stream state and
to return fsize_max on error.

Changing m_state prevented declaring size() method as const before.

cache::seek() was missing size() return value check.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-01 14:11:02 +01:00
8fbbf58a1b system: update documentation
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-01 14:05:54 +01:00
571463b22c html: fix parser to handle empty documents
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-29 12:04:17 +01:00
14e6bec509 parser: fix basic_eol
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-29 11:32:28 +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
7685818bf7 parser: HTTP spaces are always ASCII
No need to use "C" locale, which implementation on Windows is not that
very fast.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-28 13:38:20 +01:00
d9e04170ac unicode: extend charset_from_name
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-28 13:36:42 +01:00
97014df244 html: fix localizable attribute mapping
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-28 12:14:37 +01:00
b824c204a6 parser: fix IPv6 detection
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-19 12:11: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
dff646a4f8 README: add link to auto-generated documentation
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-17 15:18:06 +01:00
87c41c0947 html: add simple tokenizer and parser
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-17 15:14:54 +01:00
424f297c7b sgml: sgml2wstr→sgml2str, wstr2sgml→str2sgml 🧨
This is analogous to string.hpp's strlen, strcpy, strcat, which use C++
polymorphism rather than function name decorations for char/wchar_t
flavors.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-17 15:14:53 +01:00