-
-
Notifications
You must be signed in to change notification settings - Fork 740
added hexString() and hexBytes() functions #3058
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
Conversation
I'd perhaps add a template constraint to static bool isHex(T)(in T hexData) if (isSomeString!T) and shouldn't this go in |
std.ascii already has |
return false; | ||
i += isH; | ||
} | ||
return !(i & 1) & (i > 0); |
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.
What is the purpose of this? It already returns early if it's not a hex literal.
edit:
Nevermind, I see now it's not that simple. I still think the code is seriously confusing. bool
is not supposed to be treated like an 8-bit integer.
the last return statement is not about |
I like the compile-time templates, but I don't think we should commit to the runtime functions yet. They're pretty inefficient and are hard-coded to using the GC. If we make them public, it's only a matter of time before someone complains that they don't accept ranges, don't accept an output range, aren't |
The idea is to use the same private template for the compile time and run time versions. I wait for more comments about this. The initial idea of Walter is to replace a single feature, but i recognize that i've been a bit overzealous in the commit. |
And I'm fine with that, but I think making the runtime functions public is a mistake, as they are too specific. |
$(D wchar) or $(D dchar). | ||
*/ | ||
@property @safe nothrow pure | ||
auto hexString(string hexData, C = char)() |
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.
These should be value templates, not function templates:
template hexString(string hexData, C = char)
if (hexData.isHexLiteral && isSomeChar!C)
{
immutable hexString = hexStrImpl!C(hexData);
}
as the result of hexStrImpl
The function $(D isHexLiteral) checks the consistency of a string for the | ||
functions $(D hexString) and $(D hexBytes). | ||
The result is only true if the input string is composed of ASCII white | ||
characters (\f\n\r\t\v) or hexadecimal digits (regarless of the case). |
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.
regardless
+ added ddoc example for isHexLiteral
Why was this closed? |
It seems like @bbasile has deleted his fork of Phobos. |
Seems a shame. Looks like I'll adopt and resurrect it myself. |
I've deleted the source fork because i forgot to create a brach for the patch. Later i didnt re-fork it because i thought the initial PR would fall into a black hole. |
as suggested by W.B in http://forum.dlang.org/thread/me4njq$1cul$1@digitalmars.com