πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #264293

Re: trn 4 and UTF-8

#264293
From: Eli the Bearded
Date: Wed, 05 Aug 2020 23:44
147 lines
5918 bytes
Crosspost and follow-ups set to comp.editors.

In news.software.readers, Arlen Holder  <arlenholder@newmachine.com> wrote:
> I have what I think is that same problem with telnet/vim that the funky
> diagraph characters don't show up, on your end, as being what they were
> on my end. 
> 
> I never knew why.
> o <https://i.postimg.cc/TP0dsDyX/smartquote01.jpg>
> 
> For example, this is a cut-and-paste of what you wrote:
>  "Michael BΓ€uerle posted using an ISO-8859-1 mime-encoded word"
> (where the "a" in his last name is xxx in vim)

The screenshot you show there has a proper U+E4 LATIN SMALL LETTER A
WITH DIAERESIS  in Michael's name, not "xxx".

> I just never knew shy smart quotes don't get sent properly.

Newsreader software that properly understands character encoding (so
*not* trn) require the appropriate headers to make sense of non-ASCII
encodings in posts.

Vim does not have access to that metadata, and uses preferences and
heuristics to guess the encoding.

For me:
    fileencodings=ucs-bom,utf-8,default,latin1

That indicates the encodings vim will attempt to guess for a document.

And this is what it has selected for this document:

    fileencoding=utf-8

If it guesses wrong, or if I want to explicitly change it, I can
set fileencoding to a new value. When I follow-up to ISO-8859-1
("latin1") posts, I either edit out all highbits or change the encoding
with ":set fileencoding=utf-8". Doing so does not "dirty" the content,
and if I've made no other edits ":q" will not warn me about unsaved
changes, so I often explicitly ":w" after such a change.

Depending on compile time options in vim, these settings may not be
available or just won't work.

> Notice that, in vim, a "ga" (i.e., get ascii) shows the following:
> The "a" in Bauerle is decimal 228.

I was unaware of that tool in vim. I see

    <Γ€> 228, Hex 00e4, Oct 344, Digr a:

When I try it. Note that lowercase a with diaeresis is at the same
position (228 or 0xE4) in both the ISO-8859-1 and Unicode character
sets, but has a different encoding in the Unicode character encodings
(UTF-x, UCS-x, where "x" indicates a family of encodings). MIME uses one
word to indicate both character set and character encoding, "charset",
but properly they are two different things.

ISO-8859-1 only encodes a character in a single octet. UCS-4 only uses
four octets to encode. UTF-7 uses a series of seven bit safe octets to
encode any character in Unicode (using a form of inline base64), UTF-8
uses a series of one to four octets to encode an any character in
Unicode. Seven bit safe code points are encoded in one seven bit safe
octet, all other code points are encoded in a series of high-bit set
octets.

Critically, here, this means U+E4 must be encoded differently for UTF-8
and ISO-8859-1. And many UTF-8 encodings can be mistaken for a series of
high-bit set characters in a ISO-8859-1 encoding.

> When I want to "fix" them in vim, I use the following sequence:

When I want to fix them in vim, I use a mappings to desmart quote
stuff on input or filter them with a Perl script.

#!/usr/local/bin/perl -w
# Use the .news_vimrc rules to turn high-bit content into ASCII text
# content. Note that .news_vimrc should be considered binary, not
# UTF-8, since it includes rules for bad encodings. And note that it
# doesn't attempt to remove all high-bit stuff.
#
# September 2018

use strict;
use vars qw( $infile %rules $all_re $hb $t $count );

$infile = $ENV{HOME} . '/.news_vimrc';

if(!open(RC, "< $infile")) {
  # die "$0: $infile: $!\n";
  # use fallback set of rules
  *RC = *DATA;
}

while(<RC>) {
  # map! (whitespace) (non-whitespace LHS) (whitespace) (RHS with embeded WS)
  # but ignore rules like:
  # map! <F6> Content-Type: text/plain; charset="UTF-8"<cr>MIME-Version: 1.0<cr>
  if(($hb, $t) = /^\s*map!\s+([^<\s]\S*)\s+(\S.*)/) {
    if ($hb =~ /[].*+|^\$\\()[{}]/) {
      die "$0: Whoa. Rule on line $. has RE metacharacters\n";
    }
    $rules{$hb} = $t;
  }
}
close RC;

$_ = join('|', keys(%rules));
die "$0: no rules!\n" unless length $_;

$all_re = qr/($_)/;

$count = 0;
while(<>) {
  s/$all_re/$rules{$1}/eg;
  if(/[^\t\n\r -~]/) {
    $count ++;
  }
  print;
}
if($count) {
  warn "$0: warning: $count line(s) still have highbits\n";
}
__END__
# simplified fallback set of mappings to use
" smart quotes
map! ’ '
map! β€˜ '
map! β€œ "
map! ” "
map! β€³ "
" ellipsis
map! … ...
" n-dash
map! – --
" m-dash
map! β€” --
" U+2212 minus
map! βˆ’ -
" U+2010 hyphen
map! ‐ -


Elijah
------
notably does not have a subsitute for the bullet point example
Technical Details
Message-ID: <eli$2008051859@qaz.wtf>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
References: <rganif$m4h$1@neodome.net> <eli$2008051347@qaz.wtf> <eli$2008051651@qaz.wtf> <rgfc30$gm3$1@news.mixmin.net>

Show Full Headers
Complete Article Headers
Message-ID: <eli$2008051859@qaz.wtf>
Subject: Re: trn 4 and UTF-8
Date: Wed, 05 Aug 2020 23:44:09 +0000
From: Eli the Bearded <*@eli.users.panix.com>
References: <rganif$m4h$1@neodome.net> <eli$2008051347@qaz.wtf> <eli$2008051651@qaz.wtf> <rgfc30$gm3$1@news.mixmin.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
Newsgroups: news.software.readers,comp.editors
Organization: Some absurd concept
Lines: 147
X-Attribution: EtB
X-Trace: reader1.panix.com 1596671049 828 166.84.1.5 (5 Aug 2020 23:44:09 GMT)
Encrypted: double rot-13
Followup-To: comp.editors
Nntp-Posting-Date: Wed, 5 Aug 2020 23:44:09 +0000 (UTC)
X-Us-Congress: Moronic Fucks.
X-Motto: "Erosion of rights never seems to reverse itself." -- kenny@panix
User-Agent: Vectrex rn 2.1 (beta)
X-Liz: It's actually happened, the entire Internet is a massive game of Redcode
Nntp-Posting-Host: panix5.panix.com
Mime-Version: 1.0
X-Complaints-To: abuse@panix.com
Xfrom: is a real address
Content-Type: text/plain; charset="UTF-8"