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:23:07 +0200 (CEST)

> There may be a bug in the .substring function in 
> GNU troff version 1.16.1.
> 
> 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.
> 
> Are n1 and n2 supposed to be the starting and ending indices
> of the substring to be retained?

Yes.

> 
> Here are some results:
> 
> for s=abcdefg .substring s 0 1 yields "abcdefg"
> for s=abcdefg .substring s 0 2 yields "bcdefg"
> 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"
> 
> If this is not a bug, can someone explain the output to me?

It is a bug.  Thanks for spotting.  I've just fixed it in the CVS.
Now you'll get the following consistent results:

  for s=abcdefg .substring s  0   yields "g"
  for s=abcdefg .substring s  0 1 yields "abcdefg"
  for s=abcdefg .substring s  0 2 yields "bcdefg"
  for s=abcdefg .substring s  0 3 yields "cdefg"
  for s=abcdefg .substring s  1 1 yields "a"
  for s=abcdefg .substring s  1 2 yields "ab"
  for s=abcdefg .substring s  1 3 yields "abc"
  for s=abcdefg .substring s  2 1 yields "ab"
  for s=abcdefg .substring s  2 2 yields "b"
  for s=abcdefg .substring s  2 3 yields "bc"
  for s=abcdefg .substring s -2   yields "efg"
  for s=abcdefg .substring s -1   yields "fg"
  for s=abcdefg .substring s  0   yields "g"
  for s=abcdefg .substring s  1   yields "abcdefg"
  for s=abcdefg .substring s  2   yields "bcdefg"

Ruslan, may I ask that you check mdoc?  This is the only macro package
of groff which uses the .substring request.


    Werner



reply via email to

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