Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
tueda wants to merge2 commits intoform-dev:master
base:master
Choose a base branch
Loading
fromtueda:dev-substr
Draft

Add substr_ macro#101

tueda wants to merge2 commits intoform-dev:masterfromtueda:dev-substr

Conversation

@tueda
Copy link
Collaborator

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 implementedsubstr_(STRING,POS,LEN) macro, which is more or lesssubstr of Perl and PHP but the first character is at POS=1. (Note that it is notsubstring_(STRING,FROM,TO)).POS andLEN are somewhat extended to non-positive and negative integers, respectively. Especially,LEN=-1 means the actual length ofSTRING.

An application is defining a procedure with optional parameters:

#procedure Proc1(x,?opts)  #define expand "-1"  #do opt={`?opts'}    #ifdef `opt'      #switch `opt'        #case expand          #redefine expand "0"          #break        #case noexpand          #redefine expand "-1"          #break        #default          #if "`substr_(`opt',1,7)'" == "expand="            #redefine expand "`substr_(`opt',8,-1)'"          #else            #message Error: illegal option of Proc1: `opt'            #terminate          #endif          #break      #endswitch    #endif  #enddo  #message x=`x'  #message expand=`expand'#endprocedure

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 ofstrlen_(STRING), but it is not primitive in the sense that it can be implemented based onsubstr_:

#procedure StrLen(?str,dest)  #redefine `dest' "0"  #do loop=1,1    #if "`substr_(`?str',1,``dest'')'" != "`?str'"      #redefine `dest' "{``dest''+1}"      #redefine loop "0"    #endif  #enddo#endprocedure#define n ""#call StrLen(12345,n)

Other string operations likestrreplace_(STRING,OLD,NEW) can also be implemented based onsubstr_.

`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.
@tuedatueda marked this pull request as draftApril 13, 2023 01:11
@tueda
Copy link
CollaboratorAuthor

FYI: if your pull request is still incomplete and needs more work, then there is the "Draft" feature for pull requests in GitHub.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request

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").

@tuedatueda changed the title[WIP] Add substr_ macroAdd substr_ macroMar 11, 2024
@tueda
Copy link
CollaboratorAuthor

Note: I found1d4b775 addedtakeleft_,takeright_,keepleft_ andkeepright_.

Example:

#message `takeleft_(abcdefg,2)'#message `takeright_(abcdefg,2)'#message `keepleft_(abcdefg,2)'#message `keepright_(abcdefg,2)'.end
    #message `takeleft_(abcdefg,2)'~~~cdefg    #message `takeright_(abcdefg,2)'~~~abcde    #message `keepleft_(abcdefg,2)'~~~ab    #message `keepright_(abcdefg,2)'~~~fg

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@tueda

[8]ページ先頭

©2009-2025 Movatter.jp