-
Notifications
You must be signed in to change notification settings - Fork 168
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 logical functions to character strings #321
Comments
It may be interesting to apply the is_blank function to delete multiple white spaces in character strings, e.g, change the string
by
Could this composite functionality be contained in a standard library? |
@aslozada , thanks for the suggestion. I think the functionality you are interested could be done with a combintation of I never realized that Effectively the functions you are proposing are just specializations of the intrinsic I might be mistaken, but I believe that within the limits of standard Fortran there is no way to replicate the Would it be possible to auto-generate these procedures? Maintaining them manually seems very tedious. Edit: Sometimes I long for the (obsolescent) Fortran 77 statement functions. Then one could easily implement
could return some sort of of lambda expression or procedure pointer equivalent. It could save some interface typing... |
Basically, yes, but I would implement them by iterating over the string using the corresponding
You are right, there is currently no way to replicate this functionality with Fortran. I would vote for ignoring it as well. |
Thanks, @ivan-pi, the idea is to delete extra blank spaces in a character string. I have read about mixing procedures to perform this task, but my comment and question is about the use of a is_blank extension to obtain the same result, and if such a procedure can be considered as a functionality of a standard library. |
@aslozada Proposing a function like |
Indeed this implementation has the lowest memory footprint. For the
I would guess that internally the |
I recall there was a similar development precedent in the actual Fortran standard, where the |
Please correct me if I understood it wrong.
Shouldn't we say that when |
I believe the any/all analogy in the original post is actually the opposite way round. From the description of the intrinsic routines:
The intrinsic The intrinsic |
Yeah, I actually deleted my last comment because I realised that I interpreted them wrong and also posted a new one. I agree with what you have said.
I want to make it clearer for me that when |
No, it implies the opposite. When |
At least for the most common charater sequences (letters and digits) we already provide the constants (
For comprehension I think a name like |
Currently most routines provided by
stdlib_ascii
are only applicable to single characters. The conversion (to_lower
andto_upper
) routines were straight-forward to extend to character strings (see #310). For the logical functions it is a bit more complicated.For each of the logical functions (
is_ascii
, ...) two possible reductions apply:any
andall
. To follow the Fortran naming of theverify
andscan
intrinsic` one could implement three versions for each logical function:is_ascii
verify_ascii
(empty string returns.false.
)scan_ascii
(empty string returns.true.
)Alternatively, to be more in line with the
verify
andscan
function, the index of the first matching character could be returned, which makes it easy to create the respective logical by a simple comparison.The text was updated successfully, but these errors were encountered: