HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
byte_string.hpp
1// Copyright 2019 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include <cstddef>
7#include <string>
8#include <string_view>
9#include <cstring>
10
11namespace tt {
12
14public:
15 using char_type = std::byte;
16 using int_type = unsigned int;
20
21 static constexpr void assign(std::byte &r, std::byte const &a) noexcept {
22 r = a;
23 }
24
25 static constexpr bool eq(std::byte a, std::byte b) noexcept {
26 return static_cast<uint8_t>(a) == static_cast<uint8_t>(b);
27 }
28
29 static constexpr bool lt(std::byte a, std::byte b) noexcept {
30 return static_cast<uint8_t>(a) < static_cast<uint8_t>(b);
31 }
32
33 static std::byte *assign(std::byte *p, std::size_t count, char_type a) {
34 return reinterpret_cast<std::byte *>(std::memset(p, static_cast<uint8_t>(a), count));
35 }
36
37 static std::byte *move(std::byte *dest, std::byte const *src, size_t count) {
38 return reinterpret_cast<std::byte *>(std::memmove(dest, src, count));
39 }
40
41 static std::byte *copy(std::byte *dest, std::byte const *src, size_t count) {
42 return reinterpret_cast<std::byte *>(std::memcpy(dest, src, count));
43 }
44
45 static int compare(std::byte const *a, std::byte const *b, size_t count) {
46 return std::memcmp(a, b, count);
47 }
48
49 static size_t length(std::byte const *s) {
50 return std::strlen(reinterpret_cast<char const *>(s));
51 }
52
53 static std::byte const *find(std::byte const *s, size_t count, std::byte const &ch) {
54 return reinterpret_cast<std::byte const *>(std::memchr(reinterpret_cast<char const *>(s), static_cast<uint8_t>(ch), count));
55 }
56
57 static constexpr std::byte to_char_type(unsigned int c) noexcept {
58 return static_cast<std::byte>(c);
59 }
60
61 static constexpr unsigned int to_int_type(std::byte c) noexcept {
62 return static_cast<unsigned int>(c);
63 }
64
65 static constexpr bool eq_int_type(unsigned int c1, unsigned int c2) noexcept {
66 return c1 == c2;
67 }
68
69 static constexpr unsigned int eof() noexcept {
70 return 256;
71 }
72
73 static constexpr unsigned int not_eof(unsigned int e) noexcept {
74 return eq_int_type(e, eof()) ? 0 : e;
75 }
76};
77
79using bstring_view = std::basic_string_view<std::byte, byte_char_traits>;
80
81}
Definition byte_string.hpp:13
T memchr(T... args)
T memcmp(T... args)
T memcpy(T... args)
T memmove(T... args)
T memset(T... args)
T strlen(T... args)