On Thu, 2024-08-15 at 13:07 +0200, Jürgen Spitzmüller wrote:
> My case was escaped quote as last content of the quoted string (e.g.,
> "\"" which returned \ rather than \")
> 

That makes sense. :-)

> > BTW I usually prefer code that is more expressive:
> > 
> > if val.startswith('"'):
> >     val =  val[1:]
> > if val.endswith('"'):
> >     val =  val[:-1]
> 
> OK, will change that.

There is no need to change it. My purpose here is just to give these
comments on context. :-)

With all the work you did in lyx2lyx I am aware that you understand
clearly what is going on. My comment is more general.


Honestly here the code, in this context, makes more sense like this:

if val.startswith('"') and val.endswith('"'):
    val =  val[1:-1]

So it only makes sense to remove both at once. Again on practice the
cases where this fails should not happen, unless there is something
like

\"

where the last double quote will be wrongly removed. The issue is that,
in principle, lyx should never write this code.


Now pushing this even further the code could be

return val[1:-1] if val.startswith('"') and val.endswith('"') else val

This is similar to the C++ ?: operator. :-)

-- 
José Abílio
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to