Article View: news.software.readers
Article #159865Re: [Dialog] A script that substitutes problematical win chars
From: Enrico C
Date: Thu, 30 Dec 2004 00:56
Date: Thu, 30 Dec 2004 00:56
444 lines
17222 bytes
17222 bytes
On Wed, 29 Dec 2004 10:11:38 -0800, Tarkus wrote:
> On 12/29/2004 3:15:12 AM, Enrico C wrote:
>
>> Here it is (in a different way!)
>> Just run the script (in Dialog main window) before pasting any text
>> with Windows special chars (for instance when you copy from a web page
>> or a Word document with such chars) to a new message.
>
> This is a very useful script. Thank you very much!
>
> I post some articles to a Yahoo Group, and quite often those odd
> characters come out all screwed up on the other end (though not when
> reading with Dialog). This script fixes that.
Great! :)
> Any chance of adding code to delete extra blank lines? Also, extra lines
> with nothing but spaces or tabs?
For now, let's get rid of those redundant spaces and tabs ;)
|| Program PasteSpecialPlus;
||
|| {**********************************************
|| PasteSpecialPlus beta 0.2a+
||
|| A script that replaces Win special chars in the clipboard.
|| It can be useful for copy&paste to a new message from the web or from a Word doc.
||
|| [This "Plus" version also "compacts" (removes) redundant blanks
|| in empty lines with nothing but spaces or tabs.
|| Id est, a line with only spaces and tabs will become an empty line (no spaces, no tabs)!
|| You can better "see" the results by pasting the text, after applying the script,
|| to a text editor with "Show hidden text" capabilities]
||
||
||
||
|| Ciao!
||
|| I didn't do much to write this script! :)
|| It's mainly based on the SelectiveQuotedDestructor script by Alain Guerin
|| and on the Umlaut replace script on 40tude Wiki.
|| I (Enrico C , Sir and Master of www.lillathedog.net :)
|| combined those two scripts and used the result for my purposes.
||
|| This script replaces the special Windows CP-1252 characters, sometimes problematical,
|| with their equivalent "normal" ISO characters
|| (see http://www.cs.tut.fi/~jkorpela/www/windows-chars.html#subst )
||
|| You can use it when you copy any text to a new message,
|| especially when you copy from a web page or from a Word document
|| that may have such chars.
||
||
||
|| “Don’t write like this”
|| will become
|| "Don't write like this"
||
|| • They only accept florins (ƒ)…
|| will became
|| * They only accept florins (f)...
||
||
||
|| Instructions:
||
|| Just run the script before pasting.
||
|| STEP 1: Copy a text
||
|| STEP 2: Select Dialog main window and run the script
|| (I do that by pressing CTRL-E, the shortcut I assigned to the script),
||
|| STEP 3: Paste the text ib the new message composition window.
||
|| Steps 1 and 3 are the usual steps when you copy and paste.
|| Use step 2 (the script) if you want to "purify" a text containing special chars.
||
|| (Note that you can use the script to "purify" and copy a text
|| to any document, not only Dialog new messages).
||
||
||
|| Installation:
||
|| To use this script, create a new blank script in Custom scripts,
|| then replace with this script
|| (delete the || chars at the beginning of lines, of course),
|| save and compile it.
||
|| It's easier if you define a shortcut or a button to run the script.
|| 1 Pick an Icon for this script,
|| 2 Write a Hint ("PasteSpecial") and close the scripting window,
|| 3 Rightclick on the toolbar in Dialog main window,
|| 4 select Configure buttons/shortcuts,
|| 5 browse to Script - PasteSpecial,
|| 6a define a Shortcut, for instance CTRL-E if you don't use it otherwise,
|| 6b drag the script Icon on the toolbar to create a button.
||
|| To run the script by a shortcut, select Dialog main window first
|| (Alt-Tab frome the Composition window).
||
||
|| Here are the replaced chars
||
|| // ‚ baseline single quote Alt+130 ==> ' apostrophe
||
|| // ƒ florin Alt+131 ==> f
||
|| // „ baseline double quote Alt+132 ==> " quotation mark
||
|| // … ellipsis Alt+133 ==> ... 3 dots
||
|| // † dagger Alt+134 ==> superscript 1: ¹ (assuming use as footnote reference)
||
|| // ‡ double dagger Alt+135 ==> superscript 2: ² (assuming use as footnote reference)
||
|| // ˆ circumflex accent Alt+136 ==> ^ circumflex
||
|| // ‰ permile Alt+137 ==> o/oo
||
|| // Š S Hacek Alt+138 ==> Sh
||
|| // ‹ left single guillemet Alt+139 ==> <
||
|| // Œ OE ligature Alt+140 ==> OE
||
|| // ‘ left single quote Alt+145 ==> ' apostrophe used as single quote
||
|| // ’ right single quote Alt+146 ==> ' apostrophe used as single quote
||
|| // “ left double quote Alt+147 ==> " quotation mark
||
|| // ” right double quote Alt+148 ==> " quotation mark
||
|| // • bullet Alt+149 ==> * asterisk
||
|| // – endash Alt+150 ==> - hyphen
||
|| // — emdash Alt+151 ==> -- 2 hyphens
||
|| // ˜ tilde accent Alt+152 ==> ~ tilde
||
|| // ™ trademark ligature Alt+153 ==> (TM)
||
|| // š s Hacek Alt+154 ==> sh
||
|| // › right single guillemet Alt+155 ==> >
||
|| // œ oe ligature Alt+156 ==> oe
||
|| // Ÿ Y Dieresis Alt+159 ==> Y
||
||
||
|| NB: some symbols can have different meanings according to language/context.
|| You can therefore set the script to behave differently for some newsgroups, e.g. according to language
|| If you want the script to behave in a special way for some English groups, for ecample,
|| write a list of those groups in a text file. See the CONST section in the script.
|| If you want to use more languages modify the "SelectLanguage" Function section accordingly.
||
|| ***********************************************}
||
|| uses
|| Forms,
|| StdCtrls;
||
|| // CONST
||
|| // EnglishGroups = 'C:\Documenti\Short English groups.txt';
|| // ItalianGroups = 'C:\Documenti\Short English groups.txt';
|| // GermanGroups = 'C:\Documenti\Short German groups.txt';
|| // FrenchGroups = 'C:\Documenti\Short German groups.txt';
||
|| TYPE
|| TLanguage = (LGeneral, LEnglish, LItalian, LGerman, LFrench);
|| // TDayTime = (DTMorning, DTDay, DTAfternoon, DTEvening, DTNight);
||
||
|| VAR
|| DummyForm : TForm;
|| DummyMemo : TMemo;
|| DummyEdit : TEdit;
|| HeaderName : String;
|| WithDigit : boolean;
|| s:string;
|| S_Line:string;
|| i:integer;
||
|| 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 FindLanguage(VAR List : TStringList; LanguageFileName: string; NewsHeader : string): boolean;
||
|| begin
|| result := false;
|| list.LoadFromFile(LanguageFileName);
|| try
|| writeln(inttostr(list.indexof(NewsHeader)));
|| Result := list.indexof(NewsHeader) > -1;
|| (* where each line is a newsgroup in the language tested, e.g. English:
|| news.software.readers
|| carlokok.public.pascalscript
|| *)
||
|| except
|| writeln('(error)')
|| end;
|| end;
||
||
|| function SelectLanguage(NewsHeader : String):TLanguage;
||
|| var
|| list: TStringList;
||
||
|| begin
|| writeln(NewsHeader);
|| Result := LGeneral;
|| list := TStringList.Create();
||
|| try
||
|| // IF FindLanguage(List, EnglishGroups, NewsHeader) THEN
|| // Result := LEnglish
|| (*
|| ELSE
|| IF FindLanguage(List, GermanGroups, NewsHeader) THEN
|| Result := LGerman*);
||
|| finally
|| list.free;
|| end;
|| (* or in code option:
|| IF (POS('news.software.readers', NewsHeader) > 0)
|| OR (POS('carlokok.public.pascalscript', NewsHeader) > 0) THEN
|| Result := LEnglish;
|| but it is case sen;sitive in this way ;-)
|| *)
||
|| end;
||
|| BEGIN
|| DummyForm := TForm.Create(Nil);
|| try
|| DummyMemo := TMemo.Create(DummyForm);
|| DummyMemo.Parent := DummyForm;
|| DummyMemo.WordWrap := false;
|| DummyMemo.PasteFromClipBoard;
|| IF DummyMemo.Lines.Count > 0 THEN
|| BEGIN
|| DummyEdit := TEdit.Create(DummyForm);
|| try
|| DummyEdit.Parent := DummyForm;
|| ADo('NewgroupPane');
|| Ado('Copy');
|| DummyEdit.PasteFromClipBoard;
|| IF Pos('(', DummyEdit.Text) > 0 THEN
|| HeaderName := copy(DummyEdit.Text, 1, Pos('(', DummyEdit.Text)-1 )
|| ELSE
|| HeaderName := DummyEdit.Text;
|| HeaderName := trim(headername);
|| WHILE Pos(#9, HeaderName)> 0 DO
|| delete(HeaderName,Pos(#9, HeaderName),1);
|| IF Length(HeaderName) >0 THEN
|| WithDigit := (HeaderName[1] >='0') AND (HeaderName[1] <='9')
|| ELSE
|| WithDigit := false;
|| WHILE WithDigit AND (Length(HeaderName) >0) DO
|| BEGIN
|| Delete(HeaderName, 1, 1);
|| IF Length(HeaderName) >0 THEN
|| WithDigit := (HeaderName[1] >='0') AND (HeaderName[1] <='9')
|| ELSE
|| WithDigit := false;
|| END;
|| WHILE Pos(#9, HeaderName)> 0 DO
|| delete(HeaderName,Pos(#9, HeaderName),1);
||
||
|| s:=DummyMemo.text;
||
|| CASE SelectLanguage(HeaderName) OF
||
|| LGeneral :
||
|| begin
||
|| s:=StringReplace(s,'“','"'); // virgolette inglesi sx con normali
|| s:=stringreplace(s,'”','"'); // virgolette inglesi dx con normali
||
|| // ‚ baseline single quote Alt+130 ==> apostrophe
|| s:=stringreplace(s,'‚',#39);
||
|| // ƒ florin Alt+131 ==> f
|| s:=stringreplace(s,'ƒ','f');
||
|| // „ baseline double quote Alt+132 ==> " quotation mark
|| s:=stringreplace(s,'„','"');
||
|| // … ellipsis Alt+133 ==> ... 3 dots
|| s:=stringreplace(s,'…','...');
||
|| // † dagger Alt+134 ==> superscript 1: ¹ (assuming use as footnote reference)
|| s:=stringreplace(s,'†','¹');
||
|| // ‡ double dagger Alt+135 ==> superscript 2: ² (assuming use as footnote reference)
|| s:=stringreplace(s,'‡','²');
||
|| // ˆ circumflex accent Alt+136 ==> ^ circumflex
|| s:=stringreplace(s,'ˆ','^');
||
|| // ‰ permile Alt+137 ==> o/oo
|| s:=stringreplace(s,'‰','o/oo');
||
|| // Š S Hacek Alt+138 ==> Sh
|| s:=stringreplace(s,'Š','Sh');
||
|| // ‹ left single guillemet Alt+139 ==> <
|| s:=stringreplace(s,'‹','<');
||
|| // Œ OE ligature Alt+140 ==> OE
|| s:=stringreplace(s,'Œ','OE');
||
|| // ‘ left single quote Alt+145 ==> ' apostrophe used as single quote
|| s:=stringreplace(s,'‘',#39);
||
|| // ’ right single quote Alt+146 ==> ' apostrophe used as single quote
|| s:=stringreplace(s,'’',#39);
||
|| // “ left double quote Alt+147 ==> " quotation mark
|| s:=stringreplace(s,'“','"');
||
|| // ” right double quote Alt+148 ==> " quotation mark
|| s:=stringreplace(s,'”','"');
||
|| // • bullet Alt+149 ==> * asterisk
|| s:=stringreplace(s,'•','*');
||
|| // – endash Alt+150 ==> - hyphen
|| s:=stringreplace(s,'–','-');
||
|| // — emdash Alt+151 ==> -- 2 hyphens
|| s:=stringreplace(s,'—','--');
||
|| // ˜ tilde accent Alt+152 ==> ~ tilde
|| s:=stringreplace(s,'˜','~');
||
|| // ™ trademark ligature Alt+153 ==> (TM)
|| s:=stringreplace(s,'™','(TM)');
||
|| // š s Hacek Alt+154 ==> sh
|| s:=stringreplace(s,'š','sh');
||
|| // › right single guillemet Alt+155 ==> >
|| s:=stringreplace(s,'›','>');
||
|| // œ oe ligature Alt+156 ==> oe
|| s:=stringreplace(s,'œ','oe');
||
|| // Ÿ Y Dieresis Alt+159 ==> Y
|| s:=stringreplace(s,'Ÿ','Y');
||
||
|| end;
||
||
|| LEnglish :
||
|| begin
||
|| // insert chars replace commands here
||
|| end;
||
||
|| // LItalian :
|| // insert chars replace commands here
||
|| // LGerman :
|| // insert chars replace commands here
||
|| // LFrench :
|| // insert chars replace commands here
||
|| END;
||
|| DummyMemo.text:=s;
||
|| // no empty lines
|| for i:=0 to DummyMemo.Lines.count-1 do
|| begin
|| S_Line:=DummyMemo.lines.strings[i];
||
|| S_Line:=stringreplace(S_Line,' ','');
|| S_Line:=stringreplace(S_Line,#09,'');
||
|| if S_Line='' then DummyMemo.lines.strings[i]:=S_Line;
|| end;
||
||
||
|| DummyMemo.SelectAll;
|| DummyMemo.CopyToClipBoard;
|| beep;
|| finally
|| writeln('1');
|| dummyedit.free;
|| end;
|| END;
|| finally
|| beep;
|| writeln('2');
|| DummyForm.Free
|| end
||
|| END.
Technical Details
Message-ID:
<9jcrumhmvseu.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!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!news.moat.net!newsfeed.mesh.ad.jp!newsfeed.media.kyoto-u.ac.jp!x-privat.org!not-for-mailReferences:
<1xln9aej5brbh.dlg@news.lillathedog.net> <3yf8op1yopkl.dlg@news.lillathedog.net> <1p6lqwj6qdddf.dlg@tarkus.karnevil9.com>Show Full Headers
Complete Article Headers
Message-ID: <9jcrumhmvseu.dlg@news.lillathedog.net>
Subject: Re: [Dialog] A script that substitutes problematical win chars
Date: Thu, 30 Dec 2004 00:56:18 +0000
From: Enrico C <use_replyto_address@despammed.com>
References: <1xln9aej5brbh.dlg@news.lillathedog.net> <3yf8op1yopkl.dlg@news.lillathedog.net> <1p6lqwj6qdddf.dlg@tarkus.karnevil9.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!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!news.moat.net!newsfeed.mesh.ad.jp!newsfeed.media.kyoto-u.ac.jp!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
X-Face: ^o~FP:1J&VVuw0s!7#|FI{U^k0Y@l`vtAIZwT&X#_iF<KDE`_QC3Hh&.k{f,
r'(2F3.-qo^
z>tB)vqIb2&[mberaB%lw6MRk/|p5@A:X4ZTI$\6[#%k:pA_LQ{ZZ=@^Ci$Y'd"xWHNB\kNg1R
NNTP-Posting-Host: $$6drnk_$xjnxn9.x-privat.org
Organization: X-Privat NNTP Server - http://www.x-privat.org
Lines: 444
X-Authenticated-User: $$t9dw0m0cxnc-vpzkjjlef
X-Complaints-To: abuse@x-privat.org