-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add char_traits<uint8_t> #1820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
placintaalexandru
wants to merge
1
commit into
microsoft:master
Choose a base branch
from
placintaalexandru:fix/Build-on-recent-libc++
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+75
−0
Open
Add char_traits<uint8_t> #1820
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,74 @@ | ||||||||||
#include <cstdint> | ||||||||||
#include <cstring> | ||||||||||
#include <string> | ||||||||||
|
||||||||||
namespace std | ||||||||||
{ | ||||||||||
template<> | ||||||||||
struct char_traits<uint8_t> | ||||||||||
{ | ||||||||||
using char_type = uint8_t; | ||||||||||
using int_type = unsigned int; | ||||||||||
using off_type = std::streamoff; | ||||||||||
using pos_type = std::streampos; | ||||||||||
using state_type = std::mbstate_t; | ||||||||||
|
||||||||||
static void assign(char_type& c1, const char_type& c2) noexcept { c1 = c2; } | ||||||||||
|
||||||||||
static bool eq(char_type c1, char_type c2) noexcept { return c1 == c2; } | ||||||||||
|
||||||||||
static bool lt(char_type c1, char_type c2) noexcept { return c1 < c2; } | ||||||||||
|
||||||||||
static int compare(const char_type* s1, const char_type* s2, std::size_t n) noexcept | ||||||||||
{ | ||||||||||
return std::memcmp(s1, s2, n); | ||||||||||
} | ||||||||||
|
||||||||||
static std::size_t length(const char_type* s) noexcept | ||||||||||
{ | ||||||||||
const char_type* p = s; | ||||||||||
while (*p != 0) | ||||||||||
++p; | ||||||||||
return p - s; | ||||||||||
} | ||||||||||
|
||||||||||
static const char_type* find(const char_type* s, std::size_t n, const char_type& a) noexcept | ||||||||||
{ | ||||||||||
for (std::size_t i = 0; i < n; ++i) | ||||||||||
{ | ||||||||||
if (eq(s[i], a)) | ||||||||||
{ | ||||||||||
return s + i; | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
return nullptr; | ||||||||||
} | ||||||||||
|
||||||||||
static char_type* move(char_type* s1, const char_type* s2, std::size_t n) noexcept | ||||||||||
{ | ||||||||||
return static_cast<char_type*>(std::memmove(s1, s2, n)); | ||||||||||
} | ||||||||||
|
||||||||||
static char_type* copy(char_type* s1, const char_type* s2, std::size_t n) noexcept | ||||||||||
{ | ||||||||||
return static_cast<char_type*>(std::memcpy(s1, s2, n)); | ||||||||||
} | ||||||||||
|
||||||||||
static char_type* assign(char_type* s, std::size_t n, char_type a) noexcept | ||||||||||
{ | ||||||||||
std::fill_n(s, n, a); | ||||||||||
return s; | ||||||||||
} | ||||||||||
|
||||||||||
static int_type not_eof(int_type c) noexcept { return c == eof() ? ~eof() : c; } | ||||||||||
|
||||||||||
static char_type to_char_type(int_type c) noexcept { return static_cast<char_type>(c); } | ||||||||||
|
||||||||||
static int_type to_int_type(char_type c) noexcept { return static_cast<int_type>(c); } | ||||||||||
|
||||||||||
static bool eq_int_type(int_type c1, int_type c2) noexcept { return c1 == c2; } | ||||||||||
|
||||||||||
static int_type eof() noexcept { return static_cast<int_type>(-1); } | ||||||||||
}; | ||||||||||
} // namespace std | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.