Thread View: news.software.readers
7 messages
7 total messages
Started by Enrico C
Tue, 28 Dec 2004 00:08
[Dialog] A script that substitutes problematical win chars
Author: Enrico C
Date: Tue, 28 Dec 2004 00:08
Date: Tue, 28 Dec 2004 00:08
109 lines
4381 bytes
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.
Re: [Dialog] A script that substitutes problematical win chars
Author: Scott Marquardt
Date: Tue, 28 Dec 2004 15:43
Date: Tue, 28 Dec 2004 15:43
19 lines
2130 bytes
2130 bytes
Enrico C opined thusly on Dec 27: > 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 I have a similar script that replaced all kinds of stuff, but it hasn't been working at all for the last many weeks. Can't figure why. Scripting is just broken. I'll wager it's something to do with 2.0.14.1. Latest beta to public! :-) -- Scott 12/28/2004 9:34:49 AM
Re: [Dialog] A script that substitutes problematical win chars
Author: Enrico C
Date: Wed, 29 Dec 2004 10:46
Date: Wed, 29 Dec 2004 10:46
411 lines
15769 bytes
15769 bytes
On 28 Dec 2004 01:08:08 +0100, Enrico C wrote:
> 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.
> That means, for instance, replacing “ and ” with " , ’ with ' , and so
> on.
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.
To make it, I combined two existing scripts. Thank you very much to their
authors! :)
|| Program PasteSpecial;
||
|| {**********************************************
|| PasteSpecial 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.
||
||
|| 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"
||
||
|| 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 in 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 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;
||
||
|| 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;
|| DummyMemo.SelectAll;
|| DummyMemo.CopyToClipBoard;
|| beep;
|| finally
|| writeln('1');
|| dummyedit.free;
|| end;
|| END;
|| finally
|| beep;
|| writeln('2');
|| DummyForm.Free
|| end
||
|| END.
Re: [Dialog] A script that substitutes problematical win chars
Author: Enrico C
Date: Wed, 29 Dec 2004 11:15
Date: Wed, 29 Dec 2004 11:15
415 lines
15855 bytes
15855 bytes
On 28 Dec 2004 01:08:08 +0100, Enrico C wrote:
> 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.
> That means, for instance, replacing “ and ” with " , ’ with ' , and so
> on.
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.
To make it, I combined two existing scripts. Thank you very much to their
authors! :)
|| Program PasteSpecial;
||
|| {**********************************************
|| PasteSpecial 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.
||
||
|| 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 in 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 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;
||
||
|| 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;
|| DummyMemo.SelectAll;
|| DummyMemo.CopyToClipBoard;
|| beep;
|| finally
|| writeln('1');
|| dummyedit.free;
|| end;
|| END;
|| finally
|| beep;
|| writeln('2');
|| DummyForm.Free
|| end
||
|| END.
Re: [Dialog] A script that substitutes problematical win chars
Author: Tarkus
Date: Wed, 29 Dec 2004 18:11
Date: Wed, 29 Dec 2004 18:11
18 lines
2104 bytes
2104 bytes
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. Any chance of adding code to delete extra blank lines? Also, extra lines with nothing but spaces or tabs? -- "I'm trying to free your mind, Neo. But I can only show you the door. You're the one that has to walk through it."
Re: [Dialog] A script that substitutes problematical win chars
Author: 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.
Re: [Dialog] A script that substitutes problematical win chars
Author: Tarkus
Date: Thu, 30 Dec 2004 17:07
Date: Thu, 30 Dec 2004 17:07
15 lines
1836 bytes
1836 bytes
On 12/29/2004 4:56:18 PM, Enrico C wrote: > For now, let's get rid of those redundant spaces and tabs ;) Thanks. Now, about those extra blank lines..... :) -- "I went down the street to the 24-hour grocery. When I got there, the guy was locking the front door. I said, 'Hey, the sign says you're open 24 hours.' He said, 'Yes, but not in a row.'" - Steven Wright
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads