Skip to content
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

find function for substring matching #421

Closed
aman-godara opened this issue May 31, 2021 · 1 comment · Fixed by #433
Closed

find function for substring matching #421

aman-godara opened this issue May 31, 2021 · 1 comment · Fixed by #433
Labels
idea Proposition of an idea and opening an issue to discuss it

Comments

@aman-godara
Copy link
Member

Description

Signature: find(string, pattern, start(Optional) = 1, end(Optional) = len(string), occurrence(Optional) = 1, consider_overlapping(Optional)= .true.)

Output: an integer (index)

Returns the index at which occurrence'th occurrence of substring pattern is present in the input string string
between the index start and end, if not found returns 0.
consider_overlapping: comment #1 & comment #2

Prior Art

Fortran has an intrinsic function index (description) which does the same thing but has limited features.

PS: Some of the features proposed above may not be best to add to the stdlib at this moment, hence there is also a need to discuss the importance of these features. They are added in the issue to bring them into the discussion.

@aman-godara aman-godara added the idea Proposition of an idea and opening an issue to discuss it label May 31, 2021
@aman-godara
Copy link
Member Author

A higher level implementation of find function (based upon KMP algorithm) can be found here.

occurrence argument helps to find the nth occurrence the user is looking for. It also provides an option to consider_overlapping substrings or not while finding the nth occurrence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Proposition of an idea and opening an issue to discuss it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant