CHANGESTR.REX: Difference between revisions

Content added Content deleted
m (→‎the CHANGESTR source: changed a comment to reflect its IF statement.)
m (→‎the CHANGESTR source: changed some comments (to align better for perusing).)
Line 30: Line 30:
╚═════════════════════════════╝ │ │ │ │ │ │ ╚═══════════════════════════╝
╚═════════════════════════════╝ │ │ │ │ │ │ ╚═══════════════════════════╝
↓ ↓ ↓ ↓ ↓ ↓ */
↓ ↓ ↓ ↓ ↓ ↓ */
changestr: parse arg o,h,n,t,b,p, ,$ f /*T, B, P are optional. */
changestr: parse arg o,h,n,t,b,p, ,$ f /* ◄────────────────────┐*/
/*T, B, P are optional ►─┘*/
t=word(t 999999999, 1) /*maybe use the default? */
t=word(t 999999999, 1) /*maybe use the default? */
b=word(b 1 , 1) /* " " " " */
b=word(b 1 , 1) /* " " " " */
Line 38: Line 39:
if \datatype(t, 'W') then signal syntax /*4th arg not an integer. */
if \datatype(t, 'W') then signal syntax /*4th arg not an integer. */
if \datatype(b, 'W') then signal syntax /*5th " " " " */
if \datatype(b, 'W') then signal syntax /*5th " " " " */
if \datatype(p, 'W') then signal syntax /*6th arg " " " */
if \datatype(p, 'W') then signal syntax /*6th " " " " */
if t<0 then signal syntax /*4th arg " non-negative*/
if t<0 then signal syntax /*4th " " non-negative.*/
if b<1 then signal syntax /*5th arg " positive. */
if b<1 then signal syntax /*5th " " positive. */
if p<1 then signal syntax /*6th " " " */
if p<1 then signal syntax /*6th " " " */
L=length(o) /*length of OLD string. */
L=length(o) /*length of OLD string. */
if L==0 & t\=0 then return n || h /*changing a null char? */
if L==0 & t\=0 then return n || h /*changing a [null] char? */
if p\=1 then do /*if P ¬= 1, adjust F & H.*/
/* [↓] check for position*/
if p\=1 then do /*P¬=1? Then ajust F & H.*/
f=left(h, min(p-1, length(h))) /*keep first part intact. */
f=left(h, min(p-1, length(h))) /*keep first part intact. */
h=substr(h, p) /*only use this part of H.*/
h=substr(h, p) /*only use this part of H.*/
Line 53: Line 55:
if _=='' then return f || $ || y /*no more left, return. */
if _=='' then return f || $ || y /*no more left, return. */
$=$ || y /*append the residual txt.*/
$=$ || y /*append the residual txt.*/
/* [↓] check if too soon.*/
if j<b then $=$ || o /*append OLD if too soon. */
if j<b then $=$ || o /*append OLD if too soon. */
else do /*met the occurrence test.*/
else do /*met the occurrence test.*/
$=$ || n /*append the NEW string.*/
$=$ || n /*append the NEW string.*/
#=#+1 /*bump occurrence number.*/
#=#+1 /*bump occurrence number. */
end
end /* [↑] append new string.*/
end /*j*/ /*Note: most REXX ··· */
end /*j*/ /*Note: most REXX ··· */
/* CHANGESTR BIFs only ···*/
/* CHANGESTR BIFs only ···*/