GNU bug report logs - #20258
24.5; format-time-string miscounting of multibyte characters

Previous Next

Package: emacs;

Reported by: Gunnar Horrigmo <gunnar.horrigmo <at> usit.uio.no>

Date: Sat, 4 Apr 2015 15:36:01 UTC

Severity: minor

Tags: fixed, patch

Found in version 24.5

Fixed in version 27.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 20258 <at> debbugs.gnu.org, Gunnar Horrigmo <gunnar.horrigmo <at> usit.uio.no>
Subject: bug#20258: 24.5; format-time-string miscounting of multibyte characters
Date: Sat, 04 Apr 2015 12:03:47 -0400
> 'length' counts characters, not bytes.  If you need to count bytes,
> use 'string-bytes' instead:

>   (string-bytes "  lø.") => 6

And in 99% of the cases, using length-bytes doesn't do what you think
(it doesn't count the number of bytes that it would take in your
favorite coding-system, but the number of bytes it takes within Emacs's
internal encoding).
If you want to know how many bytes it would take in your locale's
encoding, then you need:

   (length (encode-coding-string <thestring> locale-coding-system))


        Stefan




This bug report was last modified 5 years and 234 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.