all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: handa <handa@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gregory@heytings.org, 46933@debbugs.gnu.org
Subject: bug#46933: Possible bugs in filepos-to-bufferpos / bufferpos-to-filepos
Date: Sat, 27 Mar 2021 22:23:59 +0900	[thread overview]
Message-ID: <871rc0u3v4.fsf@gnu.org> (raw)
In-Reply-To: <8335whowuj.fsf@gnu.org> (message from Eli Zaretskii on Sat, 27 Mar 2021 10:54:28 +0300)

In article <8335whowuj.fsf@gnu.org>, Eli Zaretskii <eliz@gnu.org> writes:
> Thanks.  The patch fixes the problem with the extra 6 bytes, so I
> installed it.

Thank you for the improved concise comment in the code.

> The results of filepos-to-bufferpos with the file attached by Gregory
> are better now, but there are still problems for some values of BYTE
> argument.  The problem is that ISO-2022 encoding (and others like it)
> include shift-in and shift-out sequences, used to switch between
> character sets.  As a trivial example, each CR+LF sequence has the
> "ESC ( B" sequence before it and "ESC $ B" sequence after it, to
> switch to ASCII before the newline, then switch to Japanese after it.
> And likewise whenever there's Latin text within Japanese (there are
> quite a lot of them in this particular file).  These shift-in and
> shift-out sequences consume bytes, but don't produce any characters.
> So if the BYTE argument of filepos-to-bufferpos specifies a byte in
> the middle of one of these shift sequences, the result will be
> incorrect, because decoding a partial sequence produces the bytes of
> that sequence verbatim, and the logic in filepos-to-bufferpos of using
> the length of the decoded text breaks.  We need special handling of
> this and other similar coding-systems to fix these corner use cases,
> similarly to what we do in filepos-to-bufferpos--dos.  Patches
> welcome.

How about something like this method:
1. Encode the buffer text one line by one until we get a longer byte
sequence than BYTE.
2. Delete the result of enoding the last line above.
3. Provided that the above last line has chars C1 C2 ... Cn, 
encode characters C1...Cn, C1...Cn-1, C1...Cn-2 until we get a shorter
byte sequence than BYTE.

The first step may be optimized by encode multiple lines instead of
single line.

---
K. Handa
handa@gnu.org





  reply	other threads:[~2021-03-27 13:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-04 21:21 bug#46933: Possible bugs in filepos-to-bufferpos / bufferpos-to-filepos Gregory Heytings
2021-03-21 15:27 ` Eli Zaretskii
2021-03-27  5:38   ` handa
2021-03-27  7:54     ` Eli Zaretskii
2021-03-27 13:23       ` handa [this message]
2021-03-27 13:54         ` Eli Zaretskii
2021-03-28 14:29           ` handa
2021-03-28 14:51             ` Eli Zaretskii
2021-04-01 15:14               ` handa
2021-04-01 15:25                 ` Eli Zaretskii
2021-04-01 15:32                 ` Eli Zaretskii
2021-04-03 16:12                   ` handa
2022-06-20  0:59                     ` Lars Ingebrigtsen
2022-06-20 11:52                       ` Eli Zaretskii
2022-06-21 10:40                         ` Lars Ingebrigtsen
2022-06-21 12:14                           ` Eli Zaretskii
2022-06-22  4:17                             ` Lars Ingebrigtsen
2022-06-22 13:11                               ` Eli Zaretskii
2021-03-27 14:24     ` Gregory Heytings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871rc0u3v4.fsf@gnu.org \
    --to=handa@gnu.org \
    --cc=46933@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=gregory@heytings.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.