 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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] tag povray org> 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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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] povray org> wrote in message
news:slr### [at] 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:
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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] gmx de>
IsoWood include, radiosity tutorial, TransSkin and other
things on: http://www.schunter.etc.tu-bs.de/~chris/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Rune <run### [at] iname com> 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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Christoph Hormann <chr### [at] gmx de> 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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |