*>>SOURCE FORMAT IS FIXED *> *************************************************************** *> Author: Brian Tiffin *> Date: 27-Oct-2008 *> Purpose: Find and replace unequal length sub strings *> in this case, for HTML entities *> Tectonics: cobc -x ocfr.cob *> *************************************************************** identification division. program-id. ENTITYIFY. data division. working-storage section. 01 source-string pic x(256). 01 dest pic x(256). 01 fore usage binary-long. 01 aft usage binary-long. 01 source-limit usage binary-long. 01 elements constant as 3. 01 element usage binary-long. 01 finder-table. 03 filler pic x(1) value "<". 03 filler pic x(1) value ">". 03 filler pic x(1) value "&". 01 filler redefines finder-table. 03 finder pic x(1) occurs elements times. 01 replacement-table. 03 filler pic x(5) value "<". 03 filler pic x(5) value ">". 03 filler pic x(5) value "&". 01 filler redefines replacement-table. 03 replacement pic x(5) occurs elements times. 01 rlen usage binary-long. 01 flen usage binary-long. 01 substitute-flag pic x value low-value. 88 no-substitution value low-value. 88 substitution-occured value high-value. *> ************************************************************** procedure division. *> ************************************************************** *> * This is a very particular usage. The OC developer should *> * have access to a more generic *substitute this for that* *> * operation. Whether it be a copybook performable or a *> * separate callable program. *> ************************************************************** *> move "<" to finder(1) *> move "<" to replacement(1) *> move ">" to finder(2) *> move ">" to replacement(2) *> move "&" to finder(3) *> move "&" to replacement(3) move "" & "this is a sample" & "" & "

A sample showing entity replacement" & "

of < > and & for safe browser source display

" & "" & "" to source-string move spaces to dest. display "|" function trim(source-string trailing) "|" end-display perform find-replace-all display "|" function trim(dest trailing) "|" end-display move "<& a string showing %amp; &>" to source-string move spaces to dest. display "|" function trim(source-string trailing) "|" end-display perform find-replace-all display "|" function trim(dest trailing) "|" end-display goback. *> ************************************************************** find-replace-all. compute aft = 1 end-compute compute fore = 1 end-compute compute source-limit = function length(function trim(source-string trailing)) end-compute perform until fore > source-limit set no-substitution to true move 1 to element perform until element > elements perform find-replace-current if no-substitution add 1 to element end-add end-if end-perform if no-substitution move source-string(fore:1) to dest(aft:1) add 1 to fore end-add add 1 to aft end-add end-if end-perform exit. *> ************************************************************** find-replace-current. compute rlen = function length(function trim(replacement(element) trailing)) end-compute compute flen = function length(function trim(finder(element) trailing)) end-compute if source-string(fore:flen) = finder(element) move replacement(element) to dest(aft:rlen) add rlen to aft end-add add flen to fore end-add set substitution-occured to true add 1 to elements giving element end-if exit. end program ENTITYIFY.