-
-
Notifications
You must be signed in to change notification settings - Fork 741
Add Informative Example to canEncode #4153
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
|
||
// avoid auto-decoding overhead | ||
foreach (item; s.representation) | ||
if (!isASCII(item)) |
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.
return s.representation.find!(x => !isASCII(x)).empty
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.
or return s.representation.all!isASCII();
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.
Yes, @JackStouffer move to return s.representation.all!isASCII();
. This will create less template bloat
Truth be told it's a hard sell:
|
@@ -25,12 +25,12 @@ | |||
+/ | |||
module std.ascii; | |||
|
|||
import std.traits; // : functionAttributes, FunctionAttribute, isSafe, isSomeString; |
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.
The bug is fixed now
374a403
to
fb81279
Compare
@DmitryOlshansky There were two separate bugs for this and a forum thread, so I think the demand is high enough for this. Fixed other issues. @9il The bug is only deprecated, imports will still be public if you use global selective imports. From the change log:
|
61d748a
to
248a1e3
Compare
LGTM then |
@@ -6854,3 +6855,34 @@ pure unittest | |||
} | |||
} | |||
|
|||
/** | |||
* Test if all of the characters in the array are in the ASCII set. |
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.
Probably use the string
instead of the array
@DmitryOlshansky fixed |
And I recall @andralex wants vet all name additions to the library. |
I guess something more useful would be |
Hmm, my thoughts
|
I'm not too thrilled about the utility of a one liner. It would be ok if it was a loop, but it's not. It's longer for the use to read the documentation than just write the one liner. Phobos should not be a repository of one liners. Masses of one liner functions tend to hide the meatier functions. Phobos should make it possible for users to write one liners to get their work done. |
I changed the function to a helper overload of |
0138d52
to
9de9094
Compare
That seems better. @WalterBright? |
Yes, it is better. But I would rather see the one liner simply as an example in the documentation for canEncode(). It is better to teach people how to put lego blocks together than to provide trivial combinations of two lego blocks, or 3 lego blocks. It's the same reason there isn't a function to multiply x by 2. My other complaint is the code:
is wrong. It should be:
The fact that nobody noticed this error suggests that we need more examples in the documentation on how to do these sorts of things. I would love to see more one liners like this as examples. |
Seems reasonable. |
9de9094
to
c80419b
Compare
Changed to example. Perhaps 11356 should be marked WONTFIX? |
Auto-merge toggled on |
Thank you. Looks good!
Good idea. Done. |
Thanks! |
Great. Thanks folks! |
I need this for my date string parsing library.