Skip to content

Commit 0bcfaff

Browse files
Add char_traits<uint8_t>
1 parent 0b1ce31 commit 0bcfaff

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

Diff for: Release/include/cpprest/char_traits.h

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <cstdint>
2+
#include <cstring>
3+
#include <string>
4+
5+
namespace std
6+
{
7+
template<>
8+
struct char_traits<uint8_t>
9+
{
10+
using char_type = uint8_t;
11+
using int_type = int;
12+
using off_type = std::streamoff;
13+
using pos_type = std::streampos;
14+
using state_type = std::mbstate_t;
15+
16+
static void assign(char_type& c1, const char_type& c2) noexcept { c1 = c2; }
17+
18+
static bool eq(char_type c1, char_type c2) noexcept { return c1 == c2; }
19+
20+
static bool lt(char_type c1, char_type c2) noexcept { return c1 < c2; }
21+
22+
static int compare(const char_type* s1, const char_type* s2, std::size_t n) noexcept
23+
{
24+
return std::memcmp(s1, s2, n);
25+
}
26+
27+
static std::size_t length(const char_type* s) noexcept
28+
{
29+
const char_type* p = s;
30+
while (*p != 0)
31+
++p;
32+
return p - s;
33+
}
34+
35+
static const char_type* find(const char_type* s, std::size_t n, const char_type& a) noexcept
36+
{
37+
for (std::size_t i = 0; i < n; ++i)
38+
{
39+
if (eq(s[i], a))
40+
{
41+
return s + i;
42+
}
43+
}
44+
return nullptr;
45+
}
46+
47+
static char_type* move(char_type* s1, const char_type* s2, std::size_t n) noexcept
48+
{
49+
return static_cast<char_type*>(std::memmove(s1, s2, n));
50+
}
51+
52+
static char_type* copy(char_type* s1, const char_type* s2, std::size_t n) noexcept
53+
{
54+
return static_cast<char_type*>(std::memcpy(s1, s2, n));
55+
}
56+
57+
static char_type* assign(char_type* s, std::size_t n, char_type a) noexcept
58+
{
59+
std::fill_n(s, n, a);
60+
return s;
61+
}
62+
63+
static int_type not_eof(int_type c) noexcept { return c == eof() ? ~eof() : c; }
64+
65+
static char_type to_char_type(int_type c) noexcept { return static_cast<char_type>(c); }
66+
67+
static int_type to_int_type(char_type c) noexcept { return static_cast<int_type>(c); }
68+
69+
static bool eq_int_type(int_type c1, int_type c2) noexcept { return c1 == c2; }
70+
71+
static int_type eof() noexcept { return static_cast<int_type>(-1); }
72+
};
73+
} // namespace std

Diff for: Release/include/cpprest/streams.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef CASA_STREAMS_H
1616
#define CASA_STREAMS_H
1717

18+
#include "char_traits.h"
1819
#include "cpprest/astreambuf.h"
1920
#include <iosfwd>
2021
#include <cstdio>

0 commit comments

Comments
 (0)