-
Notifications
You must be signed in to change notification settings - Fork 182
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
Extend stdlib_ascii module for handling character variables #310
Conversation
Thank you, I think it's mostly a good addition, and much needed functions. A few questions and comments:
|
One more question: Why do you need interface definitions in the module? |
From the discussion in #69 I concluded that there will be potentially both, a string type and a module for handling intrinsic character variables. For the former the |
I just saw your post in #69. I like Considering planning for a
|
Mainly because I was trying to overload the |
Maybe the implementation could be moved into the |
I like this solution also. |
- extend to_lower function to work on character strings - extend to_upper function to work on character strings - implement to_title function - implement reverse function
e17034b
to
6720abd
Compare
Moved the implementation to |
Thanks for fixing this. This was an initial blunder, the result of following the C routines to literally... The I adopted the naming I am still slightly confused by the logic in the |
I have to admit I was deliberately opening this pull request to start a discussion on the features mentioned in #69. I found a few additional caveats of the current
I'm fully trusting the compiler to be capable of inlining a pure function in the same module scope. I can inline them of course, which will require some code duplication, since I'm currently able to reuse |
With three functions, I agree it is cleaner this way. No need to inline. With
This is consistent with your proposed behavior, and honestly not a problem, once you are accustome to it. |
PR works fine for me. |
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.
Thank you for this PR. Here are some comments.
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 intent of the to_title
routine is clear to me now.
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 links to the specs in the source code should be added. But it could be done at the end of the review
Co-authored-by: Jeremie Vandenplas <[email protected]>
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.
I promoted the four public functions to elemental (it's free lunch) and added tests for elementalness.
I think it's good to go, thank you!
Thanks, I was planning to look into making most of the |
The issue of elemental vs pure for the character validation functions was already raised in the original issue: #11 (comment) If the procedures are made elemental, then the subroutine stdlib/src/tests/ascii/test_ascii.f90 Line 487 in a1c911c
|
I see, I wasn't aware of this. It's not free lunch after all. I see 3 options going forward (don't have to be resolved in this PR).
or similar. |
I reverted e670262, but left it in the history. We should certainly discuss this separately and implement whatever solution we find most suitable with a different patch. |
From my own experience, I have rarely resorted to using arrays of single characters. Therefore I am not strongly invested in making these procedures elemental. (After all the equivalent C routines are not elemental either...). On the other hand the usage case as procedure pointers is quite artificial. If one needs to switch between different operations, one could easily replace procedure pointers with a select case statement and an integer flag to perform the right operation. |
Elemental here would apply to multi-char strings as well (the test that I included did). It could be useful to pass output of the upcoming (F202X) |
I agree that for multi-char strings the elemental makes sense. 👍 If I might suggest a different generalization, the character validation functions (
|
What do you think? Are we ready to merge this PR? |
Yes, @jvdp1 please merge when ready. |
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.
Sorry for the delay. I corrected some minor typos in specs and added hyperlinks in the code.
I'll commit them and merge this PR after a last check.
All checks have passed! I'll merge it. thank you @awvwgk for this PR. |
This PR implements some character handling routines discussed in #69, but purposely does not put them into the
stdlib_string
namespace.There is one little caveat with this implementation due to a namespace collision with thestdlib_ascii
module, which might require reconsidering the naming of the functions implemented here.to_lower
function to work on character stringsto_upper
function to work on character stringsto_title
functionreverse
functionThe change in
stdlib_ascii
might be breaking ABI compatibility with the default branch.