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: Werner LEMBERG
Subject: Re: .substring bug - indicies don't work as documented(?)
Date: Sat, 27 Oct 2001 19:42:50 +0200 (CEST)

> >        .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.
> 
> 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

But this is not the behavior documented in the man page.  It talks
about character indices, not the `point' between two characters (as
used e.g. in Emacs).  So the table has to be

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

I believe that this is natural for computing substrings.

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

This is especially noteworthy.  The substring starting at index 1 and
ending at index 1 is of course "a" and not the empty string.

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

Exactly.


    Werner



reply via email to

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