[Gambas-user] Bug in split() ? (1.0.13)

Benoit Minisini gambas at ...1...
Wed Jan 18 13:09:25 CET 2006


On Wednesday 18 January 2006 10:45, Eilert wrote:
> I am not quite sure, folks, but this seems to be a bug in the Split()
> function. Or didn't I understand how to use it? Anyway:
>
> In my program, there are strings from a file indicating where and how
> certain input elements of an input mask should appear. For example,
> there is a "list" element (ComboBox) which has to display some items for
> the user to click on.
>
> This is what those strings look like:
>
>     item= mask:'*rau', opt:nocase, insert:'Frau', display:'weiblich'
>     item= mask:'*err', opt:nocase, insert:'Herr', display:'männlich'
>
> This means, if you find "*rau", case-insensitive, display "weiblich". If
> chosen by the user, insert "Frau" into the field.
>
> Now, this function was meant to pick out the "display" command from the
> string. I inserted a message.info, because it shows what goes wrong:
>
> RIVATE FUNCTION MaskeLstDisplay(lst AS String) AS String
> DIM lOpt AS NEW String[]
> DIM lCom AS NEW String[]
> DIM i AS Integer
> DIM x$ AS String
>
>
>   lOpt = Split(lst, ",", "'") 'String nach Optionen aufteilen (Kommas)
>
>
>   'Kommando "display" suchen:
>   FOR i = 0 TO lOpt.Count - 1
>     lCom = Split(lOpt[i], ":", "'")
> message.Info(lCom[0] & "--" & lCom[1])
>     IF String.LCase(Trim$(lCom[0])) = "display" THEN
>       x$ = Trim$(lCom[1])
>       IF String.Left(x$, 1) = "'" THEN x$ = String.Mid(x$, 2)
>       IF String.Right(x$, 1) = "'" THEN x$ = String.Left(x$,
> String.Len(x$) - 1)
>       RETURN x$
>     END IF
>   NEXT
>
>
>   RETURN "?display-Angabe fehlt"
>
> END
>
> The line above the message.info includes "'" as an escape string. This
> would mean you could use ":" within the strings without getting trouble.

The escape character is just checked at the beginning and at the end of a 
splitted element, i.e., in your case, just before a comma, just after, at the 
beginning or at the end of string. It allows you to have a comma inside a 
splitted element.

I think this is not what you expected.

> If you feed the function with strings like above, you will see that the
> last "'" will remain, whilest all other "'" are cut. In my program, this
> function is called about 6 times, and sometimes (not reproduceably) the
> Split() keeps garbage from previous calls. I've got "display" commands
> with shorter strings, and sometimes character garbage and some "m nnl
> ch" or so will remain at the end of the next string.
>

This seems to be a bug. Can you send me a big list of such strings so that I 
can test your function. Maybe I could get the same bugs as you.

> The point is, when you leave the Escape character away, everything runs
> smoothly, it just leaves the "'" at the strings and doesn't care about
> them.

So you don't get the bug if you don't use the escape character? So it will 
help me to find the bug. I wanted to make a 1.0.14, but I will delay it so 
that I can fix this bug.

>
> So, is this a bug or am I making a mistake?

Both! :-)

>
> Thanks for your hints.
>
> Rolf
>

Regards,

-- 
Benoit Minisini





More information about the User mailing list