GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
base16.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_CORE_FORMATS_BASE16_HPP
5#define GREM_CORE_FORMATS_BASE16_HPP
6
8
13
14namespace grem::base16 {
15
24[[nodiscard]] constexpr bool isHexadecimalDigit(char ch) noexcept {
25 return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f');
26}
27
37[[nodiscard]] constexpr Optional<int> getHexadecimalDigitValue(char ch) noexcept {
38 if (ch >= '0' && ch <= '9') {
39 return ch - '0';
40 }
41 if (ch >= 'A' && ch <= 'F') {
42 return 10 + ch - 'A';
43 }
44 if (ch >= 'a' && ch <= 'f') {
45 return 10 + ch - 'a';
46 }
47 return {};
48}
49
61GREM_API(core) String encodeLowercase(StringView data);
62
74GREM_API(core) String encodeUppercase(StringView data);
75
90GREM_API(core) String decode(StringView string);
91
92} // namespace grem::base16
93
94#endif
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Definition aliases.hpp:11
String decode(StringView string)
Decode the original data from a lowercase or uppercase hexadecimal Base16 string.
String encodeLowercase(StringView data)
Encode arbitrary data into a lowercase hexadecimal Base16 string.
String encodeUppercase(StringView data)
Encode arbitrary data into an uppercase hexadecimal Base16 string.
constexpr Optional< int > getHexadecimalDigitValue(char ch) noexcept
Get the hexadecimal digit value of a Base16 character.
Definition base16.hpp:37
constexpr bool isHexadecimalDigit(char ch) noexcept
Check if a character value represents a valid hexadecimal Base16 character (ASCII values '0'-'9',...
Definition base16.hpp:24
StringBase< char, std::char_traits< char >, std::allocator< char > > String
Definition String.hpp:17
StringViewBase< char, std::char_traits< char > > StringView
Definition StringView.hpp:16