From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#31679: 26.1; detect-coding-string does not detect UTF-16 Date: Thu, 12 Aug 2021 15:51:28 +0200 Message-ID: <87tujukbz3.fsf@gnus.org> References: <87efhq47nz.fsf@justinian.i-did-not-set--mail-host-address--so-tickle-me> <83zi0deish.fsf@gnu.org> <874lilgumy.fsf@blei.turtle-trading.net> <836031e06k.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14827"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 31679@debbugs.gnu.org, Benjamin Riefenstahl To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 12 15:52:09 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mEB7w-0003b4-U5 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 12 Aug 2021 15:52:08 +0200 Original-Received: from localhost ([::1]:44510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEB7v-0003fS-T9 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 12 Aug 2021 09:52:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEB7p-0003fJ-RD for bug-gnu-emacs@gnu.org; Thu, 12 Aug 2021 09:52:01 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mEB7p-0004sy-L1 for bug-gnu-emacs@gnu.org; Thu, 12 Aug 2021 09:52:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mEB7p-0008IO-JL for bug-gnu-emacs@gnu.org; Thu, 12 Aug 2021 09:52:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Aug 2021 13:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31679 X-GNU-PR-Package: emacs Original-Received: via spool by 31679-submit@debbugs.gnu.org id=B31679.162877630131843 (code B ref 31679); Thu, 12 Aug 2021 13:52:01 +0000 Original-Received: (at 31679) by debbugs.gnu.org; 12 Aug 2021 13:51:41 +0000 Original-Received: from localhost ([127.0.0.1]:37871 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEB7U-0008HW-Te for submit@debbugs.gnu.org; Thu, 12 Aug 2021 09:51:41 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:41120) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEB7T-0008HI-GX for 31679@debbugs.gnu.org; Thu, 12 Aug 2021 09:51:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=tnYNJT83X4Fl4fw1MI3HqvdTgAswmxKmPcA/6J3VeLQ=; b=kvRb/+QDTnlBsLn3I+8GT+Sczf 0+hUYO3FayNqd5s0TkgYD4gnsDuIjZsZPB1qYI3sExMNQqQwtf850Rxz2Q79nExfw7XoS9agxhMcO U1JRbS56ltLFALaIPw4vT0T4fnvc96GSp0n3urY8i6lyyeivkQm4hd2cHCKm0dMjfcW4=; Original-Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mEB7I-0006TN-MF; Thu, 12 Aug 2021 15:51:32 +0200 In-Reply-To: <836031e06k.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 02 Jun 2018 17:24:19 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:211677 Archived-At: Eli Zaretskii writes: >> My use-case is that I am trying to paste types other than UTF8_STRING >> from the X11 clipboard, and have them handled as automatically as >> possible. While official clipboard types probably have a documented >> encoding (and I have code for those), applications like Firefox also put >> private formats there. And Firefox seems to like UTF-16, even the >> text/html format it puts there is UTF-16. > > If you have a special application in mind, you could always write some > simple enough code in Lisp to see if UTF-16 should be tried, then tell > Emacs to try that explicitly. I ran into the same issue when dealing with X selections -- but there's even more peculiarities in that area (some selections add a spurious nul to the end, and some done), so you have to write a bit of code around this: `decode-coding-string' in itself can't be expected to deal/guess all these oddities (as you say). >> I have tried to debug the C routines that implement this (s.a.), but the >> code is somewhat hairy. I guess I'll have another look to see if I can >> understand it better. > > We could add code to detect_coding_system that looks at some short > enough prefix of the text and sees whether there's a null byte there > for each non-null byte, and try UTF-16 if so. Assuming that we want > to improve the chances of having UTF-16 detected for a small penalty, > that is. I do think that, in general, it would be nice if detect_coding_system did try a bit harder to guess at utf-16. For instance, if (in the first X bytes of the string) more than 90% of the byte pairs look like non-nul/nul pairs, then it's pretty likely to be utf-16. (And I think that would be easy enough to implement?) On the other hand, as you point out, there's a performance penalty that may not be worth it. So... uhm... does anybody have an opinion here? Try harder for utf-16 or just leave it as it is? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no