felixguendling / cista

Cista is a simple, high-performance, zero-copy C++ serialization & reflection library.
https://cista.rocks
MIT License
1.8k stars 116 forks source link

fix next_power_of_two and improve generic_string #220

Closed freshFruict closed 4 months ago

freshFruict commented 4 months ago

generic_string: add starts_with and ends_with functions

performs a simple way to check if a string has prefix/suffix add test cases for starts_with and ends_with

fix next_power_of_two function

fix wrong sizeof comparison for 64-bit integers add sizeof comparisons for 16 and 32-bit integers

felixguendling commented 4 months ago

Would it make sense to forward the starts_with and ends_with calls to std::string_view like this?

template <typename T> bool starts_with(T&& t) constexpr { return view().starts_with(t); }
template <typename T> bool ends_with(T&& t) constexpr { return view().ends_with(t); }

If there's an option to maintain less code and still provide the same value, I would prefer that.

Can you please run clang-format?

freshFruict commented 4 months ago

I've lessen code. As starts_with and ends_with were added in C++ 20, forwarding calls would break C++ 17 compatibility, so I didn't use them

felixguendling commented 4 months ago

/home/runner/work/cista/cista/test/string_test.cc:108: FATAL ERROR: test case CRASHED: SIGABRT - Abort (abnormal termination) signal

Can you please check? :)

Not breaking C++17 compat sounds like a good idea.