🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #159773

[Dialog] A script that substitutes problematical win chars

#159773
From: Enrico C
Date: Tue, 28 Dec 2004 00:08
109 lines
4381 bytes
I would like to have a Dialog script that automatically substitutes some
"problematical" CP-win-1252 chars with their ISO-8859-1 equivalents before
sending the message.
I refer to the characters discussed in
http://www.cs.tut.fi/~jkorpela/www/windows-chars.html

[such "forbidden" chars, by the way, are also refused by a robotmoderator,
as it was pointed out in a thread on it.comp.software.newsreader .
Message-ID: <1uzf9rnafvo6w.dlg@ID-28877.user.uni-berlin.de>
in Italian, sorry!]

That means, for instance, replacing  “ and ” with " ,  ’ with ' , and so
on. 
I tried to use the "Umlaut" OnBeforeSending script in the 40tude Wiki 
http://www.40tude.com/dialog/wiki/index.php/ScriptreplaceUmlaut
(by the way, there is a missing ' in the stringreplace lines, I corrected
that in my version).

It works! For instance, it replaces the Utf-8 representation [in many cases
Dialog correctly switches to Utf-8 to represent them] of “ (⤽) and ”
(⤝) with a ".

| program OnBeforeSendingMessage;
| 
| 
| function StringReplace(S, OldPattern, NewPattern: string): string;
| var
|   SearchStr, Patt, NewStr: string;
|   Offset: Integer;
| begin
|   SearchStr := S;
|   Patt := OldPattern;
|   NewStr := S;
|   Result := '';
|   while SearchStr <> '' do
|   begin
|     Offset := AnsiPos(Patt, SearchStr);
|     if Offset = 0 then
|     begin
|       Result := Result + NewStr;
|       Break;
|     end;
|     Result := Result + Copy(NewStr, 1, Offset - 1) + NewPattern;
|     NewStr := Copy(NewStr, Offset + Length(OldPattern), 2147483647);
|     SearchStr := Copy(SearchStr, Offset + Length(Patt), 2147483647);
|   end;
| end;
| 
| function OnBeforeSendingMessage(var Message: TStringlist; Servername: string; IsEmail: boolean):boolean;
| var s:string;
| begin
| result:=true;
| s:=message.text;
| s:=StringReplace(s,'⤽','"'); 
| s:=StringReplace(s,'⤝','"');  
| message.text:=s;
| end;
| 
| begin
| end.

The problem, of course, is that such a script is Utf-8 specific and doesn't
apply to other charsets.

Now I would like to rewrite the script as an OnOutgoingMessageCheck script,
so that, hopefully, it will replace the problematical chars before they are
coded in a given charset, i.e. regardless of their representation.

I tried this, it compiles Ok but it doesn't seem to do what I expected.
 
| 
| program OnOutgoingMessageCheck;
| 
| 
| function StringReplace(S, OldPattern, NewPattern: string): string;
| var
|   SearchStr, Patt, NewStr: string;
|   Offset: Integer;
| begin
|   SearchStr := S;
|   Patt := OldPattern;
|   NewStr := S;
|   Result := '';
|   while SearchStr <> '' do
|   begin
|     Offset := AnsiPos(Patt, SearchStr);
|     if Offset = 0 then
|     begin
|       Result := Result + NewStr;
|       Break;
|     end;
|     Result := Result + Copy(NewStr, 1, Offset - 1) + NewPattern;
|     NewStr := Copy(NewStr, Offset + Length(OldPattern), 2147483647);
|     SearchStr := Copy(SearchStr, Offset + Length(Patt), 2147483647);
|   end;
| end;
| 
| procedure OnOutgoingMessageCheck(Message: TStringlist; var Warnings, Errors: TStringlist);
| 
| var s:string;
| begin
| s:=message.text;
| s:=StringReplace(s,'“','"'); // 
| s:=stringreplace(s,'”','"'); //                                  
| message.text:=s;
| end;
| 
| begin
| end.  
Technical Details
Message-ID: <1xln9aej5brbh.dlg@news.lillathedog.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news-out.tin.it!news-in.tin.it!x-privat.org!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <1xln9aej5brbh.dlg@news.lillathedog.net>
Subject: [Dialog] A script that substitutes problematical win chars
Date: Tue, 28 Dec 2004 00:08:08 +0000
From: Enrico C <use_replyto_address@despammed.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news-out.tin.it!news-in.tin.it!x-privat.org!not-for-mail
Newsgroups: news.software.readers
User-Agent: 40tude_Dialog/2.0.14.1
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Reply-To: enrico.c@people.it
NNTP-Posting-Host: $$6drnk_$xjn2m.x-privat.org
Organization: X-Privat NNTP Server - http://www.x-privat.org
Lines: 109
X-Authenticated-User: $$t9dw0m0cxnc-vpzkjjlef
X-Complaints-To: abuse@x-privat.org