Focal Point
[Hocus-Pocus-Focus] STRREP

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/2787027716

March 12, 2012, 07:10 AM
linnex
[Hocus-Pocus-Focus] STRREP
Hello everyone,

today I was again surprised by an awkwardly strange behaviour of one WebFOCUS function, yet not suprised to much as I have experienced the same awkwardness with other features and functions in this so-called powerful tool.

My today's favorite is STRREP - which is meant to replace all string occurences (param #4) in an input string (param #2).
Usually this works as expected - BUT:

Have you tried using this one with an input string shorter than the search string. Well you might say: what's the point in doing so - simple answer: when using dynamic strings you cannot a-priori tell what will be in there.
(I stumbled accross this problem btw. when trying to use STRREP on multi-selection strings from an HTML page - replacing the ' OR ' with a comma+space - for input strings with a length < 6 this won't work)

If you now try the following:

 
-SET &MYSMURF = 'PAPA';
-SET &SMURF = STRREP(&MYSMURF.LENGTH, &MYSMURF.QUOTEDSTRING, 6, 'CLUMSY', 5, 'HEFTY', 20, 'A20');
-TYPE &SMURF


You won't get your PAPA back - instead an empty string is returned. Even worse: in some versions of WF (I "successfully" tried 7.7.01)using the a.m. construction in a DEFINE FUNCTION part leads to an agent crash. At least this crash seems to have been fixed in 7.7.03

In every other computer language where you can script or program with strings a similar function would just return the in-string, as the string-to-replace can never be found.
But ... "Hocus-Pocus-Focus" ... WF doesn't.

So - again a check + exception handling is needed to test the dynamic string length and avoid performing a STRREP if instr.length < repstr.length. Pain in the ...

Cheers, Linne

This message has been edited. Last edited by: linnex,


WebFOCUS 7.7.03
March 12, 2012, 10:39 AM
GamP
Syntax of the STRREP procedure:
STRREP (inlength, instring, searchlength, searchstring, replength, repstring, outlength, outstring)
The manual states that 'searchlength' must be less than or equal to 'inlength' (searchlength: Is the number of characters in the (shorter length) string to be replaced). In your case it is not.
If you expand the string to be searched to at least 6 charcaters, you do get the original string in case the search string can't be found.
It is not documented however that it should return an empty string when something is not correct. You might want to bring that to the attention of IB tech support by opening a case.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
March 12, 2012, 03:32 PM
Waz
quote:
Hocus-Pocus-Focus


Great Song!




Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 12, 2012, 03:36 PM
Tony A
Hocus Pocus by Focus, sad to say that, like Waz, I remember it well Music in fact it's in my head now and I can't get it out Frowner

T
March 12, 2012, 03:45 PM
Waz
My job is done....




Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 13, 2012, 05:44 AM
linnex
Hi everyone,

@GamP
quote:
The manual states that 'searchlength' must be less than or equal to 'inlength'


I do not quite agree - that the restriction is stated there, for me it is only "hinted". Cool
IMHO: A standard documentation should state: "The search length must be less than the in-string length" or similar.

Well, I must admit I have read this passage of "shorter length" after I had my superb experience with STRREP + multiple agent crashes. One might assume that this "shorter length" refers to the instr - nevertheless this is still at least strange.
But of course you are right, that the result actual result returned is not at all documented. I will consider opening a case here.

Nevertheless I am happy to have given you that catchy tune Wink

Cheers, Linne


WebFOCUS 7.7.03
March 13, 2012, 09:41 AM
Prarie
The song was not coming to me..so I had to go find it. Ever wonder what the Lyrics looked like in print?

Smiler

Yodeadodoyodeadodoyodeadodoyodeadodo. yodeadodoyodeadodoyo-bab-baaaaa. Ahhhhhh-aaahhhh-aaaaaa-aaaaAAA
March 13, 2012, 02:36 PM
M Meagher
.... and I just walked over and put it on my turntable. Tjis van Leer on the flute.
March 13, 2012, 04:08 PM
John_Edwards
I've always been a little perplexed about why I need to tell WF how long strings are in the first place. It can't figure out the length of 'abc' on its own?

J.



March 13, 2012, 04:57 PM
Waz
The issue with supplying string lengths was explained a long time ago, can't remember is it was in this forum or verbally to me.

But there was good reason for it.

As for the STRREP function, I guess it would be illogical to search for a string that is larges than the string you are searching through.

But it would have been nice to have the function return the original string in this case.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 13, 2012, 04:58 PM
Waz
quote:
and I just walked over and put it on my turntable


You have a turntable, how retro....

Big Grin


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 13, 2012, 08:51 PM
j.gross
quote:
supplying string lengths


The FUSELIB routines were originally either written in FORTRAN, or written to be callable from FORTRAN.

It's been a while (Big Grin), but as I recall the FORTRAN function-call protocol just passed the address of the variable (or of a copy of its value), without supplying any info on the "type" of the argument. For that matter, there was no native Character data type -- we would sneak them into arrays of one of the numeric types.

And, since they were "contributed" to the library, without "editing" or peer review, you got a hodgepodge of length-then-value and value-ten-length designs for the parameter list. (Even the RJUST, LJUST, CENTER trio are not consistent.)
March 13, 2012, 09:05 PM
Waz
quote:
passed the address of the variable


That fired some old neurons.

Thats what I told/read.

Good One


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 14, 2012, 07:18 AM
GamP
Yep, that's it.
As I remember it, it is called parameter passing by reference. You only pass the memory address of the first byte of the parameter, which is why you really do need the length to be specified also and why you can't figure out what size string you have been passed.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
March 14, 2012, 08:40 AM
j.gross
quote:
... can't figure out what size string you have been passed.


That's the reason (aside from the cultural reference to FORTRAN I/O statements) for the parens in arg 2 of
FTOA(number, '(format)', outfield)


One mystery:
CHGDAT('in_display_options','out_display_options',date_string,outfield)

-- the output option string can be 1 to 5 characters long (e.g., 'Y' and 'YYMDX'). If shorter than 4, the value is blank-padded to a full word. But if it's 4 -- e.g., 'YYMD' -- what assures that the next word in memory does not start with T (or X), which would (mis)lead the routine to convert the month to alpha?

-Jack
March 14, 2012, 08:52 AM
GamP
In this special case, literal strings are being passed (the values are within quotes). In that case the parameters are not passed by reference, but by value. The receiving function will have to cater for the maximum number of characters passed.
What makes you state that if it is shorter than 5, it gets padded to a full-word?


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
March 14, 2012, 11:39 AM
j.gross
quote:
What makes you state that if it is shorter than 5, it gets padded to a full-word?


That's the way it is (or was) in FORTRAN, in the 360 spawning ground of FOCUS -- all allocated variables and literals would start on whole-word boundaries, so the remainder of the last word of a character literal (if length is not a multiple of 4), would be padded with blanks.

It may be platform-dependent.