Skip to content
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

Create separate evmc::hex library for hex encoding/decoding #575

Merged
merged 2 commits into from
Mar 22, 2021
Merged

Conversation

chfast
Copy link
Member

@chfast chfast commented Mar 15, 2021

No description provided.

lib/hex/hex.cpp Outdated Show resolved Hide resolved
@gumb0
Copy link
Member

gumb0 commented Mar 17, 2021

I'm reading intro to std::error_code at http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-4.html and I think public function const std::error_category& hex_category() is going to be needed, for the user to be able to check e.code().category() == evmc::hex_category().

include/evmc/hex.hpp Outdated Show resolved Hide resolved
for (auto it = hex_begin; it != hex.end(); ++it)
{
const auto h = *it;
if (std::isspace(h))
Copy link
Member

@gumb0 gumb0 Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm why do you want to allow whitespace? If this is to skip extra whitespace from command line, it's better to handle it in command line code.

Also currently it looks to allow "0x12" and " 12" (also "0x 12" and "1 2"), but not " 0x12"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is what I want for simplicity. This is useful for loading hex from files to get rid of line breaks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just hex.erase(std::remove_if(hex.begin(), hex.end()), std::isspace), hex.end()) them!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work with input iterators (planned change). In the end we can have hex_decoding_iterator and strip_whitespace_iterator but I think having just one is simpler.

lib/hex/hex.cpp Outdated
const std::error_category& hex_category() noexcept
{
// Create static category object. This involves mutex-protected dynamic initialization.
// Because of the C++ defect 253, the {} syntax is used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"valarray helper functions are almost entirely useless" ? http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#253

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chfast chfast merged commit dc14cf7 into master Mar 22, 2021
@chfast chfast deleted the hexlib branch March 22, 2021 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants