POV-Ray : Newsgroups : povray.general : Doc bug - substr() Server Time
8 Aug 2024 08:17:56 EDT (-0400)
  Doc bug - substr() (Message 1 to 10 of 35)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Rune
Subject: Doc bug - substr()
Date: 21 Feb 2001 15:20:19
Message: <3a942303@news.povray.org>
In the POV-Ray documentation on the page about string functions the
following is stated:

> substr(S,P,L) Sub-string from S. Returns a string that is
> a subset of the characters in parameter S starting at the
> position specified by the integer value P for a length
> specified by the integer value L. For example
> substr("ABCDEFGHI",4,2) evaluates to the string "EF".
> If P+L>strlen(S) an error occurs.

However, there are two errors. The last but one line should read:

> substr("ABCDEFGHI",4,2) evaluates to the string "DE".

And the last line should read:

> If P+L+1>strlen(S) an error occurs.

Or something like that.

Can anybody confirm?

And is this a known bug?

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated January 28)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Wlodzimierz ABX Skiba
Subject: Re: Doc bug - substr()
Date: 21 Feb 2001 18:43:50
Message: <3a9452b6@news.povray.org>
Rune wrote in message <3a942303@news.povray.org>...
> In the POV-Ray documentation on the page about string functions the
> following is stated:

that's funny
looking at time of your post it seems that I've met this bug at the same moment
perhaps even in solving the same problem :-)

> > substr("ABCDEFGHI",4,2) evaluates to the string "EF".
> However, there are two errors. The last but one line should read:
> substr("ABCDEFGHI",4,2) evaluates to the string "DE".

I can confirm

> > If P+L>strlen(S) an error occurs.
> If P+L+1>strlen(S) an error occurs.

I can confirm

> Can anybody confirm?

yes

> And is this a known bug?


I don't know

ABX


Post a reply to this message

From: Warp
Subject: Re: Doc bug - substr()
Date: 22 Feb 2001 05:23:01
Message: <3a94e885@news.povray.org>
It seems that the one who wrote that part of the doc thought that the
indexing starts from 0 and ends at strlen(S)-1, as in C.

  Perhaps the problem is not in the documentation, but in povray. In my
opinion this behaviour is a bit inconsistent. Array indexing starts from 0.

-- 
char*i="b[7FK@`3NB6>B:b3O6>:B:b3O6><`3:;8:6f733:>::b?7B>:>^B>C73;S1";
main(_,c,m){for(m=32;c=*i++-49;c&m?puts(""):m)for(_=(
c/4)&7;putchar(m),_--?m:(_=(1<<(c&3))-1,(m^=3)&3););}    /*- Warp -*/


Post a reply to this message

From: Bob H 
Subject: Re: Doc bug - substr()
Date: 22 Feb 2001 08:11:19
Message: <3a950ff7@news.povray.org>
Position 1 might be a good way of saying first character of a string though,
since it isn't a completely numerical thing being dealt with.
substr("abcd",1,1) being "a", instead of substr("abcd",0,0), just looks more
correct in this context to me.
Why isn't there a strlen() in the documentation?  :-)

Bob H.

"Warp" <war### [at] tagpovrayorg> wrote in message
news:3a94e885@news.povray.org...
>   It seems that the one who wrote that part of the doc thought that the
> indexing starts from 0 and ends at strlen(S)-1, as in C.
>
>   Perhaps the problem is not in the documentation, but in povray. In my
> opinion this behaviour is a bit inconsistent. Array indexing starts from
0.
>
> --
> char*i="b[7FK@`3NB6>B:b3O6>:B:b3O6><`3:;8:6f733:>::b?7B>:>^B>C73;S1";
> main(_,c,m){for(m=32;c=*i++-49;c&m?puts(""):m)for(_=(
> c/4)&7;putchar(m),_--?m:(_=(1<<(c&3))-1,(m^=3)&3););}    /*- Warp -*/


Post a reply to this message

From: Ron Parker
Subject: Re: Doc bug - substr()
Date: 22 Feb 2001 08:16:03
Message: <slrn99a48k.q8h.ron.parker@fwi.com>
On Thu, 22 Feb 2001 07:10:17 -0600, Bob H. wrote:
>Why isn't there a strlen() in the documentation?  :-)

There is, but it's not with the string functions.  It returns a numeric
value, so it's with the float functions:

strlen(S) Length of S. Returns an integer value that is the number of 
characters in the string S. 



-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Bob H 
Subject: Re: Doc bug - substr()
Date: 22 Feb 2001 08:28:19
Message: <3a9513f3@news.povray.org>
Sorry, I didn't look hard enough.  I used Context Help by right-clicking on
strlen within a scene file and it claimed not to have it even though I knew
it was a function.  Using Scene help button in WinPOV found it fine.

Bob H.

"Ron Parker" <ron### [at] povrayorg> wrote in message
news:slr### [at] fwicom...
> On Thu, 22 Feb 2001 07:10:17 -0600, Bob H. wrote:
> >Why isn't there a strlen() in the documentation?  :-)
>
> There is, but it's not with the string functions.  It returns a numeric
> value, so it's with the float functions:


Post a reply to this message

From: Christoph Hormann
Subject: Re: Doc bug - substr()
Date: 22 Feb 2001 08:55:00
Message: <3A951A2C.3DC886DE@gmx.de>
Warp wrote:
> 
>   It seems that the one who wrote that part of the doc thought that the
> indexing starts from 0 and ends at strlen(S)-1, as in C.
> 
>   Perhaps the problem is not in the documentation, but in povray. In my
> opinion this behaviour is a bit inconsistent. Array indexing starts from 0.
> 

But don't forget that in Pascal/Delphi it works the other way:

copy('ABCDEF', 3, 2) 

returns 'CD'.

Both ways have their advantages, i would keep it the way it is now.

Christoph

-- 
Christoph Hormann <chr### [at] gmxde>
IsoWood include, radiosity tutorial, TransSkin and other 
things on: http://www.schunter.etc.tu-bs.de/~chris/


Post a reply to this message

From: Geoff Wedig
Subject: Re: Doc bug - substr()
Date: 22 Feb 2001 09:19:05
Message: <3a951fd9@news.povray.org>
Rune <run### [at] inamecom> wrote:

> In the POV-Ray documentation on the page about string functions the
> following is stated:

>> substr(S,P,L) Sub-string from S. Returns a string that is
>> a subset of the characters in parameter S starting at the
>> position specified by the integer value P for a length
>> specified by the integer value L. For example
>> substr("ABCDEFGHI",4,2) evaluates to the string "EF".
>> If P+L>strlen(S) an error occurs.

> However, there are two errors. The last but one line should read:

>> substr("ABCDEFGHI",4,2) evaluates to the string "DE".

> And the last line should read:

>> If P+L+1>strlen(S) an error occurs.

> Or something like that.

> Can anybody confirm?

> And is this a known bug?

This is C style, counting from 0 rather than 1, which is what arrays do. 
Have you tried the program to see what it does?  Does it count from 1 or 0? 
If it goes from 1, then I see it as a bug in the program, not the docs,
because it's inconsistent.

Speaking of manual bugs, can anyone confirm that the #range feature for
#switch is actually lower < value <= upper and not lower <= value <= upper
like it says in the manual?

Geoff


Post a reply to this message

From: Francois Labreque
Subject: Re: Doc bug? #range - not a doc bug.
Date: 22 Feb 2001 10:29:05
Message: <3A952F9F.43B9E767@videotron.ca>
Geoff Wedig wrote:
> 
> Speaking of manual bugs, can anyone confirm that the #range feature for
> #switch is actually lower < value <= upper and not lower <= value <= upper
> like it says in the manual?

The doc is correct.

#switch( var)
    #range (1, 10)
        box{ 0, 1 pigment{ color rgb 1 }}
    #else
	sphere{ 0, 1 pigment { color rgb <1,0,0> }}
#end

creates a white box when var=1, not a red sphere as you think it would.


> 
> Geoff

-- 
Francois Labreque |   //\\    Wear an ASCII ribbon!
    flabreque     |  ||  ||   
        @         |   \\//    Support the campain
   videotron.ca        \\     against HTML e-mail
                      //\\    and news!


Post a reply to this message

From: Warp
Subject: Re: Doc bug - substr()
Date: 22 Feb 2001 10:39:02
Message: <3a953296@news.povray.org>
Christoph Hormann <chr### [at] gmxde> wrote:
: Both ways have their advantages, i would keep it the way it is now.

  The problem is that it can cause confusion.
  If someone is used to use substr() and then starts using arrays he will
probably be confused at first and think that also in arrays the indexing
starts from 1. And the other way around.

  It's the same type of confusion as caused by functions taking radians and
rotate taking degrees...

-- 
char*i="b[7FK@`3NB6>B:b3O6>:B:b3O6><`3:;8:6f733:>::b?7B>:>^B>C73;S1";
main(_,c,m){for(m=32;c=*i++-49;c&m?puts(""):m)for(_=(
c/4)&7;putchar(m),_--?m:(_=(1<<(c&3))-1,(m^=3)&3););}    /*- Warp -*/


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.