Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

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

Merged
chfast merged 2 commits intomasterfrom
hexlib
Mar 22, 2021
Merged

Create separate evmc::hex library for hex encoding/decoding#575
chfast merged 2 commits intomasterfrom
hexlib

Conversation

@chfast
Copy link
Copy Markdown
Member

@chfast chfast commented Mar 15, 2021

No description provided.

@gumb0
Copy link
Copy Markdown
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().

for (auto it = hex_begin; it != hex.end(); ++it)
{
const auto h = *it;
if (std::isspace(h))
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants