bug-groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: .substring bug - indicies don't work as documented(?)


From: Ralph Corderoy
Subject: Re: .substring bug - indicies don't work as documented(?)
Date: 27 Oct 2001 10:42:22 +0100

Hi Jim,

> The man page says:
>        .substring xx n1 [n2]
>               Replace the string in register  xx  with  the  subĀ­
>               string defined by the indices n1 and n2.  The first
>               character in the string has index one.   If  n2  is
>               omitted,  it  is  taken to be equal to the string's
>               length.  If the index value n1 or n2 is negative or
>               zero,  it  will  be  counted  from  the  end of the
>               string, going backwards:  The  last  character  has
>               index  0,  the  character before the last character
>               has index -1, etc.

Agreed.

> If this is not a bug, can someone explain the output to me?

I'll try, although I haven't come across .substring before.

Here's your string with points between the characters labelled with the
indexes as described above.

        1   2   3   4   5   6   7   8
        | a | b | c | d | e | f | g |
       -7  -6  -5  -4  -3  -2  -1   0

> for s=abcdefg .substring s 0 1 yields "abcdefg"

All characters between 0 and 1 is the whole string.

> for s=abcdefg .substring s 0 2 yields "bcdefg"

Yep, still OK.

> for s=abcdefg .substring s 0 3 yields "cdefg"
> for s=abcdefg .substring s 1 1 yields ""
> for s=abcdefg .substring s 1 2 yields "a"
> for s=abcdefg .substring s 1 3 yields "ab"
> for s=abcdefg .substring s 2 1 yields "a"

Looks like it doesn't matter which way around n1 and n2 are, it is
always the characters inbetween that are taken.

Here's your first one swapped around and another test.

    % (echo .ds x abcdefg; echo .substring x 1 0; echo '\*x') | nroff | cat -s
    abcdefg

    % (echo .ds x abcdefg; echo .substring x 6 -5; echo '\*x') | nroff | cat -s
    cde

Cheers,


Ralph.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]