-
Notifications
You must be signed in to change notification settings - Fork 246
Add strisdigit(), and use it instead of its pattern #1153
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
a349dfd
to
2433508
Compare
04c1c1b
to
e22bf37
Compare
e22bf37
to
d549476
Compare
2e14501
to
39e47ac
Compare
39e47ac
to
c8a5713
Compare
8b96932
to
edf0994
Compare
@hallyn , it would be interesting to get this one merged soon-ish. I have a decent number of patches that depend on this one, and that would reduce the amount of rebasing. Thanks! |
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.
If there are no precedents, I would prefer 'isalldigits' as the function name. Otherwise, feel free to merge.
There are precedents, indeed: https://codesearch.debian.net/search?q=%5Cbstrisdigit+*%5C%28&literal=0 There are no entries for isalldigits(). |
Oh well, a different search engine shows results for isAllDigits(): |
If you're worried about the name not being clear on if it means any characters or all characters, I have some APIs where a different meaning is wanted. This is the rule I developed for consistency: strisXXX() (string is XXX) means that all characters are of that class. strchrisXXX() (string character is XXX) means that any character is of that class. I've got these APIs in the oven at the moment:
Does this plan sound consistent and intuitive to you? |
Right, that's my concern. If you ask me "is '1xx' a digit", I would say yes, or ask for clarification. Because a digit is explicitly one [0-9].
In general it makes sense, but I'd still say the first should be strisdigits, just because of the definition of 'digit'. |
edf0994
to
7388c36
Compare
I'd say that a string character is a digit, but the string is not made up of digit characters. So, strchrisdigit() true, but strisdigit() false.
Hmmmm, I had that debate internally for a long time. I still haven't found an ideal name I like. I agree that strisdigits() seems better. But then I wanted something that can be consistent with strisprint() too. I'm not sure about calling it strisprints()... I considered straredigit(), but it sounds very weird. I could live with strallisdigit(). |
7388c36
to
b9e6bf2
Compare
Reviewed-by: Serge Hallyn <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
Note that the old code in (1) lib/strtoday.c:strtoday() (2) lib/subordinateio.c:append_uids() was considering an empty string as if it were a number. strisdigit() does not consider an empty string to be numeric. I think it will not affect the behavior in either case, as they should sooner or later result in an error somewhere. And it seems (IMO) surprising to treat empty strings as numeric strings, so let's not do it. Reviewed-by: Serge Hallyn <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
Please let me know your opinion. I slightly prefer strisdigit(), but something in my head says it's not a perfect name. |
Ok let's stick with what you have. |
Thanks! Another PR with several patches waiting after it is #1152, for when you can have a look at it. :) |
Revisions:
v2
v3
v4
v4b
v5
v5b
v5c
v5d
v5e
v5f
v6
v6b
v6c