- Notifications
You must be signed in to change notification settings - Fork148
Add substr_ macro#101
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
`strlen_(STRING)' gives the number of characters in STRING.
`substr_(STRING,POS,LEN)' gives the substring of STRING starting fromPOS and with the length of LEN.
tueda commentedApr 13, 2023
FYI: if your pull request is still incomplete and needs more work, then there is the "Draft" feature for pull requests in GitHub. Even if your work is in progress, creating a draft pull request to get others' feedback sometimes be beneficial (I have changed the status of this pull request to "Draft"). |
tueda commentedMar 15, 2024
Note: I found1d4b775 added Example: |
Although this may be a "feature creep" and I'm not sure whether many people find it useful or not, I would like to make a "Work in Progress" pull request, hoping this may stimulate other discussions.
As far as I know, there is no way/trick to extract a part of a string in FORM. So I experimentally implemented
substr_(STRING,POS,LEN)macro, which is more or lesssubstrof Perl and PHP but the first character is at POS=1. (Note that it is notsubstring_(STRING,FROM,TO)).POSandLENare somewhat extended to non-positive and negative integers, respectively. Especially,LEN=-1means the actual length ofSTRING.An application is defining a procedure with optional parameters:
which accepts
#call Proc1(x,expand=2)as well as#call Proc1(x),#call Proc1(x,expand)or#call Proc1(x,noexpand).This branch also contains an implementation of
strlen_(STRING), but it is not primitive in the sense that it can be implemented based onsubstr_:Other string operations like
strreplace_(STRING,OLD,NEW)can also be implemented based onsubstr_.