| e8555c89 Andy McCall |
1 |
#ifndef STRING32_HH |
| 2 |
#define STRING32_HH |
| 3 |
|
| 4 |
#include "narrow.hh" |
| 5 |
#include <cassert> |
| 6 |
#include <cstdint> |
| 7 |
#include <type_traits> |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
using String32 = std::conditional_t< |
| 20 |
(sizeof(char*) > sizeof(uint32_t)), |
| 21 |
uint32_t, |
| 22 |
const char*>; |
| 23 |
|
| 24 |
|
| 25 |
constexpr void toString32(const char* buffer, const char* str, uint32_t& result) { |
| 26 |
assert(buffer <= str); |
| 27 |
result = narrow<uint32_t>(str - buffer); |
| 28 |
} |
| 29 |
constexpr void toString32(const char* , const char* str, const char*& result) { |
| 30 |
result = str; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
[[nodiscard]] constexpr const char* fromString32(const char* buffer, uint32_t str32) { |
| 35 |
return buffer + str32; |
| 36 |
} |
| 37 |
[[nodiscard]] constexpr const char* fromString32(const char* , const char* str32) { |
| 38 |
return str32; |
| 39 |
} |
| 40 |
|
| 41 |
#endif |