Commit Graph

126 Commits

Author SHA1 Message Date
Martchus d31092b7d9 Apply clang-format 2024-04-08 12:33:57 +02:00
Martchus 909346c199 Fix reserving size for error message in `charToDigit()` 2024-02-27 02:16:52 +01:00
Martchus c9cd44ceee Apply clang-format 2024-02-22 19:41:29 +01:00
Martchus d8e144d312 Optimize `numberToString()`
This function is slower than it needs to be due to the expensive inserts at
the front of the string. The new version is 38 times faster for a 9-digit
number using GCC 13.2 with full optimizations according to Quick Bench.
2024-02-21 21:21:11 +01:00
Martchus a2f9748c1a Apply clang-format 2023-11-14 00:01:27 +01:00
Martchus 035a448da0 Avoid clazy warning about `decodeBase64`
The warning is about invalid memory usage within the loop in
case `strSize` is zero. It is supposedly not correct because
then the loop would never be entered anyways in that case.
However, it is likely nevertheless a good idea to silence the
warning.
2023-09-01 17:21:18 +02:00
Martchus 8d28ab70b3 Use `std::` consistently in `decodeBase64` 2023-09-01 17:18:39 +02:00
Martchus 9191117120 Fix binary conversion functions for big endian systems
The code was broken on big endian systems by
07e9546855. When doing an explicit swap
one must distinguish the endianness the code runs on.
2023-06-20 14:03:36 +02:00
Martchus dd95310c73 Suppress warning about implicit sign conversions
The conversion from unsigned int to int should be ok here.
2023-06-10 18:14:06 +02:00
Martchus 0341316b4b Fix warning from MSVC about data loss 2023-05-10 22:06:59 +02:00
Martchus 07e9546855 Avoid relying on compiler optimizations for binary conversions
* Add/update binary conversion functions to use `std::memcopy`
* Only GCC could actually optimize the custom code using bit operations
    * Clang could only optimize the `getBytes()` functions
    * MSVC could not optimize any of the functions
* The to…Int…() functions cannot be updated as they are `constexpr` (and
  thus `std::memcopy` and `reinterpret_cast` cannot be used). So they stay
  as-is and `toInt()` has been added instead
* The `BinaryReader` class has been updated to use the new `toInt()`
  function
2023-02-05 21:29:22 +01:00
Martchus 31f369d051 Add signed versions of `swapOrder()` functions 2023-02-05 21:20:53 +01:00
Martchus 3b2615fa62 Move `BE`/`LE` namespaces to the end so these functions can use previous helpers 2023-02-05 20:17:32 +01:00
Martchus b3fd365502 Use `std::byteswap()` when compiling in C++23 mode 2023-02-05 20:15:29 +01:00
Martchus 8588c17df3 Remove wrong includes in `binaryconversionprivate.h`
This header is not meant to be self-contained and must not include any
other headers.
2023-02-05 19:57:36 +01:00
Martchus 7d6fc9721a Apply clang-format/cmake-format 2023-02-03 13:31:18 +01:00
Martchus be6626f6a6 Fix using percentage operators of `stringbuilder.h` with MSVC 2023-02-01 00:43:53 +01:00
Martchus 25e4eebb64 Avoid MSVC warning about possible overflow 2023-01-31 22:37:06 +01:00
Martchus 4d96a82ed9 Workaround unfortunate macro definition in `windows.h` 2023-01-31 22:37:06 +01:00
Martchus d4fbe5f43d Use `std::` consistently in `convertMultiByteToWide()` 2023-01-26 22:20:59 +01:00
Martchus 16f17fb9de Make feature detection for thead local work with MSVC 2023-01-26 22:20:20 +01:00
Martchus d8c38699ba Avoid warning about unqualified std cast 2022-11-04 16:50:13 +01:00
Martchus 639018285d Fix typos 2022-06-26 11:48:44 +02:00
Martchus 052f8d2bd2 Add helper to make native path from internal representaton 2022-03-17 22:31:11 +01:00
Martchus 203679bf32 Document that delimiter for splitString*() must not be empty 2021-07-24 23:38:12 +02:00
Martchus b3ebe5ce38 Fix typos found via `codespell --skip .git -w` 2021-07-03 19:07:49 +02:00
Martchus 2e93882882 Reduce redundant code in stringconversion.h 2021-05-24 19:51:49 +02:00
Martchus 3afed30760 Detect overflow in functions to convert strings to numbers
Otherwise these functions can strictly run into undefined behavior which
should be prevented.
2021-05-24 19:51:49 +02:00
Martchus d5e35e460c Fix a few details in string conversion functions 2021-05-23 19:20:45 +02:00
Martchus 63955ffcc5 Avoid including ranges header under reflective-rapidjson's generator
This works around errors which Clang 11.1.0 has when parsing this header
from GCC 11.1.0. (Yes, at this point the GCC and Clang versions which are
currently in Arch Linux testing are identical.)
2021-05-16 19:21:58 +02:00
Martchus 6d5045c2b1 Port away from deprecated WriteCompilerDetectionHeader module 2021-05-13 15:49:53 +02:00
Martchus f549285fde Fix splitString()/splitStringSimple() for case of empty trailing part 2021-05-11 16:42:28 +02:00
Martchus b43de126b9 Retain source compatibility of numberToString()/stringToNumber()
IntegralType and BaseType need to be kept different types, otherwise one
runs into deduction errors if both arguments have different types (which is
quite likely in practise). Since the base is always a small positive
integer the cast should always be safe.
2021-03-22 13:45:16 +01:00
Martchus a30ba0c147 Ensure still the right stringToNumber() overload is called for char arrays 2021-03-22 12:13:20 +01:00
Martchus 42132719e5 Remove comments about std::expected (which didn't even make it into C++20) 2021-03-22 12:12:11 +01:00
Martchus 8c033ca243 Fix warnings 2021-03-20 21:56:45 +01:00
Martchus 3c8eb5a333 Apply clang-format 2021-03-05 23:14:54 +01:00
Martchus cc63c8c250 Improve parameter-passing in some string conversion functions
* Allow using a range as input of joinStrings()
* Use `std::string_view` instead of `const std::string &` to pass read-only
  parameters to joinStrings() and splitString*() to avoid constructing an
  `std::string` from `const char *` parameters
* Use auto for return types of toMultiline() and toArrayOfLines()
* Does not affect BC because those are template functions
* Should not affect source compatibility; at least uses in my main projects
  seem to be unaffected
2021-03-05 23:01:30 +01:00
Martchus 6968716d5c Avoid using substr in splitString()/splitStringSimple() 2021-02-23 20:54:04 +01:00
Martchus 27e9761f63 Adjust conditions for C++20 for g++ 2021-02-09 00:22:20 +01:00
Martchus c61a1784ec Allow using splitStringSimple() with `std::unordered_set` in C++20
* So one could use e.g. `std::unordered_set<std::string_view>` as target
  container when splitting an `std::string_view`.
* Still an experimental feature
2021-02-09 00:21:53 +01:00
Martchus 70f827c78e Apply clang-format 2020-11-25 17:53:28 +01:00
Martchus a26f3d7e1a Avoid instantiating an std::string for find and replace parameters
This overloads should allow passing an std::string_view or C-string to
findAndReplace() without instantiating an std::string.
2020-09-19 15:40:32 +02:00
Martchus b363498f53 Allow specifying return type in joinStrings()
for joining an std::string from an std::vector<std::string_view>.
2020-07-25 22:53:46 +02:00
Martchus bf8e0db87f Construct tuple in in string builder directly 2020-03-02 18:23:38 +01:00
Martchus 8744cf95ef Ensure no copy is made when using argsToString()
It seems that std::make_tuple() is using __decay_and_strip so
the arguments get copied. Using the std::tuple c'tor directly
instead.

When using the %-operator it is already taken care that strings
are stored as pointers and not by value.
2020-02-18 19:29:23 +01:00
Martchus 1154ed4d1c Improve exception messages of NativeFileStream
So one gets e.g. "open failed: Permission denied" instead of
just "open failed: iostream error".
2020-02-14 17:13:05 +01:00
Martchus 7204bc6f06 Support using string builder with types convertible to target string type
So e.g. std::filesystem::path can be used to build an std::string.
2020-02-13 17:05:46 +01:00
Martchus a5283535cc Support nested tuples in string builder
This is useful to concatenate previously constructed sub
strings passed around as tuples.
2020-01-26 19:02:22 +01:00
Martchus 7376a2bb9b Support string builder operator '+' for std::string_view 2019-11-28 23:10:16 +01:00