groff
[Top][All Lists]
Advanced

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

Can .substring be made to handle an empty result?


From: Jim Avera
Subject: Can .substring be made to handle an empty result?
Date: Fri, 26 Mar 2021 15:20:11 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1

I'm trying to use .substring to remove the first character of a string, leaving behind whatever follows, even if that is nothing (i.e. the string had only one character).

  .substring str 1

or

  .length n2 "\*[str]
  .nr n2 -1
  .substring str 1 \n[n2]

(if n2 is omitted, it appears to default to length-1 as you might expect).

The above works as long as the string originally had at least two characters.  If it only has one, so the desired result is the empty string, it does not remove anything, leaving behind the 0th character and emitting a warning (with -w all).

This seems like a corner-case bug.

Question: Is this intentional, to remain "bug compatible" with some older roff systems?

At first glance, it seems like it would be safe to fix this because the result is currently always wrong in this case, i.e. n1 equals the length of the string (so the result should be empty).

Thoughts?

-Jim




reply via email to

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