From 92c33dc1ee9b0ee4d706621711f47c2c8ae94477 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 26 Sep 2018 22:57:28 +0000 Subject: [PATCH] jvcllaz: Add new package JvNetLazR/D (html etc). Add demo HTMLParser. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6658 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../jvcllaz/design/JvNet/Images/images.txt | 4 + .../jvcllaz/design/JvNet/Images/make_res.bat | 1 + .../design/JvNet/Images/tjvformtohtml.bmp | Bin 0 -> 1654 bytes .../design/JvNet/Images/tjvhtmlparser.bmp | Bin 0 -> 1654 bytes .../jvcllaz/design/JvNet/Images/tjvmail.bmp | Bin 0 -> 1654 bytes .../design/JvNet/Images/tjvrgbtohtml.bmp | Bin 0 -> 1654 bytes .../JvNet/Images/tjvstringlisttohtml.bmp | Bin 0 -> 1654 bytes .../design/JvNet/Images/tjvstrtohtml.bmp | Bin 0 -> 1654 bytes components/jvcllaz/design/JvNet/jvnetreg.pas | 27 + .../JvDialButton/JvDialButtonDemo.lpi | 3 + .../JvHTMLParser/JvHTMLParserMainFormU.lfm | 263 ++++++++++ .../JvHTMLParser/JvHTMLParserMainFormU.pas | 299 +++++++++++ .../JvHTMLParser/JvHtmlParserProj.lpi | 85 +++ .../JvHTMLParser/JvHtmlParserProj.lpr | 16 + .../jvcllaz/examples/JvHTMLParser/sample.htm | 61 +++ .../jvcllaz/examples/JvHTMLParser/sample2.htm | 61 +++ .../jvcllaz/examples/JvLED/JvLEDDemo.lpi | 3 + components/jvcllaz/examples/JvLED/LEDMain.lfm | 1 + components/jvcllaz/packages/jvnetlazd.lpk | 43 ++ components/jvcllaz/packages/jvnetlazr.lpk | 49 ++ components/jvcllaz/resource/jvnet.res | Bin 0 -> 6828 bytes components/jvcllaz/run/JvNet/jvformtohtml.pas | 259 +++++++++ components/jvcllaz/run/JvNet/jvhtmlparser.pas | 483 +++++++++++++++++ .../jvcllaz/run/JvNet/jvstringlisttohtml.pas | 160 ++++++ components/jvcllaz/run/JvNet/jvstrtohtml.pas | 492 ++++++++++++++++++ 25 files changed, 2310 insertions(+) create mode 100644 components/jvcllaz/design/JvNet/Images/images.txt create mode 100644 components/jvcllaz/design/JvNet/Images/make_res.bat create mode 100644 components/jvcllaz/design/JvNet/Images/tjvformtohtml.bmp create mode 100644 components/jvcllaz/design/JvNet/Images/tjvhtmlparser.bmp create mode 100644 components/jvcllaz/design/JvNet/Images/tjvmail.bmp create mode 100644 components/jvcllaz/design/JvNet/Images/tjvrgbtohtml.bmp create mode 100644 components/jvcllaz/design/JvNet/Images/tjvstringlisttohtml.bmp create mode 100644 components/jvcllaz/design/JvNet/Images/tjvstrtohtml.bmp create mode 100644 components/jvcllaz/design/JvNet/jvnetreg.pas create mode 100644 components/jvcllaz/examples/JvHTMLParser/JvHTMLParserMainFormU.lfm create mode 100644 components/jvcllaz/examples/JvHTMLParser/JvHTMLParserMainFormU.pas create mode 100644 components/jvcllaz/examples/JvHTMLParser/JvHtmlParserProj.lpi create mode 100644 components/jvcllaz/examples/JvHTMLParser/JvHtmlParserProj.lpr create mode 100644 components/jvcllaz/examples/JvHTMLParser/sample.htm create mode 100644 components/jvcllaz/examples/JvHTMLParser/sample2.htm create mode 100644 components/jvcllaz/packages/jvnetlazd.lpk create mode 100644 components/jvcllaz/packages/jvnetlazr.lpk create mode 100644 components/jvcllaz/resource/jvnet.res create mode 100644 components/jvcllaz/run/JvNet/jvformtohtml.pas create mode 100644 components/jvcllaz/run/JvNet/jvhtmlparser.pas create mode 100644 components/jvcllaz/run/JvNet/jvstringlisttohtml.pas create mode 100644 components/jvcllaz/run/JvNet/jvstrtohtml.pas diff --git a/components/jvcllaz/design/JvNet/Images/images.txt b/components/jvcllaz/design/JvNet/Images/images.txt new file mode 100644 index 000000000..90f34d4de --- /dev/null +++ b/components/jvcllaz/design/JvNet/Images/images.txt @@ -0,0 +1,4 @@ +tjvhtmlparser.bmp +tjvformtohtml.bmp +tjvstringlisttohtml.bmp +tjvstrtohtml.bmp \ No newline at end of file diff --git a/components/jvcllaz/design/JvNet/Images/make_res.bat b/components/jvcllaz/design/JvNet/Images/make_res.bat new file mode 100644 index 000000000..eb9f509ab --- /dev/null +++ b/components/jvcllaz/design/JvNet/Images/make_res.bat @@ -0,0 +1 @@ +lazres ../../../resource/jvnet.res @images.txt diff --git a/components/jvcllaz/design/JvNet/Images/tjvformtohtml.bmp b/components/jvcllaz/design/JvNet/Images/tjvformtohtml.bmp new file mode 100644 index 0000000000000000000000000000000000000000..8abcffafc193a8c391c4584cdcc72c22ef273307 GIT binary patch literal 1654 zcmeH_!I8o+3`G?yvBQ`GC}AtuGsB%8QU&LfLMblAC2-#Zd`Whk%)s86$tObM`O63m zm+Q@w>bEEQL3Jw8(Ww0FG}&8+gn0ZtiJpj@5lKtRcS@|ZM_bPDgW_=Z r@hdOX>f*--^=kg)7f1D@misl3{+lPX`8RWh_y1@PA=K5ij0L>_=M5t+ literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvNet/Images/tjvhtmlparser.bmp b/components/jvcllaz/design/JvNet/Images/tjvhtmlparser.bmp new file mode 100644 index 0000000000000000000000000000000000000000..8ef224f65b46de7fcda80d756ff7670ae6f235aa GIT binary patch literal 1654 zcmeH^O;Us~5QUqBgkcaPXrV{&1g5w0^+`FJFo%DR~ zrK`!jzP)SWcqxgVQ9bQh(1rOZ`0!hS1G#OR+lbZ`X}SFR{6M`BSuks{W*Y56<6>!E z+=-kQnrH9{^@MYDIgzE6(2WD~8RrX}FYu3F;6Y}gwJslhWE3UyqJVVd5`IuDaS-%< z-{z3wIu@? z>C+oiBUvNOkDtGuWVG*}MZVGddhsA%M%_M*n1=^qFTzg%%SYQxwbQ2qX$Ur>0689Dzik=d?{pgCmeA^n4|*q`?tL6neg{P}1NCBnmxW zWh!ZK1QLawuep>oI0A`6k56E&q`?tL6k3A$hbWerJC-d`XbBZ4430pe(DSpIk_Ja0 zQRw+eT}gu@kSO&0-26#|!4XIldM<@j(%=Xr3O$!eDQR#75``X1C|XH_BakSx6!R}p z7#xAbvh`eAs-(dYNECW5J5$o&2qX$Um!vCca0C*Cp360qG&ll@LeHg~N*Wx2M4{(0 zFC`6*K+4POS&obg?k92{yPVHU4{S?`!=J;d?f3h)r`c9jx}*O3%BgMrz<8?c&vz%T z^}7?}{>%91?TKrh=Uca1ou^&3kLP?|X0d8-mv*ajw`H<3_P6@#qO)x4WAwOeTfbf+ zhs}L%II&mbA$K!e2XVzzx{^R4dKE{2Fztt%(*DP&2e*7NQb$txn9^|mQ UJo8-~c00bzU0Xiw?ms8q0i8~DasU7T literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvNet/Images/tjvrgbtohtml.bmp b/components/jvcllaz/design/JvNet/Images/tjvrgbtohtml.bmp new file mode 100644 index 0000000000000000000000000000000000000000..dbf98f3e13d6edb16038e1065d9bfc2a0dcd96ba GIT binary patch literal 1654 zcmeH@!41P83`Grr$lahLbb_9%-n&lE8Kt8z3Y(-K8wb-7s#p-C_rI~j^Yvay;+}|Z zI9>Y=#KIp@l70eG+xt#bD|V41)eljrRHzaZiEZnLGo3GRzQA9-z#3hol$MKzqc{pD zf)qKnWgC7_tT6L9IJ5JEBg7x<4rKNmSD^+~Z5{rAa6{Rg4SQkfpuRZOQ~C03T~X^IO6AblmPKN0>i)=<&k@j7|G&*uf9ju zb?B~FL=3nbj}VK9c-7j0wFCdK1Ft?)RaM)4k`FM{7nni&#ok)^7b$JrfH@Y IO#%CG15HXX(EtDd literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvNet/Images/tjvstrtohtml.bmp b/components/jvcllaz/design/JvNet/Images/tjvstrtohtml.bmp new file mode 100644 index 0000000000000000000000000000000000000000..e9e507e009719e9d697e6f87b93760377232ee2f GIT binary patch literal 1654 zcmeH@%@G124244$9PGdntiZG5-F7^0DVDOO(8>Dp0~=a!HWJBv?*+2F-k%F;JTlQ8 z)y*?eRsLk%>@Q)H+;^hZkeim&zC>H2jT%AGSXVF3?RegQ61qTQW SA$Bf$zS1EoFC|#Lgzy8q + + + diff --git a/components/jvcllaz/examples/JvHTMLParser/JvHTMLParserMainFormU.lfm b/components/jvcllaz/examples/JvHTMLParser/JvHTMLParserMainFormU.lfm new file mode 100644 index 000000000..84048bf10 --- /dev/null +++ b/components/jvcllaz/examples/JvHTMLParser/JvHTMLParserMainFormU.lfm @@ -0,0 +1,263 @@ +object JvHTMLParserMainForm: TJvHTMLParserMainForm + Left = 365 + Height = 530 + Top = 143 + Width = 684 + Caption = 'JvHtmlParser DEMO' + ClientHeight = 530 + ClientWidth = 684 + Color = clBtnFace + Constraints.MinHeight = 200 + Constraints.MinWidth = 300 + DefaultMonitor = dmDesktop + Font.Color = clWindowText + OnCreate = FormCreate + Position = poScreenCenter + LCLVersion = '2.1.0.0' + Scaled = False + object PageControl1: TPageControl + Left = 0 + Height = 507 + Top = 0 + Width = 684 + ActivePage = TabSheet1 + Align = alClient + ParentShowHint = False + ShowHint = True + TabIndex = 0 + TabOrder = 0 + object TabSheet1: TTabSheet + Hint = 'Table Demo' + Caption = 'Table' + ClientHeight = 479 + ClientWidth = 676 + object JvSplitter1: TSplitter + Cursor = crVSplit + Left = 0 + Height = 4 + Top = 189 + Width = 676 + Align = alTop + ResizeAnchor = akTop + end + object TreeView1: TTreeView + Left = 0 + Height = 189 + Top = 0 + Width = 676 + Align = alTop + Indent = 19 + ReadOnly = True + ScrollBars = ssAutoBoth + TabOrder = 0 + Options = [tvoAutoItemHeight, tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw] + end + object DisplayMemo1: TMemo + Left = 0 + Height = 252 + Top = 193 + Width = 676 + Align = alClient + ReadOnly = True + ScrollBars = ssAutoBoth + TabOrder = 1 + WordWrap = False + end + object Panel1: TPanel + Left = 0 + Height = 34 + Top = 445 + Width = 676 + Align = alBottom + AutoSize = True + BevelOuter = bvNone + ClientHeight = 34 + ClientWidth = 676 + TabOrder = 2 + object btnProcessTable: TButton + AnchorSideTop.Control = Panel1 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = Panel1 + AnchorSideRight.Side = asrBottom + Left = 606 + Height = 25 + Top = 5 + Width = 66 + Anchors = [akTop, akRight] + AutoSize = True + BorderSpacing.Around = 4 + Caption = 'Execute' + OnClick = btnProcessTableClick + TabOrder = 0 + end + object btnOpen: TButton + AnchorSideLeft.Control = Panel1 + AnchorSideTop.Control = Panel1 + AnchorSideTop.Side = asrCenter + Left = 4 + Height = 25 + Top = 5 + Width = 64 + AutoSize = True + BorderSpacing.Around = 4 + Caption = '&Open...' + OnClick = btnOpenClick + TabOrder = 1 + end + end + end + object TabSheet2: TTabSheet + Hint = 'HTML to text converter' + Caption = 'HTML2Text' + ClientHeight = 479 + ClientWidth = 676 + ImageIndex = 1 + object DisplayMemo2: TMemo + Left = 0 + Height = 445 + Top = 0 + Width = 676 + Align = alClient + ReadOnly = True + ScrollBars = ssAutoBoth + TabOrder = 0 + end + object Panel2: TPanel + Left = 0 + Height = 34 + Top = 445 + Width = 676 + Align = alBottom + AutoSize = True + BevelOuter = bvNone + ClientHeight = 34 + ClientWidth = 676 + TabOrder = 1 + object btnProcessHTML2Text: TButton + AnchorSideTop.Control = Panel2 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = Panel2 + AnchorSideRight.Side = asrBottom + Left = 606 + Height = 25 + Top = 5 + Width = 66 + Anchors = [akTop, akRight] + AutoSize = True + BorderSpacing.Around = 4 + Caption = 'Execute' + OnClick = btnProcessHTML2TextClick + TabOrder = 0 + end + end + end + object TabSheet3: TTabSheet + Hint = 'Simple URL detector' + Caption = 'URL detect' + ClientHeight = 479 + ClientWidth = 676 + ImageIndex = 2 + object DisplayMemo3: TMemo + Left = 0 + Height = 445 + Top = 0 + Width = 676 + Align = alClient + ReadOnly = True + ScrollBars = ssAutoBoth + TabOrder = 0 + end + object Panel3: TPanel + Left = 0 + Height = 34 + Top = 445 + Width = 676 + Align = alBottom + AutoSize = True + BevelOuter = bvNone + ClientHeight = 34 + ClientWidth = 676 + TabOrder = 1 + object btnProcessURL: TButton + AnchorSideTop.Control = Panel3 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = Panel3 + AnchorSideRight.Side = asrBottom + Left = 606 + Height = 25 + Top = 5 + Width = 66 + Anchors = [akTop, akRight] + AutoSize = True + BorderSpacing.Around = 4 + Caption = 'Execute' + OnClick = btnProcessURLClick + TabOrder = 0 + end + end + end + object TabSheet4: TTabSheet + Hint = 'Tags detector' + Caption = 'Tags' + ClientHeight = 479 + ClientWidth = 676 + ImageIndex = 3 + object DisplayMemo4: TMemo + Left = 0 + Height = 445 + Top = 0 + Width = 676 + Align = alClient + ReadOnly = True + ScrollBars = ssAutoBoth + TabOrder = 0 + end + object Panel4: TPanel + Left = 0 + Height = 34 + Top = 445 + Width = 676 + Align = alBottom + AutoSize = True + BevelOuter = bvNone + ClientHeight = 34 + ClientWidth = 676 + TabOrder = 1 + object btnProcessTags: TButton + AnchorSideTop.Control = Panel4 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = Panel4 + AnchorSideRight.Side = asrBottom + Left = 606 + Height = 25 + Top = 5 + Width = 66 + Anchors = [akTop, akRight] + AutoSize = True + BorderSpacing.Around = 4 + Caption = 'Execute' + OnClick = btnProcessTagsClick + TabOrder = 0 + end + end + end + end + object StatusBar1: TStatusBar + Left = 0 + Height = 23 + Top = 507 + Width = 684 + Panels = <> + end + object JvHtmlParser1: TJvHTMLParser + FileName = 'data\sample.htm' + left = 224 + top = 72 + end + object OpenDialog1: TOpenDialog + Filter = 'HTML files|*.htm;*.html;*.htt|All files|*.*' + InitialDir = '.' + left = 336 + top = 72 + end +end diff --git a/components/jvcllaz/examples/JvHTMLParser/JvHTMLParserMainFormU.pas b/components/jvcllaz/examples/JvHTMLParser/JvHTMLParserMainFormU.pas new file mode 100644 index 000000000..a102dd4de --- /dev/null +++ b/components/jvcllaz/examples/JvHTMLParser/JvHTMLParserMainFormU.pas @@ -0,0 +1,299 @@ +{****************************************************************** + + JEDI-VCL Demo + + Copyright (C) 2002 Project JEDI + + Original author: + + Contributor(s): + + You may retrieve the latest version of this file at the JEDI-JVCL + home page, located at http://jvcl.delphi-jedi.org + + The contents of this file are used with permission, subject to + the Mozilla Public License Version 1.1 (the "License"); you may + not use this file except in compliance with the License. You may + obtain a copy of the License at + http://www.mozilla.org/MPL/MPL-1_1Final.html + + Software distributed under the License is distributed on an + "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + implied. See the License for the specific language governing + rights and limitations under the License. + +******************************************************************} + +unit JvHTMLParserMainFormU; + +{$mode objfpc}{$H+} + +interface + +uses + //Windows, Messages, + Forms, SysUtils, Classes, Controls, StdCtrls, ExtCtrls, ComCtrls, Dialogs, + JvHtmlParser; + +type + TJvHTMLParserMainForm = class(TForm) + PageControl1: TPageControl; + TabSheet1: TTabSheet; + TabSheet2: TTabSheet; + TabSheet3: TTabSheet; + TreeView1: TTreeView; + StatusBar1: TStatusBar; + TabSheet4: TTabSheet; + JvSplitter1: TSplitter; + DisplayMemo1: TMemo; + Panel1: TPanel; + btnProcessTable: TButton; + JvHtmlParser1: TJvHtmlParser; + DisplayMemo2: TMemo; + DisplayMemo3: TMemo; + DisplayMemo4: TMemo; + Panel2: TPanel; + btnProcessHTML2Text: TButton; + Panel3: TPanel; + btnProcessURL: TButton; + Panel4: TPanel; + btnProcessTags: TButton; + btnOpen: TButton; + OpenDialog1: TOpenDialog; + procedure btnProcessTableClick(Sender: TObject); + procedure TableKeyFound(Sender: TObject; Key, Results, OriginalLine: string); + procedure TableKeyFoundEx(Sender: TObject; Key, Results, + OriginalLine: String; TagInfo: TTagInfo; Attributes: TStrings); + procedure HTML2TextKeyFound(Sender: TObject; Key, Results, OriginalLine: string); + procedure URLDetectKeyFound(Sender: TObject; Key, Results, OriginalLine: string); + procedure TagsKeyFound(Sender: TObject; Key, Results, OriginalLine: string); + procedure btnProcessHTML2TextClick(Sender: TObject); + procedure btnProcessURLClick(Sender: TObject); + procedure btnProcessTagsClick(Sender: TObject); + procedure btnOpenClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + private + CurNode: TTreeNode; + FText: string; + FStartTime: TTime; + public + function ReplaceSpecials(Str: string): string; + procedure ShowStatus(t: TTime); + procedure DoKeyFoundEx(Sender: TObject; Key, Results, OriginalLine: string; TagInfo:TTagInfo; Attributes:TStrings); + end; + +var + JvHTMLParserMainForm: TJvHTMLParserMainForm; + +implementation + +uses + StrUtils; + + { +uses + JclStrings; + } +{$R *.lfm} + +procedure TJvHTMLParserMainForm.btnProcessTableClick(Sender: TObject); +begin + Screen.Cursor := crHourGlass; + Self.Tag := 0; + FStartTime := Now(); + with JvHtmlParser1 do + begin + ClearConditions; + AddCondition('TD', '', ''); + AddCondition('TH', '', ''); + AddCondition('TR', '', ''); +// OnKeyFound := TableKeyFound; + OnKeyFoundEx := @TableKeyFoundEx; + end; + TreeView1.Items.BeginUpdate; + DisplayMemo1.Lines.BeginUpdate; + try + DisplayMemo1.Clear; + JvHtmlParser1.AnalyseFile; + ShowStatus(Now() - FStartTime); + finally + TreeView1.Items.EndUpdate; + DisplayMemo1.Lines.EndUpdate; + Screen.Cursor := crDefault; + end; +end; + +procedure TJvHTMLParserMainForm.btnProcessHTML2TextClick(Sender: TObject); +begin + Screen.Cursor := crHourGlass; + Self.Tag := 0; + FStartTime := Now(); + with JvHtmlParser1 do + begin + ClearConditions; + AddCondition('Text', '>', '<'); + OnKeyFound := @HTML2TextKeyFound; + end; + DisplayMemo2.Lines.BeginUpdate; + try + DisplayMemo2.Clear; + JvHtmlParser1.AnalyseFile; + ShowStatus(Now() - FStartTime); + DisplayMemo2.Text := ReplaceSpecials(FText); + finally + FText := ''; + DisplayMemo2.Lines.EndUpdate; + Screen.Cursor := crDefault; + end; +end; + +procedure TJvHTMLParserMainForm.btnProcessURLClick(Sender: TObject); +begin + Screen.Cursor := crHourGlass; + Self.Tag := 0; + FStartTime := Now(); + with JvHtmlParser1 do + begin + ClearConditions; + AddCondition('URL', 'href=http://', '>'); + AddCondition('URL', 'href="http://', '">'); + OnKeyFound := @URLDetectKeyFound; + end; + DisplayMemo3.Lines.BeginUpdate; + try + DisplayMemo3.Clear; + JvHtmlParser1.AnalyseFile; + ShowStatus(Now() - FStartTime); + finally + DisplayMemo3.Lines.EndUpdate; + Screen.Cursor := crDefault; + end; +end; + +procedure TJvHTMLParserMainForm.btnProcessTagsClick(Sender: TObject); +begin + Screen.Cursor := crHourGlass; + Self.Tag := 0; + FStartTime := Now(); + with JvHtmlParser1 do + begin + ClearConditions; + AddCondition('URL', '<', '>'); + OnKeyFound := nil; + OnKeyFoundEx := @DoKeyFoundEx; + end; + DisplayMemo4.Lines.BeginUpdate; + try + DisplayMemo4.Clear; + JvHtmlParser1.AnalyseFile; + ShowStatus(Now() - FStartTime); + finally + DisplayMemo4.Lines.EndUpdate; + Screen.Cursor := crDefault; + end; +end; + +procedure TJvHTMLParserMainForm.TableKeyFound(Sender: TObject; Key, Results, + OriginalLine: string); +begin + Self.Tag := Self.Tag + 1; + DisplayMemo1.Lines.Add(Key + #13#10 + Results); + if UpperCase(Key) = 'TR' then + CurNode := TreeView1.Items.AddChild(nil, 'TR') + else + TreeView1.Items.AddChild(CurNode, Results); +end; + +procedure TJvHTMLParserMainForm.TableKeyFoundEx(Sender: TObject; + Key, Results, OriginalLine: String; TagInfo: TTagInfo; + Attributes: TStrings); +var + i : integer; +begin + Self.Tag := Self.Tag + 1; + DisplayMemo1.Lines.Add(Key + #13#10 + Results); + for i:=0 to Attributes.Count-1 do + DisplayMemo1.Lines.Add('Attributes=' + Attributes[i]); + if UpperCase(Key) = 'TR' then + CurNode := TreeView1.Items.AddChild(nil, 'TR') + else + TreeView1.Items.AddChild(CurNode, Results); +end; + +procedure TJvHTMLParserMainForm.HTML2TextKeyFound(Sender: TObject; Key, Results, + OriginalLine: string); +begin + //this is only for sample! + Self.Tag := Self.Tag + 1; + if (FText <> '') and (FText[Length(FText)] <> ' ') then + FText := FText + ' '; + FText := FText + Results; +end; + +procedure TJvHTMLParserMainForm.URLDetectKeyFound(Sender: TObject; Key, Results, + OriginalLine: string); +begin + Self.Tag := Self.Tag + 1; + DisplayMemo3.Lines.Add('http://' + Results); +end; + +procedure TJvHTMLParserMainForm.TagsKeyFound(Sender: TObject; Key, Results, + OriginalLine: string); +begin + Self.Tag := Self.Tag + 1; + DisplayMemo4.Lines.Add('<' + Results + '>'); +end; + +procedure TJvHTMLParserMainForm.ShowStatus(t: TTime); +var + h, m, s, ms: Word; +begin + DecodeTime(t, h, m, s, ms); + StatusBar1.SimpleText := + Format('%d tags are processed for period: %0.2d:%0.2d:%0.2d.%0.3d', + [Self.Tag, h, m, s, ms]); +end; + +function TJvHTMLParserMainForm.ReplaceSpecials(Str: string): string; +begin + Result := Str; + Result := StringReplace(Result, '>', '>', [rfReplaceAll, rfIgnoreCase]); + Result := StringReplace(Result, '<', '<', [rfReplaceAll, rfIgnoreCase]); + Result := StringReplace(Result, '&', '&', [rfReplaceAll, rfIgnoreCase]); + Result := StringReplace(Result, ' ', ' ', [rfReplaceAll, rfIgnoreCase]); + Result := StringReplace(Result, '"', '"', [rfReplaceAll, rfIgnoreCase]); + Result := StringReplace(Result, '©', #169, [rfReplaceAll, rfIgnoreCase]); + // add more here... +end; + +procedure TJvHTMLParserMainForm.btnOpenClick(Sender: TObject); +var + I: Integer; +begin + if OpenDialog1.Execute then + begin + JvHtmlParser1.FileName := OpenDialog1.FileName; + for I := 0 to ComponentCount - 1 do + if (Components[I] <> btnOpen) and (Components[I] is TButton) then + TButton(Components[I]).OnClick(nil); + end; +end; + +procedure TJvHTMLParserMainForm.FormCreate(Sender: TObject); +begin + JvHtmlParser1.OnKeyFoundEx := @DoKeyFoundEx; +end; + +procedure TJvHTMLParserMainForm.DoKeyFoundEx(Sender: TObject; Key, Results, + OriginalLine: string; TagInfo: TTagInfo; Attributes: TStrings); +begin + Self.Tag := Self.Tag + 1; + DisplayMemo4.Lines.Add('<' + Results + '>'); + if Attributes.Count > 0 then + begin + DisplayMemo4.Lines.Add('Attributes:'); + DisplayMemo4.Lines.AddStrings(Attributes); + end; +end; + +end. diff --git a/components/jvcllaz/examples/JvHTMLParser/JvHtmlParserProj.lpi b/components/jvcllaz/examples/JvHTMLParser/JvHtmlParserProj.lpi new file mode 100644 index 000000000..f1c0e694a --- /dev/null +++ b/components/jvcllaz/examples/JvHTMLParser/JvHtmlParserProj.lpi @@ -0,0 +1,85 @@ + + + + + + + + + + <Scaled Value="True"/> + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <XPManifest> + <DpiAware Value="True"/> + </XPManifest> + <Icon Value="0"/> + </General> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + <UseFileFilters Value="True"/> + </PublishOptions> + <RunParams> + <FormatVersion Value="2"/> + <Modes Count="0"/> + </RunParams> + <RequiredPackages Count="2"> + <Item1> + <PackageName Value="JvNetLazR"/> + </Item1> + <Item2> + <PackageName Value="LCL"/> + </Item2> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="JvHtmlParserProj.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="JvHTMLParserMainFormU.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="JvHTMLParserMainForm"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <PathDelim Value="\"/> + <Target> + <Filename Value="..\..\bin\JvHtmlParserProj"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Debugging> + <UseExternalDbgSyms Value="True"/> + </Debugging> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/components/jvcllaz/examples/JvHTMLParser/JvHtmlParserProj.lpr b/components/jvcllaz/examples/JvHTMLParser/JvHtmlParserProj.lpr new file mode 100644 index 000000000..70ad73ef8 --- /dev/null +++ b/components/jvcllaz/examples/JvHTMLParser/JvHtmlParserProj.lpr @@ -0,0 +1,16 @@ +program JvHtmlParserProj; + +uses + Interfaces, Forms, + JvHTMLParserMainFormU in 'JvHTMLParserMainFormU.pas' {JvHTMLParserMainForm}; + +{$R *.res} + +begin + Application.Scaled:=True; + Application.Initialize; + Application.Title:='JvHtmlParserProj'; + Application.CreateForm(TJvHTMLParserMainForm, JvHTMLParserMainForm); + Application.Run; +end. + diff --git a/components/jvcllaz/examples/JvHTMLParser/sample.htm b/components/jvcllaz/examples/JvHTMLParser/sample.htm new file mode 100644 index 000000000..8be303f8a --- /dev/null +++ b/components/jvcllaz/examples/JvHTMLParser/sample.htm @@ -0,0 +1,61 @@ +<html> +<body> +<h2>This is a JvHtmlParser Demo</h2><br> +<Table Width="100%" Border=1 BgColor="#ffffcc"> +<TR><TH>EmpNo</TH><TH>LastName</TH><TH>FirstName</TH><TH>PhoneExt</TH><TH>HireDate</TH><TH>Salary</TH></TR> +<TR><TD>2</TD><TD>Nelson</TD><TD>Roberto</TD><TD>250</TD><TD>28.12.1988</TD><TD>40000</TD></TR> +<TR><TD>4</TD><TD>Young</TD><TD>Bruce</TD><TD>233</TD><TD>28.12.1988</TD><TD>55500</TD></TR> +<TR><TD>5</TD><TD>Lambert</TD><TD>Kim</TD><TD>22</TD><TD>06.02.1989</TD><TD>25000</TD></TR> +<TR><TD>8</TD><TD>Johnson</TD><TD>Leslie</TD><TD>410</TD><TD>05.04.1989</TD><TD>25050</TD></TR> +<TR><TD>9</TD><TD>Forest</TD><TD>Phil</TD><TD>229</TD><TD>17.04.1989</TD><TD>25050</TD></TR> +<TR><TD>11</TD><TD>Weston</TD><TD>K. J.</TD><TD>34</TD><TD>17.01.1990</TD><TD>33292,9375</TD></TR> +<TR><TD>12</TD><TD>Lee</TD><TD>Terri</TD><TD>256</TD><TD>01.05.1990</TD><TD>45332</TD></TR> +<TR><TD>14</TD><TD>Hall</TD><TD>Stewart</TD><TD>227</TD><TD>04.06.1990</TD><TD>34482,625</TD></TR> +<TR><TD>15</TD><TD>Young</TD><TD>Katherine</TD><TD>231</TD><TD>14.06.1990</TD><TD>24400</TD></TR> +<TR><TD>20</TD><TD>Papadopoulos</TD><TD>Chris</TD><TD>887</TD><TD>01.01.1990</TD><TD>25050</TD></TR> +<TR><TD>24</TD><TD>Fisher</TD><TD>Pete</TD><TD>888</TD><TD>12.09.1990</TD><TD>23040</TD></TR> +<TR><TD>28</TD><TD>Bennet</TD><TD>Ann</TD><TD>5</TD><TD>01.02.1991</TD><TD>34482,8</TD></TR> +<TR><TD>29</TD><TD>De Souza</TD><TD>Roger</TD><TD>288</TD><TD>18.02.1991</TD><TD>25500</TD></TR> +<TR><TD>34</TD><TD>Baldwin</TD><TD>Janet</TD><TD>2</TD><TD>21.03.1991</TD><TD>23300</TD></TR> +<TR><TD>36</TD><TD>Reeves</TD><TD>Roger</TD><TD>6</TD><TD>25.04.1991</TD><TD>33620</TD></TR> +<TR><TD>37</TD><TD>Stansbury</TD><TD>Willie</TD><TD>7</TD><TD>25.04.1991</TD><TD>39224</TD></TR> +<TR><TD>44</TD><TD>Phong</TD><TD>Leslie</TD><TD>216</TD><TD>03.06.1991</TD><TD>40350</TD></TR> +<TR><TD>45</TD><TD>Ramanathan</TD><TD>Ashok</TD><TD>209</TD><TD>01.08.1991</TD><TD>33292,94</TD></TR> +<TR><TD>46</TD><TD>Steadman</TD><TD>Walter</TD><TD>210</TD><TD>09.08.1991</TD><TD>19599</TD></TR> +<TR><TD>52</TD><TD>Nordstrom</TD><TD>Carol</TD><TD>420</TD><TD>02.10.1991</TD><TD>4500</TD></TR> +<TR><TD>61</TD><TD>Leung</TD><TD>Luke</TD><TD>3</TD><TD>18.02.1992</TD><TD>34500</TD></TR> +<TR><TD>65</TD><TD>O'Brien</TD><TD>Sue Anne</TD><TD>877</TD><TD>23.03.1992</TD><TD>31275</TD></TR> +<TR><TD>71</TD><TD>Burbank</TD><TD>Jennifer M.</TD><TD>289</TD><TD>15.04.1992</TD><TD>45332</TD></TR> +<TR><TD>72</TD><TD>Sutherland</TD><TD>Claudia</TD><TD></TD><TD>20.04.1992</TD><TD>35699</TD></TR> +<TR><TD>83</TD><TD>Bishop</TD><TD>Dana</TD><TD>290</TD><TD>01.06.1992</TD><TD>45000</TD></TR> +<TR><TD>85</TD><TD>MacDonald</TD><TD>Mary S.</TD><TD>477</TD><TD>01.06.1992</TD><TD>35699</TD></TR> +<TR><TD>94</TD><TD>Williams</TD><TD>Randy</TD><TD>892</TD><TD>08.08.1992</TD><TD>28900</TD></TR> +<TR><TD>105</TD><TD>Bender</TD><TD>Oliver H.</TD><TD>255</TD><TD>08.10.1992</TD><TD>36799</TD></TR> +<TR><TD>107</TD><TD>Cook</TD><TD>Kevin</TD><TD>894</TD><TD>01.02.1993</TD><TD>35500</TD></TR> +<TR><TD>109</TD><TD>Brown</TD><TD>Kelly</TD><TD>202</TD><TD>04.02.1993</TD><TD>27000</TD></TR> +<TR><TD>110</TD><TD>Ichida</TD><TD>Yuki</TD><TD>22</TD><TD>04.02.1993</TD><TD>25689</TD></TR> +<TR><TD>113</TD><TD>Page</TD><TD>Mary</TD><TD>845</TD><TD>12.04.1993</TD><TD>48000</TD></TR> +<TR><TD>114</TD><TD>Parker</TD><TD>Bill</TD><TD>247</TD><TD>01.06.1993</TD><TD>35000</TD></TR> +<TR><TD>118</TD><TD>Yamamoto</TD><TD>Takashi</TD><TD>23</TD><TD>01.07.1993</TD><TD>32500</TD></TR> +<TR><TD>121</TD><TD>Ferrari</TD><TD>Roberto</TD><TD>1</TD><TD>12.07.1993</TD><TD>40500</TD></TR> +<TR><TD>127</TD><TD>Yanowski</TD><TD>Michael</TD><TD>492</TD><TD>09.08.1993</TD><TD>44000</TD></TR> +<TR><TD>134</TD><TD>Glon</TD><TD>Jacques</TD><TD></TD><TD>23.08.1993</TD><TD>24855</TD></TR> +<TR><TD>136</TD><TD>Johnson</TD><TD>Scott</TD><TD>265</TD><TD>13.09.1993</TD><TD>30588,99</TD></TR> +<TR><TD>138</TD><TD>Green</TD><TD>T.J.</TD><TD>218</TD><TD>01.11.1993</TD><TD>36000</TD></TR> +<TR><TD>141</TD><TD>Osborne</TD><TD>Pierre</TD><TD></TD><TD>03.01.1994</TD><TD>35600</TD></TR> +<TR><TD>144</TD><TD>Montgomery</TD><TD>John</TD><TD>820</TD><TD>30.03.1994</TD><TD>35699</TD></TR> +<TR><TD>145</TD><TD>Guckenheimer</TD><TD>Mark</TD><TD>221</TD><TD>02.05.1994</TD><TD>32000</TD></TR> +</Table><br> +<a href="http://groups.yahoo.com/group/JVCL-Developers/">PARTICIPATION</a><br> + +If you would like to participate in JVCL development (donate new components, refactor existing ones, write help files and documentation, develop examples), please join us.<br> + + +<a href="http://groups.yahoo.com/group/JEDI-VCL/">BUGS</a><br> + +<em>To report bugs, please contact us.</em><br> +We hope that you'll find JVCL useful.<br> +<strong><font size="+1">May the Source be with you!</font></strong><br> +<a href="http://delphi-jedi.org/Jedi:VCLVCL">Team JVCL</a><br> +</body> +</html> diff --git a/components/jvcllaz/examples/JvHTMLParser/sample2.htm b/components/jvcllaz/examples/JvHTMLParser/sample2.htm new file mode 100644 index 000000000..845ec3935 --- /dev/null +++ b/components/jvcllaz/examples/JvHTMLParser/sample2.htm @@ -0,0 +1,61 @@ +<html> +<body> +<h2>This is a JvHtmlParser Demo</h2><br> +<Table Width="100%" Border=1 BgColor="#ffffcc"> +<TR><TH>EmpNo</TH><TH>LastName</TH><TH>FirstName</TH><TH>PhoneExt</TH><TH>HireDate</TH><TH>Salary</TH></TR> +<TR><Td>2</TD><TD Align="right" Valign="top">Nelson</TD><TD>Roberto</TD><TD>250</TD><TD>28.12.1988</TD><TD>40000</TD></TR> +<TR><TD>4</TD><TD><Font Face="Arial, Verdana, Helvetica" Size=3>Young</Font></TD><TD>Bruce</TD><TD>233</TD><TD>28.12.1988</TD><TD>55500</TD></TR> +<TR><TD>5</TD><TD>Lambert</TD><TD>Kim</TD><TD>22</TD><TD>06.02.1989</TD><TD>25000</TD></TR> +<TR><TD>8</TD><TD>Johnson</TD><TD>Leslie</TD><TD>410</TD><TD>05.04.1989</TD><TD>25050</TD></TR> +<TR><TD>9</TD><TD>Forest</TD><TD>Phil</TD><TD>229</TD><TD>17.04.1989</TD><TD>25050</TD></TR> +<TR><TD>11</TD><TD>Weston</TD><TD>K. J.</TD><TD>34</TD><TD>17.01.1990</TD><TD>33292,9375</TD></TR> +<TR><TD>12</TD><TD>Lee</TD><TD>Terri</TD><TD>256</TD><TD>01.05.1990</TD><TD>45332</TD></TR> +<TR><TD>14</TD><TD>Hall</TD><TD>Stewart</TD><TD>227</TD><TD>04.06.1990</TD><TD>34482,625</TD></TR> +<TR><TD>15</TD><TD>Young</TD><TD>Katherine</TD><TD>231</TD><TD>14.06.1990</TD><TD>24400</TD></TR> +<TR><TD>20</TD><TD>Papadopoulos</TD><TD>Chris</TD><TD>887</TD><TD>01.01.1990</TD><TD>25050</TD></TR> +<TR><TD>24</TD><TD>Fisher</TD><TD>Pete</TD><TD>888</TD><TD>12.09.1990</TD><TD>23040</TD></TR> +<TR><TD>28</TD><TD>Bennet</TD><TD>Ann</TD><TD>5</TD><TD>01.02.1991</TD><TD>34482,8</TD></TR> +<TR><TD>29</TD><TD>De Souza</TD><TD>Roger</TD><TD>288</TD><TD>18.02.1991</TD><TD>25500</TD></TR> +<TR><TD>34</TD><TD>Baldwin</TD><TD>Janet</TD><TD>2</TD><TD>21.03.1991</TD><TD>23300</TD></TR> +<TR><TD>36</TD><TD>Reeves</TD><TD>Roger</TD><TD>6</TD><TD>25.04.1991</TD><TD>33620</TD></TR> +<TR><TD>37</TD><TD>Stansbury</TD><TD>Willie</TD><TD>7</TD><TD>25.04.1991</TD><TD>39224</TD></TR> +<TR><TD>44</TD><TD>Phong</TD><TD>Leslie</TD><TD>216</TD><TD>03.06.1991</TD><TD>40350</TD></TR> +<TR><TD>45</TD><TD>Ramanathan</TD><TD>Ashok</TD><TD>209</TD><TD>01.08.1991</TD><TD>33292,94</TD></TR> +<TR><TD>46</TD><TD>Steadman</TD><TD>Walter</TD><TD>210</TD><TD>09.08.1991</TD><TD>19599</TD></TR> +<TR><TD>52</TD><TD>Nordstrom</TD><TD>Carol</TD><TD>420</TD><TD>02.10.1991</TD><TD>4500</TD></TR> +<TR><TD>61</TD><TD>Leung</TD><TD>Luke</TD><TD>3</TD><TD>18.02.1992</TD><TD>34500</TD></TR> +<TR><TD>65</TD><TD>O'Brien</TD><TD>Sue Anne</TD><TD>877</TD><TD>23.03.1992</TD><TD>31275</TD></TR> +<TR><TD>71</TD><TD>Burbank</TD><TD>Jennifer M.</TD><TD>289</TD><TD>15.04.1992</TD><TD>45332</TD></TR> +<TR><TD>72</TD><TD>Sutherland</TD><TD>Claudia</TD><TD></TD><TD>20.04.1992</TD><TD>35699</TD></TR> +<TR><TD>83</TD><TD>Bishop</TD><TD>Dana</TD><TD>290</TD><TD>01.06.1992</TD><TD>45000</TD></TR> +<TR><TD>85</TD><TD>MacDonald</TD><TD>Mary S.</TD><TD>477</TD><TD>01.06.1992</TD><TD>35699</TD></TR> +<TR><TD>94</TD><TD>Williams</TD><TD>Randy</TD><TD>892</TD><TD>08.08.1992</TD><TD>28900</TD></TR> +<TR><TD>105</TD><TD>Bender</TD><TD>Oliver H.</TD><TD>255</TD><TD>08.10.1992</TD><TD>36799</TD></TR> +<TR><TD>107</TD><TD>Cook</TD><TD>Kevin</TD><TD>894</TD><TD>01.02.1993</TD><TD>35500</TD></TR> +<TR><TD>109</TD><TD>Brown</TD><TD>Kelly</TD><TD>202</TD><TD>04.02.1993</TD><TD>27000</TD></TR> +<TR><TD>110</TD><TD>Ichida</TD><TD>Yuki</TD><TD>22</TD><TD>04.02.1993</TD><TD>25689</TD></TR> +<TR><TD>113</TD><TD>Page</TD><TD>Mary</TD><TD>845</TD><TD>12.04.1993</TD><TD>48000</TD></TR> +<TR><TD>114</TD><TD>Parker</TD><TD>Bill</TD><TD>247</TD><TD>01.06.1993</TD><TD>35000</TD></TR> +<TR><TD>118</TD><TD>Yamamoto</TD><TD>Takashi</TD><TD>23</TD><TD>01.07.1993</TD><TD>32500</TD></TR> +<TR><TD>121</TD><TD>Ferrari</TD><TD>Roberto</TD><TD>1</TD><TD>12.07.1993</TD><TD>40500</TD></TR> +<TR><TD>127</TD><TD>Yanowski</TD><TD>Michael</TD><TD>492</TD><TD>09.08.1993</TD><TD>44000</TD></TR> +<TR><TD>134</TD><TD>Glon</TD><TD>Jacques</TD><TD></TD><TD>23.08.1993</TD><TD>24855</TD></TR> +<TR><TD>136</TD><TD>Johnson</TD><TD>Scott</TD><TD>265</TD><TD>13.09.1993</TD><TD>30588,99</TD></TR> +<TR><TD>138</TD><TD>Green</TD><TD>T.J.</TD><TD>218</TD><TD>01.11.1993</TD><TD>36000</TD></TR> +<TR><TD>141</TD><TD>Osborne</TD><TD>Pierre</TD><TD></TD><TD>03.01.1994</TD><TD>35600</TD></TR> +<TR><TD>144</TD><TD>Montgomery</TD><TD>John</TD><TD>820</TD><TD>30.03.1994</TD><TD>35699</TD></TR> +<TR><TD>145</TD><TD>Guckenheimer</TD><TD>Mark</TD><TD>221</TD><TD>02.05.1994</TD><TD>32000</TD></TR> +</Table><br> +<a href="http://groups.yahoo.com/group/JVCL-Developers/">PARTICIPATION</a><br> + +If you would like to participate in JVCL development (donate new components, refactor existing ones, write help files and documentation, develop examples), please join us.<br> + + +<a href="http://groups.yahoo.com/group/JEDI-VCL/">BUGS</a><br> + +<em>To report bugs, please contact us.</em><br> +We hope that you'll find JVCL useful.<br> +<strong><font size="+1">May the Source be with you!</font></strong><br> +<a href="http://delphi-jedi.org/Jedi:VCLVCL">Team JVCL</a><br> +</body> +</html> diff --git a/components/jvcllaz/examples/JvLED/JvLEDDemo.lpi b/components/jvcllaz/examples/JvLED/JvLEDDemo.lpi index 5080ac236..07dbfc1f1 100644 --- a/components/jvcllaz/examples/JvLED/JvLEDDemo.lpi +++ b/components/jvcllaz/examples/JvLED/JvLEDDemo.lpi @@ -58,6 +58,9 @@ <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> </SearchPaths> <Linking> + <Debugging> + <UseExternalDbgSyms Value="True"/> + </Debugging> <Options> <Win32> <GraphicApplication Value="True"/> diff --git a/components/jvcllaz/examples/JvLED/LEDMain.lfm b/components/jvcllaz/examples/JvLED/LEDMain.lfm index aa52b202e..1c1d95f8a 100644 --- a/components/jvcllaz/examples/JvLED/LEDMain.lfm +++ b/components/jvcllaz/examples/JvLED/LEDMain.lfm @@ -422,6 +422,7 @@ object LEDDemoMain: TLEDDemoMain Height = 23 Top = 128 Width = 25 + Alignment = taCenter MaxLength = 2 OnChange = HexTextChange TabOrder = 0 diff --git a/components/jvcllaz/packages/jvnetlazd.lpk b/components/jvcllaz/packages/jvnetlazd.lpk new file mode 100644 index 000000000..6944f79df --- /dev/null +++ b/components/jvcllaz/packages/jvnetlazd.lpk @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<CONFIG> + <Package Version="4"> + <PathDelim Value="\"/> + <Name Value="JvNetLazD"/> + <Type Value="DesignTime"/> + <Author Value="Various authors - see header of each unit for original author."/> + <CompilerOptions> + <Version Value="11"/> + <PathDelim Value="\"/> + <SearchPaths> + <IncludeFiles Value="..\resource"/> + <OtherUnitFiles Value="..\design\JvNet"/> + <UnitOutputDirectory Value="..\lib\$(TargetCPU)-$(TargetOS)\design\JvNet"/> + </SearchPaths> + </CompilerOptions> + <Description Value="JVCL net components (design-time)."/> + <License Value="The JVCL is released in accordance with the MPL 1.1 license. To get your own copy or read it, go to http://www.mozilla.org/MPL/MPL-1.1.html. "/> + <Version Major="1" Release="4"/> + <Files Count="1"> + <Item1> + <Filename Value="..\design\JvNet\jvnetreg.pas"/> + <HasRegisterProc Value="True"/> + <UnitName Value="JvNetReg"/> + </Item1> + </Files> + <RequiredPkgs Count="2"> + <Item1> + <PackageName Value="JvCoreLazD"/> + </Item1> + <Item2> + <PackageName Value="JvNetLazR"/> + </Item2> + </RequiredPkgs> + <UsageOptions> + <UnitPath Value="$(PkgOutDir)"/> + </UsageOptions> + <PublishOptions> + <Version Value="2"/> + <UseFileFilters Value="True"/> + </PublishOptions> + </Package> +</CONFIG> diff --git a/components/jvcllaz/packages/jvnetlazr.lpk b/components/jvcllaz/packages/jvnetlazr.lpk new file mode 100644 index 000000000..87fa91a49 --- /dev/null +++ b/components/jvcllaz/packages/jvnetlazr.lpk @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<CONFIG> + <Package Version="4"> + <PathDelim Value="\"/> + <Name Value="JvNetLazR"/> + <Author Value="Various authors - see header of each unit for original author."/> + <CompilerOptions> + <Version Value="11"/> + <PathDelim Value="\"/> + <SearchPaths> + <OtherUnitFiles Value="..\run\JvNet"/> + <UnitOutputDirectory Value="..\lib\$(TargetCPU)-$(TargetOS)\run\JvNet"/> + </SearchPaths> + </CompilerOptions> + <Description Value="JVCL net components (Run-time): HTML parser, FormToHtml converter"/> + <License Value="The JVCL is released in accordance with the MPL 1.1 license. To get your own copy or read it, go to http://www.mozilla.org/MPL/MPL-1.1.html. "/> + <Version Major="1" Release="4"/> + <Files Count="4"> + <Item1> + <Filename Value="..\run\JvNet\jvhtmlparser.pas"/> + <UnitName Value="JvHtmlParser"/> + </Item1> + <Item2> + <Filename Value="..\run\JvNet\jvformtohtml.pas"/> + <UnitName Value="JvFormToHtml"/> + </Item2> + <Item3> + <Filename Value="..\run\JvNet\jvstringlisttohtml.pas"/> + <UnitName Value="JvStringListToHtml"/> + </Item3> + <Item4> + <Filename Value="..\run\JvNet\jvstrtohtml.pas"/> + <UnitName Value="JvStrToHtml"/> + </Item4> + </Files> + <RequiredPkgs Count="1"> + <Item1> + <PackageName Value="JvCoreLazR"/> + </Item1> + </RequiredPkgs> + <UsageOptions> + <UnitPath Value="$(PkgOutDir)"/> + </UsageOptions> + <PublishOptions> + <Version Value="2"/> + <UseFileFilters Value="True"/> + </PublishOptions> + </Package> +</CONFIG> diff --git a/components/jvcllaz/resource/jvnet.res b/components/jvcllaz/resource/jvnet.res new file mode 100644 index 0000000000000000000000000000000000000000..2cf41e341edf27c8c121d2148aa497acb4dca875 GIT binary patch literal 6828 zcmeI0y>in)5XV<{K3R$qEC(h~rsNSQ%?w{*2w{>8wM!nukK%&iIaKou6n=#C6z0FX z_h~07G8B-}qLa?Q{omf|lH778B05FeZndFX*teSK707mL=$by#SNeeGIenrp^qMZ| zir(U`*7s@XOLSlOR#794g-L#@&_~;bi8mXf%^-Q){QQCbnrHwU23#vz3~O4f2U@N9 ziMCqPY6ZSTe~IUU+mZ&_5MD(L?$O2-7+2sQUV&#ev%0P)&($)DuJEdYtK=4XP+X>P z)K4SN9rgTJ;<Mglj`{JEj7JA>mvcA{X0zG+xbK>fC*r`4TIbvh*iO79OzyDr$>IHk z&!BchZWfZhi`$@=pJ38k8{)&^+Jg|sbIqqcN?7$s6!{;;7ldEp#9JB=k#?fPoEW}R zvnMdb+2=CGushcqh+)%0e}dsT=RqKPNxIYNbSEWzM4bKl^o}l2k<L-2E@G|HKY)kS zr<>otFlP0MYtw+b#Pw;l9BYoQ?sy+p;PI_ME4!7yVb`7<s#%Loo%eNV!mA3dl3VCO zaT(jeg5KK5O&-T~5})<Tc~FO;(8Gl1g^S}Pp6}}+Pu(;nf1bUpPZCPg5(VBbY_gKB zj9^dVm?Khlm?l~mdre~vq1dT)p;OldPgptYkW8)r(D!=bo@(Fg@j<lmyi3oDphutM zOT**7e5NV?BG2jVzvA}3`t$~4()sBMmFbes=rg^?De4R-sO!H}tN1Jx>ecXTz!_>2 z&s2HM`o7k)Q>a~w)6?<Hbo<YBq~i+wH!E<&$BJOskm|Xb>wCU@oA%(wz*TYw4vK41 z=nLMbILu+Hzl(DyKX0GwbqblsbA$rSIO2QrN2>5<`o#N%vsQ9oGMD%yI3zn4^%L&^ z=Jed8+O?hmYWMDsp1<G{o(*74<ekKnTfr--uehN!>Rsa;B)#;WbUuF2s~V$j*Y~V% z4+-(Jl(;LL|8uZsu5H_}bm@t8*gs2Yt=d0H;f){gU7vipw^Nh&3^jgd$G<D1jVtiD zS3tka@+S=JJQf=fTR3y*Q#cXx#_$yy^q{z^lAFYF0!eysnCPnz1J5Ss2qmW$+)Wep zynkj%g*+MOj<827*E!-ayr1WqROV2w^G0k;&{s`9IRriqc<IP^;mCRJ2wa~C>@zF5 vjNoN775r#CFW+RTgzM+X*^~5eidx1BcL=~RGnN}C@r6dGaOX0q@51p1@}RxV literal 0 HcmV?d00001 diff --git a/components/jvcllaz/run/JvNet/jvformtohtml.pas b/components/jvcllaz/run/JvNet/jvformtohtml.pas new file mode 100644 index 000000000..440bf75f1 --- /dev/null +++ b/components/jvcllaz/run/JvNet/jvformtohtml.pas @@ -0,0 +1,259 @@ +{----------------------------------------------------------------------------- +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/MPL-1.1.html + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for +the specific language governing rights and limitations under the License. + +The Original Code is: JvFormToHtml.PAS, released on 2001-02-28. + +The Initial Developer of the Original Code is Sébastien Buysse [sbuysse att buypin dott com] +Portions created by Sébastien Buysse are Copyright (C) 2001 Sébastien Buysse. +All Rights Reserved. + +Contributor(s): Michael Beck [mbeck att bigfoot dott com]. + +You may retrieve the latest version of this file at the Project JEDI's JVCL home page, +located at http://jvcl.delphi-jedi.org + +Known Issues: +-----------------------------------------------------------------------------} +// $Id$ + +unit JvFormToHtml; + +{$mode objfpc}{$H+} + +interface + +uses + SysUtils, Classes, Graphics, Controls, Forms, StdCtrls; +// JvComponentBase; + +type + TJvFormToHtml = class(TComponent) //TJvComponent) + public + procedure FormToHtml(const Form: TCustomForm; const Filename: string); + end; + + +implementation + +function FontToCss(const Font: TFont): string; +begin + Result := Format(';font-Size:%d;color:#%d;font-weight:', [Font.Size, Font.Color]); + if fsBold in Font.Style then + Result := Result + 'bold;' + else + Result := Result + 'normal;'; + Result := Result + 'font-family:' + Font.Name; +end; + +procedure TJvFormToHtml.FormToHtml(const Form: TCustomForm; const Filename: string); +var + I, J: Integer; + C: TComponent; + S, S2, St: string; + HTML: TStringList; +begin + HTML := TStringList.Create; + try + HTML.Add('<HTML><BODY>'); + for I := 0 to Form.ComponentCount - 1 do + begin + C := Form.Components[I]; + St := ''; + if C is TLabel then + begin + St := Format('<LABEL style="position:absolute;Left:%d;Top:%d;Height:%d;Width:%d', + [TLabel(C).Left, TLabel(C).Top, TLabel(C).Height, TLabel(C).Width]) + + FontToCss((C as TLabel).Font) + '"' + + ' TITLE="' + (C as TLabel).Hint + '"' + + ' NAME=' + (C as TLabel).Name + + '>' + + TLabel(C).Caption + '</LABEL>'; + end + else + if C is TButton then + begin + if not TButton(C).Enabled then + S := ' DISABLED' + else + S := ''; + + St := Format('<BUTTON style="position:absolute;Left:%d;Top:%d;Height:%d;Width:%d', + [TButton(C).Left, TButton(C).Top, TButton(C).Height, TButton(C).Width]) + + FontToCss(TButton(C).Font) + '"' + + ' TITLE="' + TButton(C).Hint + '"' + + ' TABORDER=' + IntToStr(TButton(C).TabOrder) + + ' NAME=' + TButton(C).Name + + S + + '>' + + TButton(C).Caption + '</BUTTON>'; + end + else + if C is TMemo then + begin + S := ''; + if TMemo(C).ReadOnly then + S := S + ' ReadOnly'; + if not TMemo(C).Enabled then + S := S + ' DISABLED'; + + S2 := ''; + if TMemo(C).WordWrap then + S2 := S2 + ' WRAP=PHYSICAL' + else + S2 := S2 + ' WRAP=OFF'; + + St := Format('<TEXTAREA style="position:absolute;Left:%d;Top:%d;Height:%d;Width:%d', + [TMemo(C).Left, TMemo(C).Top, TMemo(C).Height, TMemo(C).Width]) + + FontToCss(TMemo(C).Font) + '"' + + ' TITLE="' + TMemo(C).Hint + '"' + + S + + ' NAME=' + TMemo(C).Name + + ' TABORDER=' + IntToStr(TMemo(C).TabOrder) + + S2 + + '>' + + TMemo(C).Text + '</TEXTAREA>'; + end + else + if C is TCheckBox then + begin + S := ''; + if not TCheckBox(C).Enabled then + S := S + ' DISABLED'; + if TCheckBox(C).Checked then + S := S + ' CHECKED'; + + St := Format('<INPUT style="position:absolute;Left:%d;Top:%d;Height:%d;Width:%d', + [TCheckBox(C).Left, TCheckBox(C).Top, TCheckBox(C).Height, 10]) + + FontToCss(TCheckBox(C).Font) + '"' + + ' TITLE="' + TCheckBox(C).Hint + '"' + + S + + ' TABORDER=' + IntToStr(TCheckBox(C).TabOrder) + + ' NAME=' + TCheckBox(C).Name + + ' TYPE="CHECKBOX">'; + HTML.Add(St); + St := Format('<LABEL style="position:absolute;Left:%d;Top:%d;Height:%d;Width:%d', + [TCheckBox(C).Left + 13, TCheckBox(C).Top, TCheckBox(C).Height, TCheckBox(C).Width]) + + FontToCss(TCheckBox(C).Font) + '"' + + ' TITLE="' + TCheckBox(C).Hint + '"' + + '>' + + TCheckBox(C).Caption + '</LABEL>'; + end + else + if C is TRadioButton then + begin + S := ''; + if not TRadioButton(C).Enabled then + S := S + ' DISABLED'; + if TRadioButton(C).Checked then + S := S + ' CHECKED'; + + St := Format('<INPUT style="position:absolute;Left:%d;Top:%d;Height:%d;Width:%d', + [TRadioButton(C).Left, TRadioButton(C).Top, TRadioButton(C).Height, 10]) + + FontToCss(TRadioButton(C).Font) + '"' + + ' TITLE="' + TRadioButton(C).Hint + '"' + + S + + ' NAME=' + TRadioButton(C).Parent.Name + + ' TABORDER=' + IntToStr(TRadioButton(C).TabOrder) + + ' TYPE="RADIO">'; + HTML.Add(St); + St := Format('<LABEL style="position:absolute;Left:%d;Top:%d;Height:%d;Width:%d', + [TRadioButton(C).Left + 13, TRadioButton(C).Top, + TRadioButton(C).Height, TRadioButton(C).Width]) + + FontToCss(TRadioButton(C).Font) + '"' + + ' TITLE="' + TRadioButton(C).Hint + '"' + + '>' + + TRadioButton(C).Caption + '</LABEL>'; + end + else + if C is TEdit then + begin + S := ''; + if TEdit(C).ReadOnly then + S := S + ' ReadOnly'; + if TEdit(C).MaxLength <> 0 then + S := S + ' MAXLENGTH=' + IntToStr(TEdit(C).MaxLength); + if not TEdit(C).Enabled then + S := S + ' DISABLED'; + + St := Format('<INPUT TYPE="TEXT" style="position:absolute;Left:%d;Top:%d;Height:%d;Width:%d', + [TEdit(C).Left, TEdit(C).Top, TEdit(C).Height, TEdit(C).Width]) + + FontToCss(TEdit(C).Font) + '"' + + ' TITLE="' + TEdit(C).Hint + '"' + + ' TABORDER=' + IntToStr(TEdit(C).TabOrder) + + ' NAME=' + TEdit(C).Name + + S + + ' Value=' + TEdit(C).Text + + '>'; + end + else + if C is TComboBox then + begin + if not TComboBox(C).Enabled then + S := ' DISABLED' + else + S := ''; + + St := Format('<SELECT style="position:absolute;Left:%d;Top:%d;Height:%d;Width:%d', + [TComboBox(C).Left, TComboBox(C).Top, TComboBox(C).Height, TComboBox(C).Width]) + + FontToCss(TComboBox(C).Font) + '"' + + ' TITLE="' + TComboBox(C).Hint + '"' + + ' TABORDER=' + IntToStr(TComboBox(C).TabOrder) + + ' NAME=' + TComboBox(C).Name + + S + + '>'; + HTML.Add(St); + for J := 0 to TComboBox(C).Items.Count - 1 do + begin + if TComboBox(C).ItemIndex = J then + HTML.Add('<OPTION SELECTED>' + TComboBox(C).Items[J]) + else + HTML.Add('<OPTION>' + TComboBox(C).Items[J]); + end; + St := '</SELECT>'; + end + else + if C is TListBox then + begin + if not TListBox(C).Enabled then + S := ' DISABLED' + else + S := ''; + + St := Format('<SELECT style="position:absolute;Left:%d;Top:%d;Height:%d;Width:%d', + [TListBox(C).Left, TListBox(C).Top, TListBox(C).Height, TListBox(C).Width]) + + FontToCss(TListBox(C).Font) + '"' + + ' MULTIPLE TITLE="' + TListBox(C).Hint + '"' + + ' TABORDER=' + IntToStr(TListBox(C).TabOrder) + + ' NAME=' + TListBox(C).Name + + S + + '>'; + HTML.Add(St); + for J := 0 to TListBox(C).Items.Count - 1 do + begin + if TListBox(C).ItemIndex = J then + HTML.Add('<OPTION SELECTED>' + TListBox(C).Items[J]) + else + HTML.Add('<OPTION>' + TListBox(C).Items[J]); + end; + St := '</SELECT>'; + end; + + if St <> '' then + HTML.Add(St); + end; + HTML.Add('</BODY></HTML>'); + + HTML.SaveToFile(Filename); + finally + HTML.Free; + end; +end; + +end. diff --git a/components/jvcllaz/run/JvNet/jvhtmlparser.pas b/components/jvcllaz/run/JvNet/jvhtmlparser.pas new file mode 100644 index 000000000..97035d74a --- /dev/null +++ b/components/jvcllaz/run/JvNet/jvhtmlparser.pas @@ -0,0 +1,483 @@ +{----------------------------------------------------------------------------- +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/MPL-1.1.html + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for +the specific language governing rights and limitations under the License. + +The Original Code is: JvHTMLParser.PAS, released on 2001-02-28. + +The Initial Developer of the Original Code is Sébastien Buysse [sbuysse att buypin dott com] +Portions created by Sébastien Buysse are Copyright (C) 2001 Sébastien Buysse. +All Rights Reserved. + +Contributor(s): Michael Beck [mbeck att bigfoot dott com]. + Alexander Samusenko[sandx att chat dott ru]. + CarlEfird. + +You may retrieve the latest version of this file at the Project JEDI's JVCL home page, +located at http://jvcl.delphi-jedi.org + +Known Issues: +-----------------------------------------------------------------------------} +// $Id$ + +unit JvHtmlParser; + +{$mode objfpc}{$H+} + +interface + +uses + SysUtils, Classes; + ///JclStrings, +// JvComponentBase; + +type + PTagInfo = ^TTagInfo; + + TTagInfo = record + BeginPos: Integer; + EndPos: Integer; + BeginContext: Integer; + EndContext: Integer; + Key: Integer; + end; + + // (rom) definitely needs improvement + TJvParserInfo = class(TObject) + public + StartTag: string; + EndTag: string; + MustBe: Integer; + TakeText: Integer; + end; + + TTagInfoList = class(TList) + public + procedure AddValue(const Value: TTagInfo); + procedure Clear; override; + end; + + TJvKeyFoundEvent = procedure(Sender: TObject; Key, Results, OriginalLine: string) of object; + TJvKeyFoundExEvent = procedure(Sender: TObject; Key, Results, OriginalLine: string; + TagInfo: TTagInfo; Attributes: TStrings) of object; + + TJvHTMLParser = class(TComponent) //TJvComponent) + private + FParser: TStringList; + FKeys: TStringList; + FFileName: TFileName; + FTagList: TTagInfoList; + FContent: string; + FOnKeyFound: TJvKeyFoundEvent; + FOnKeyFoundEx: TJvKeyFoundExEvent; + function GetParser: TStrings; + procedure SetParser(Value: TStrings); + procedure SetFileName(Value: TFileName); + procedure SetTagList(const Value: TTagInfoList); + function GetConditionsCount: Integer; + protected + procedure Loaded; override; + property TagList: TTagInfoList read FTagList write SetTagList; + public + procedure AnalyseString(const Str: string); + procedure AnalyseFile; + procedure AddCondition(const Keyword: string; const StartTag: string = '<'; + const EndTag: string = '>'; TextSelection: Integer = 0); + procedure RemoveCondition(Index: Integer); + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + property ConditionsCount: Integer read GetConditionsCount; + procedure ClearConditions; + procedure GetCondition(Index: Integer; var Keyword, StartTag, EndTag: string); overload; + procedure GetCondition(Index: Integer; var Keyword, StartTag, EndTag: string; + var TextSelection: Integer); overload; + property Content: string read FContent; + published + property FileName: TFileName read FFileName write SetFileName; + property Parser: TStrings read GetParser write SetParser; + property OnKeyFound: TJvKeyFoundEvent read FOnKeyFound write FOnKeyFound; + property OnKeyFoundEx: TJvKeyFoundExEvent read FOnKeyFoundEx write FOnKeyFoundEx; + end; + + +implementation + +uses + StrUtils, + {$IFNDEF COMPILER12_UP} + JvJCLUtils, + {$ENDIF ~COMPILER12_UP} + JvConsts; + +{Comparison function. Used internally for observance of the sequences tags} +function CompareTags(Item1, Item2: Pointer): Integer; +begin + Result := (PTagInfo(Item1)^.BeginPos - PTagInfo(Item2)^.BeginPos); +end; + +{ Utilities similar to corresponding JCL routines } + +function StrFind(const Substr, S: string; const Index: SizeInt = 1): SizeInt; +begin + Result := PosEx(SubStr, S, Index); +end; + + +//=== { TJvHTMLParser } ====================================================== + +constructor TJvHTMLParser.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FParser := TStringList.Create; + FKeys := TStringList.Create; + FTagList := TTagInfoList.Create; +end; + +destructor TJvHTMLParser.Destroy; +var + Index: Integer; +begin + FParser.Free; + for Index := FKeys.Count - 1 downto 0 do + FKeys.Objects[Index].Free; + FKeys.Free; + FTagList.Free; + inherited Destroy; +end; + +procedure TJvHTMLParser.Loaded; +begin + inherited Loaded; + SetParser(FParser); +end; + +procedure TJvHTMLParser.SetFileName(Value: TFileName); +begin + if FFileName <> Value then + begin + FFileName := Value; + if not (csDesigning in ComponentState) then + AnalyseFile; + end; +end; + +function TJvHTMLParser.GetParser: TStrings; +begin + Result := FParser; +end; + +procedure TJvHTMLParser.SetParser(Value: TStrings); +var + I: Integer; + Obj: TJvParserInfo; + Cap: string; +begin + if FParser <> Value then // make sure we don't assign to ourselves (that will clear the list) + FParser.Assign(Value); + for I := FKeys.Count - 1 downto 0 do + FKeys.Objects[I].Free; + FKeys.Clear; + I := 0; + while I < FParser.Count do + begin + Obj := TJvParserInfo.Create; + try + Cap := FParser[I]; + Inc(I); + Obj.StartTag := FParser[I]; + Inc(I); + Obj.EndTag := FParser[I]; + Inc(I); + Obj.MustBe := StrToInt(FParser[I]); + Inc(I); + Obj.TakeText := StrToInt(FParser[I]); + Inc(I); + finally + FKeys.AddObject(Cap, Obj); + end; + end; +end; + +// (rom) reimplemented with a TStringList + +procedure TJvHTMLParser.AnalyseFile; +var + List: TStringList; +begin + List := TStringList.Create; + try + if FileExists(FileName) then + begin + List.LoadFromFile(FileName); + AnalyseString(List.Text); + end; + finally + List.Free; + end; +end; + +procedure TJvHTMLParser.AnalyseString(const Str: string); +var + Str2, Str3: string; + StartTag1, StartTag2: string; + I, J, K, Index: Integer; + TagInfo: TTagInfo; + AttributesList: TStringList; + + procedure InnerParseAttributes(Content: PChar; Strings: TStrings); + var + Head, Tail: PChar; + EOS, InQuote, LeadQuote: Boolean; + QuoteChar: Char; + begin + if (Content = nil) or (Content^ = #0) then + Exit; + Tail := Content; + QuoteChar := #0; + repeat + while CharInSet(Tail^, [Cr, Lf, ' ']) do + Inc(Tail); + Head := Tail; + InQuote := False; + LeadQuote := False; + while True do + begin + while (InQuote and not CharInSet(Tail^, [#0, '"'])) or + not CharInSet(Tail^, [#0, Cr, Lf, ' ', '"']) do + Inc(Tail); + if Tail^ = '"' then + begin + if (QuoteChar <> #0) and (QuoteChar = Tail^) then + QuoteChar := #0 + else + begin + LeadQuote := Head = Tail; + QuoteChar := Tail^; + if LeadQuote then + Inc(Head); + end; + InQuote := QuoteChar <> #0; + if InQuote then + Inc(Tail) + else + Break; + end + else + Break; + end; + if not LeadQuote and (Tail^ <> #0) and (Tail^ = '"') then + Inc(Tail); + EOS := Tail^ = #0; + Tail^ := #0; + if Head^ <> #0 then + Strings.Add(Head); + Inc(Tail); + until EOS; + end; + + procedure ParseAttributes(Strings: TStrings; const Value: string); + var + P: PChar; + Tmp: string; + begin + Strings.Clear; + Tmp := Value; + UniqueString(Tmp); + P := PChar(Tmp); +// if P^ in [#0, '<', '>'] then + if CharInSet(P^, [#0, '>']) then + Exit; + // skip first word (the tag) and any whitespace + while (P^ <> #0) and (P <> nil) do + begin + if P^ = ' ' then + begin + Inc(P); + Break; + end; + Inc(P); + end; + InnerParseAttributes(P, Strings); + end; + +begin + if (FKeys.Count = 0) and (FParser.Count <> 0) then + SetParser(FParser); + FContent := Str; + AttributesList := TStringList.Create; + try + if FKeys.Count > 0 then + begin + FTagList.Clear; + for I := 0 to FKeys.Count - 1 do + begin + StartTag1 := TJvParserInfo(FKeys.Objects[I]).StartTag; + Starttag2 := ''; + if (Length(StartTag1) > 2) and (StartTag1[Length(StartTag1)] = '>') then + begin + // split the tag so tags with attributes can be found + Delete(StartTag1, Length(StartTag1), 1); + StartTag2 := '>'; + end; + J := 1; + while J <> 0 do + begin + // changed from StrSearch(case sensitive) to StrFind (case insensitive) + J := StrFind(StartTag1, Str, J); + if J > 0 then + begin + // changed from StrSearch(case sensitive) to StrFind (case insensitive) + K := StrFind(TJvParserInfo(FKeys.Objects[I]).EndTag, Str, J); + TagInfo.BeginPos := J; + TagInfo.EndPos := K + Length(TJvParserInfo(FKeys.Objects[I]).EndTag); + TagInfo.Key := I; + case TJvParserInfo(FKeys.Objects[I]).TakeText of + 0: //Between limits + begin + if StartTag2 = '' then + TagInfo.BeginContext := J + Length(TJvParserInfo(FKeys.Objects[I]).StartTag) + else + // changed from StrSearch(case sensitive) to StrFind (case insensitive) + TagInfo.BeginContext := StrFind(StartTag2, Str, j) + 1; + TagInfo.EndContext := K; + end; + 1: //All before start tag + begin + TagInfo.BeginContext := 1; + TagInfo.EndContext := J; + end; + 2: //All after start tag + begin + if StartTag2 = '' then + TagInfo.BeginContext := J + Length(TJvParserInfo(FKeys.Objects[I]).StartTag) + else + // changed from StrSearch(case sensitive) to StrFind (case insensitive) + TagInfo.BeginContext := StrFind(StartTag2, Str, j) + 1; + TagInfo.EndContext := Length(Str); + end; + 3: //The whole line if containing start tag + begin + TagInfo.BeginContext := J; + // changed from StrSearch(case sensitive) to StrFind (case insensitive) + TagInfo.EndContext := StrFind(Lf, Str, J); + end; + end; + FTagList.AddValue(TagInfo); + J := J + Length(TJvParserInfo(FKeys.Objects[I]).StartTag); + end; + end; + end; + end; + FTagList.Sort(@CompareTags); + with FTagList do + begin + for Index := 0 to Count - 1 do + begin + // Str2 now contains eveything between the start and end tags + Str2 := Copy(Str, PTagInfo(Items[Index])^.BeginContext, + PTagInfo(Items[Index])^.EndContext - PTagInfo(Items[Index])^.BeginContext); + if StartTag2 = '' then + Str3 := '' + else + //Str3 contains the start tag as found, may include attributes or other tags + Str3 := Copy(Str, PTagInfo(Items[Index])^.BeginPos, + PTagInfo(Items[Index])^.BeginContext - PTagInfo(Items[Index])^.BeginPos - 1); + if Assigned(FOnKeyFound) then + FOnKeyFound(Self, FKeys[PTagInfo(Items[Index])^.Key], Str2, Str); + if Assigned(FOnKeyFoundEx) then + begin + if Str3 <> '' then + ParseAttributes(AttributesList, Str3) + else + ParseAttributes(AttributesList, Str2); + FOnKeyFoundEx(Self, FKeys[PTagInfo(Items[Index])^.Key], Str2, Str, + PTagInfo(Items[Index])^, AttributesList); + end; + end; + end; + finally + AttributesList.Free; + end; +end; + +procedure TJvHTMLParser.AddCondition(const Keyword: string; + const StartTag: string; const EndTag: string; TextSelection: Integer); +var + Obj: TJvParserInfo; +begin + Obj := TJvParserInfo.Create; + Obj.StartTag := StartTag; + Obj.EndTag := EndTag; + Obj.TakeText := TextSelection; + FKeys.AddObject(Keyword, TObject(Obj)); +end; + +procedure TJvHTMLParser.RemoveCondition(Index: Integer); +begin + FKeys.Objects[Index].Free; + FKeys.Delete(Index); +end; + +procedure TJvHTMLParser.ClearConditions; +var + Index: Integer; +begin + FParser.Clear; + for Index := FKeys.Count - 1 downto 0 do + FKeys.Objects[Index].Free; + FKeys.Clear; +end; + +procedure TJvHTMLParser.GetCondition(Index: Integer; var Keyword, StartTag, EndTag: string); +begin + Keyword := FKeys[Index]; + StartTag := TJvParserInfo(FKeys.Objects[Index]).StartTag; + EndTag := TJvParserInfo(FKeys.Objects[Index]).EndTag; +end; + +procedure TJvHTMLParser.GetCondition(Index: Integer; var Keyword, StartTag, EndTag: string; + var TextSelection: Integer); +begin + GetCondition(Index, Keyword, StartTag, EndTag); + TextSelection := TJvParserInfo(FKeys.Objects[Index]).TakeText; +end; + +function TJvHTMLParser.GetConditionsCount: Integer; +begin + Result := FKeys.Count; +end; + +procedure TJvHTMLParser.SetTagList(const Value: TTagInfoList); +begin + FTagList := Value; +end; + +//=== { TTagInfoList } ======================================================= + +procedure TTagInfoList.AddValue(const Value: TTagInfo); +var + P: PTagInfo; +begin + GetMem(P, SizeOf(TTagInfo)); + if P <> nil then + begin + P^ := Value; + Add(P); + end; +end; + +procedure TTagInfoList.Clear; +var + I: Integer; +begin + for I := 0 to Count - 1 do + FreeMem(Items[I], SizeOf(TTagInfo)); + inherited Clear; +end; + +end. diff --git a/components/jvcllaz/run/JvNet/jvstringlisttohtml.pas b/components/jvcllaz/run/JvNet/jvstringlisttohtml.pas new file mode 100644 index 000000000..6bec869d8 --- /dev/null +++ b/components/jvcllaz/run/JvNet/jvstringlisttohtml.pas @@ -0,0 +1,160 @@ +{----------------------------------------------------------------------------- +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/MPL-1.1.html + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for +the specific language governing rights and limitations under the License. + +The Original Code is: JvStringListToHtml.PAS, released on 2001-02-28. + +The Initial Developer of the Original Code is Sébastien Buysse [sbuysse att buypin dott com] +Portions created by Sébastien Buysse are Copyright (C) 2001 Sébastien Buysse. +All Rights Reserved. + +Contributor(s): Michael Beck [mbeck att bigfoot dott com]. + +You may retrieve the latest version of this file at the Project JEDI's JVCL home page, +located at http://jvcl.delphi-jedi.org + +Known Issues: +-----------------------------------------------------------------------------} +// $Id$ + +unit JvStringListToHtml; + +{$mode objfpc}{$H+} + +interface + +uses + SysUtils, Classes; +// JvComponentBase; + +type + TJvStringListToHtml = class(TComponent) // TJvComponent) + private + FStrings: TStringList; + FHTML: TStringList; + FHTMLTitle: string; + FHTMLLineBreak: string; + FIncludeHeader: Boolean; + function GetHTML: TStrings; + function GetStrings: TStrings; + procedure SetStrings(const Value: TStrings); + procedure DoStringsChange(Sender: TObject); + procedure SetHTML(const Value: TStrings); + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + procedure ConvertToHTML(Source: TStrings; const FileName: string); + procedure ConvertToHTMLStrings(Source, Destination: TStrings); + published + property HTML: TStrings read GetHTML write SetHTML stored False; + property Strings: TStrings read GetStrings write SetStrings; + property HTMLLineBreak: string read FHTMLLineBreak write FHTMLLineBreak; + property HTMLTitle: string read FHTMLTitle write FHTMLTitle; + property IncludeHeader: Boolean read FIncludeHeader write FIncludeHeader default True; + end; + + +implementation + +procedure ConvertStringsToHTML(Source, Destination: TStrings; const HTMLTitle, HTMLLineBreak: string; IncludeHeader: Boolean); +var + I: Integer; +begin + if (Source = nil) or (Destination = nil) then + Exit; + Destination.BeginUpdate; + Source.BeginUpdate; + try + if IncludeHeader then + begin + Destination.Add('<HTML><HEAD>'); + Destination.Add('<TITLE>' + HTMLTitle + ''); + Destination.Add(''); + end; + for I := 0 to Source.Count - 1 do + Destination.Add(Source[I] + HTMLLineBreak); + if IncludeHeader then + begin + Destination.Add(''); + Destination.Add(''); + end; + finally + Source.EndUpdate; + Destination.EndUpdate; + end; +end; + +procedure TJvStringListToHtml.ConvertToHTML(Source: TStrings; const FileName: string); +var + Dest: TStringList; +begin + if Source = nil then + Exit; + Dest := TStringList.Create; + try + ConvertStringsToHTML(Source, Dest, HTMLTitle, HTMLLineBreak, True); + Dest.SaveToFile(FileName); + finally + Dest.Free; + end; +end; + +procedure TJvStringListToHtml.ConvertToHTMLStrings(Source, Destination: TStrings); +begin + ConvertStringsToHTML(Source, Destination, HTMLTitle, HTMLLineBreak, IncludeHeader); +end; + +constructor TJvStringListToHtml.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FStrings := TStringList.Create; + FHTML := TStringList.Create; + FStrings.OnChange := @DoStringsChange; + FHTMLLineBreak := '
'; + FHTMLTitle := 'Converted by TJvStringListToHtml'; + FIncludeHeader := True; +end; + +destructor TJvStringListToHtml.Destroy; +begin + FreeAndNil(FStrings); + FreeAndNil(FHTML); + inherited Destroy; +end; + +procedure TJvStringListToHtml.DoStringsChange(Sender: TObject); +begin + FreeAndNil(FHTML); +end; + +function TJvStringListToHtml.GetHTML: TStrings; +begin + if ComponentState * [csLoading, csDestroying] <> [] then + if FHTML.Count = 0 then + ConvertToHTMLStrings(Strings, FHTML); + Result := FHTML; +end; + +procedure TJvStringListToHtml.SetHTML(const Value: TStrings); +begin + // do nothing +end; + +function TJvStringListToHtml.GetStrings: TStrings; +begin + Result := FStrings; +end; + +procedure TJvStringListToHtml.SetStrings(const Value: TStrings); +begin + FStrings.Assign(Value); + FHTML.Clear; +end; + +end. diff --git a/components/jvcllaz/run/JvNet/jvstrtohtml.pas b/components/jvcllaz/run/JvNet/jvstrtohtml.pas new file mode 100644 index 000000000..c532c2bd6 --- /dev/null +++ b/components/jvcllaz/run/JvNet/jvstrtohtml.pas @@ -0,0 +1,492 @@ +{----------------------------------------------------------------------------- +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/MPL-1.1.html + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for +the specific language governing rights and limitations under the License. + +The Original Code is: JvStrToHtml.PAS, released on 2001-02-28. + +The Initial Developer of the Original Code is Sébastien Buysse [sbuysse att buypin dott com] +Portions created by Sébastien Buysse are Copyright (C) 2001 Sébastien Buysse. +All Rights Reserved. + +Contributor(s): Michael Beck [mbeck att bigfoot dott com]. + Andreas Hausladen [Andreas dott Hausladen att gmx dott de] + +You may retrieve the latest version of this file at the Project JEDI's JVCL home page, +located at http://jvcl.delphi-jedi.org + +Known Issues: +-----------------------------------------------------------------------------} +// $Id$ + +unit JvStrToHtml; + +{$mode objfpc}{$H+} + +interface + +uses + SysUtils, Classes; +// JvComponentBase; + +type + TJvStrToHtml = class(TComponent) // TJvComponent) + private + FHtml: string; + FValue: string; + procedure SetHtml(const Value: string); + procedure SetValue(const Value: string); + public + constructor Create(AOwner: TComponent); override; + function TextToHtml(const Text: string): string; + function HtmlToText(const Text: string): string; + published + property Text: string read FValue write SetValue; + property Html: string read FHtml write SetHtml; + end; + +function StringToHtml(const Value: string): string; +function HtmlToString(const Value: string): string; +//function CharToHtml(Ch: Char): string; + + +implementation + +uses + LazUtf8; + +type + TJvHtmlCodeRec = record + Ch: Cardinal; + Html: string; + end; + +const + { References: + http://www.w3.org/TR/REC-html40/charset.html#h-5.3 + http://www.w3.org/TR/REC-html40/sgml/entities.html#h-24.2.1 + http://www.w3.org/TR/REC-html40/sgml/entities.html#h-24.4.1 + } + + Conversions: array [0..240] of TJvHtmlCodeRec = ( + (Ch: 34; Html: '"'), + (Ch: 38; Html: '&'), + (Ch: 39; Html: '''), + (Ch: 60; Html: '<'), + (Ch: 62; Html: '>'), + (Ch: 160; Html: ' '), + (Ch: 161; Html: '¡'), + (Ch: 162; Html: '¢'), + (Ch: 163; Html: '£'), + (Ch: 164; Html: '¤'), + (Ch: 165; Html: '¥'), + (Ch: 166; Html: '¦'), + (Ch: 167; Html: '§'), + (Ch: 168; Html: '¨'), + (Ch: 169; Html: '©'), + (Ch: 170; Html: 'ª'), + (Ch: 171; Html: '«'), + (Ch: 172; Html: '¬'), + (Ch: 173; Html: '­'), + (Ch: 174; Html: '®'), + (Ch: 175; Html: '¯'), + (Ch: 176; Html: '°'), + (Ch: 177; Html: '±'), + (Ch: 178; Html: '²'), + (Ch: 179; Html: '³'), + (Ch: 180; Html: '´'), + (Ch: 181; Html: 'µ'), + (Ch: 182; Html: '¶'), + (Ch: 183; Html: '·'), + (Ch: 184; Html: '¸'), + (Ch: 185; Html: '¹'), + (Ch: 186; Html: 'º'), + (Ch: 187; Html: '»'), + (Ch: 188; Html: '¼'), + (Ch: 189; Html: '½'), + (Ch: 190; Html: '¾'), + (Ch: 191; Html: '¿'), + (Ch: 192; Html: 'À'), + (Ch: 193; Html: 'Á'), + (Ch: 194; Html: 'Â'), + (Ch: 195; Html: 'Ã'), + (Ch: 196; Html: 'Ä'), + (Ch: 197; Html: 'Å'), + (Ch: 198; Html: 'Æ'), + (Ch: 199; Html: 'Ç'), + (Ch: 200; Html: 'È'), + (Ch: 201; Html: 'É'), + (Ch: 202; Html: 'Ê'), + (Ch: 203; Html: 'Ë'), + (Ch: 204; Html: 'Ì'), + (Ch: 205; Html: 'Í'), + (Ch: 206; Html: 'Î'), + (Ch: 207; Html: 'Ï'), + (Ch: 208; Html: 'Ð'), + (Ch: 209; Html: 'Ñ'), + (Ch: 210; Html: 'Ò'), + (Ch: 211; Html: 'Ó'), + (Ch: 212; Html: 'Ô'), + (Ch: 213; Html: 'Õ'), + (Ch: 214; Html: 'Ö'), + (Ch: 215; Html: '×'), + (Ch: 216; Html: 'Ø'), + (Ch: 217; Html: 'Ù'), + (Ch: 218; Html: 'Ú'), + (Ch: 219; Html: 'Û'), + (Ch: 220; Html: 'Ü'), + (Ch: 221; Html: 'Ý'), + (Ch: 222; Html: 'Þ'), + (Ch: 223; Html: 'ß'), + (Ch: 224; Html: 'à'), + (Ch: 225; Html: 'á'), + (Ch: 226; Html: 'â'), + (Ch: 227; Html: 'ã'), + (Ch: 228; Html: 'ä'), + (Ch: 229; Html: 'å'), + (Ch: 230; Html: 'æ'), + (Ch: 231; Html: 'ç'), + (Ch: 232; Html: 'è'), + (Ch: 233; Html: 'é'), + (Ch: 234; Html: 'ê'), + (Ch: 235; Html: 'ë'), + (Ch: 236; Html: 'ì'), + (Ch: 237; Html: 'í'), + (Ch: 238; Html: 'î'), + (Ch: 239; Html: 'ï'), + (Ch: 240; Html: 'ð'), + (Ch: 241; Html: 'ñ'), + (Ch: 242; Html: 'ò'), + (Ch: 243; Html: 'ó'), + (Ch: 244; Html: 'ô'), + (Ch: 245; Html: 'õ'), + (Ch: 246; Html: 'ö'), + (Ch: 247; Html: '÷'), + (Ch: 248; Html: 'ø'), + (Ch: 249; Html: 'ù'), + (Ch: 250; Html: 'ú'), + (Ch: 251; Html: 'û'), + (Ch: 252; Html: 'ü'), + (Ch: 253; Html: 'ý'), + (Ch: 254; Html: 'þ'), + (Ch: 255; Html: 'ÿ'), + (Ch: 338; Html: 'Œ'), + (Ch: 339; Html: 'œ'), + (Ch: 352; Html: 'Š'), + (Ch: 353; Html: 'š'), + (Ch: 376; Html: 'Ÿ'), + (Ch: 402; Html: 'ƒ'), + (Ch: 710; Html: 'ˆ'), + (Ch: 732; Html: '˜'), + (Ch: 913; Html: 'Α'), + (Ch: 914; Html: 'Β'), + (Ch: 915; Html: 'Γ'), + (Ch: 916; Html: 'Δ'), + (Ch: 917; Html: 'Ε'), + (Ch: 918; Html: 'Ζ'), + (Ch: 919; Html: 'Η'), + (Ch: 920; Html: 'Θ'), + (Ch: 921; Html: 'Ι'), + (Ch: 922; Html: 'Κ'), + (Ch: 923; Html: 'Λ'), + (Ch: 924; Html: 'Μ'), + (Ch: 925; Html: 'Ν'), + (Ch: 926; Html: 'Ξ'), + (Ch: 927; Html: 'Ο'), + (Ch: 928; Html: 'Π'), + (Ch: 929; Html: 'Ρ'), + (Ch: 931; Html: 'Σ'), + (Ch: 932; Html: 'Τ'), + (Ch: 933; Html: 'Υ'), + (Ch: 934; Html: 'Φ'), + (Ch: 935; Html: 'Χ'), + (Ch: 936; Html: 'Ψ'), + (Ch: 937; Html: 'Ω'), + (Ch: 945; Html: 'α'), + (Ch: 946; Html: 'β'), + (Ch: 947; Html: 'γ'), + (Ch: 948; Html: 'δ'), + (Ch: 949; Html: 'ε'), + (Ch: 950; Html: 'ζ'), + (Ch: 951; Html: 'η'), + (Ch: 952; Html: 'θ'), + (Ch: 953; Html: 'ι'), + (Ch: 954; Html: 'κ'), + (Ch: 955; Html: 'λ'), + (Ch: 956; Html: 'μ'), + (Ch: 957; Html: 'ν'), + (Ch: 958; Html: 'ξ'), + (Ch: 959; Html: 'ο'), + (Ch: 960; Html: 'π'), + (Ch: 961; Html: 'ρ'), + (Ch: 962; Html: 'ς'), + (Ch: 963; Html: 'σ'), + (Ch: 964; Html: 'τ'), + (Ch: 965; Html: 'υ'), + (Ch: 966; Html: 'φ'), + (Ch: 967; Html: 'χ'), + (Ch: 968; Html: 'ψ'), + (Ch: 969; Html: 'ω'), + (Ch: 977; Html: 'ϑ'), + (Ch: 978; Html: 'ϒ'), + (Ch: 982; Html: 'ϖ'), + (Ch: 8194; Html: ' '), + (Ch: 8195; Html: ' '), + (Ch: 8201; Html: ' '), + (Ch: 8204; Html: '‌'), + (Ch: 8205; Html: '‍'), + (Ch: 8206; Html: '‎'), + (Ch: 8207; Html: '‏'), + (Ch: 8211; Html: '–'), + (Ch: 8212; Html: '—'), + (Ch: 8216; Html: '‘'), + (Ch: 8217; Html: '’'), + (Ch: 8218; Html: '‚'), + (Ch: 8220; Html: '“'), + (Ch: 8221; Html: '”'), + (Ch: 8222; Html: '„'), + (Ch: 8224; Html: '†'), + (Ch: 8225; Html: '‡'), + (Ch: 8226; Html: '•'), + (Ch: 8230; Html: '…'), + (Ch: 8240; Html: '‰'), + (Ch: 8242; Html: '′'), + (Ch: 8243; Html: '″'), + (Ch: 8249; Html: '‹'), + (Ch: 8250; Html: '›'), + (Ch: 8254; Html: '‾'), + (Ch: 8364; Html: '€'), + (Ch: 8482; Html: '™'), + (Ch: 8592; Html: '←'), + (Ch: 8593; Html: '↑'), + (Ch: 8594; Html: '→'), + (Ch: 8595; Html: '↓'), + (Ch: 8596; Html: '↔'), + (Ch: 8629; Html: '↵'), + (Ch: 8704; Html: '∀'), + (Ch: 8706; Html: '∂'), + (Ch: 8707; Html: '∃'), + (Ch: 8709; Html: '∅'), + (Ch: 8711; Html: '∇'), + (Ch: 8712; Html: '∈'), + (Ch: 8713; Html: '∉'), + (Ch: 8715; Html: '∋'), + (Ch: 8719; Html: '∏'), + (Ch: 8721; Html: '∑'), + (Ch: 8722; Html: '−'), + (Ch: 8727; Html: '∗'), + (Ch: 8730; Html: '√'), + (Ch: 8733; Html: '∝'), + (Ch: 8734; Html: '∞'), + (Ch: 8736; Html: '∠'), + (Ch: 8743; Html: '∧'), + (Ch: 8744; Html: '∨'), + (Ch: 8745; Html: '∩'), + (Ch: 8746; Html: '∪'), + (Ch: 8747; Html: '∫'), + (Ch: 8756; Html: '∴'), + (Ch: 8764; Html: '∼'), + (Ch: 8773; Html: '≅'), + (Ch: 8776; Html: '≈'), + (Ch: 8800; Html: '≠'), + (Ch: 8801; Html: '≡'), + (Ch: 8804; Html: '≤'), + (Ch: 8805; Html: '≥'), + (Ch: 8834; Html: '⊂'), + (Ch: 8835; Html: '⊃'), + (Ch: 8836; Html: '⊄'), + (Ch: 8838; Html: '⊆'), + (Ch: 8839; Html: '⊇'), + (Ch: 8853; Html: '⊕'), + (Ch: 8855; Html: '⊗'), + (Ch: 8869; Html: '⊥'), + (Ch: 8901; Html: '⋅'), + (Ch: 8968; Html: '⌈'), + (Ch: 8969; Html: '⌉'), + (Ch: 8970; Html: '⌊'), + (Ch: 8971; Html: '⌋'), + (Ch: 9674; Html: '◊'), + (Ch: 9824; Html: '♠'), + (Ch: 9827; Html: '♣'), + (Ch: 9829; Html: '♥'), + (Ch: 9830; Html: '♦') + ); + +var + ConversionsHash: array of Word; + +{$IFNDEF UNICODE} +const + MB_ERR_INVALID_CHARS = 8; +{$ENDIF ~UNICODE} + +{ TJvStrToHtml } + +constructor TJvStrToHtml.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FValue := ''; + FHtml := ''; +end; + +function TJvStrToHtml.HtmlToText(const Text: string): string; +begin + Result := HtmlToString(Text); +end; + +procedure TJvStrToHtml.SetHtml(const Value: string); +begin + FValue := HtmlToText(Value); +end; + +procedure TJvStrToHtml.SetValue(const Value: string); +begin + FHtml := TextToHtml(Value); +end; + +function TJvStrToHtml.TextToHtml(const Text: string): string; +begin + Result := StringToHtml(Text); +end; + +function GetHtmlHash(const S: string): Word; +var + I: Integer; +begin + Result := Length(S); + for I := 1 to Length(S) do + Result := Word(Result + Ord(S[I]) shl (I mod 4)); +end; + +procedure InitConversionsHash; +var + I: Integer; +begin + SetLength(ConversionsHash, Length(Conversions)); + for I := 0 to High(ConversionsHash) do + ConversionsHash[I] := GetHtmlHash(Conversions[I].Html); +end; + +function StringToHtml(const Value: String): String; +var + ResultLen: Integer; + CurrPos: Integer; + P, PEnd: PChar; + + procedure Append(s: String); + var + n: Integer; + begin + n := Length(s); + if CurrPos + n > ResultLen then begin + ResultLen := ResultLen + 100; + SetLength(Result, ResultLen); + end; + Move(s[1], Result[CurrPos], n); + inc(CurrPos, n); + end; + +var + J, n: Integer; + ch: Cardinal; + found: Boolean; +begin + if Value = '' then begin + Result := ''; + exit; + end; + + ResultLen := Length(Value); + SetLength(Result, ResultLen); + + P := @Value[1]; + PEnd := @Value[ResultLen]; + CurrPos := 1; + while P <= PEnd do begin + n := 1; + if P^ in ['a'..'z', 'A'..'Z', '0'..'9', '_', ' '] then + Append(P^) + else begin + ch := UTF8CodePointToUniCode(P, n); + found := false; + for J := Low(Conversions) to High(Conversions) do + if ch = Conversions[J].Ch then begin + Append(Conversions[J].Html); + found := true; + break; + end; + if not found then + Append(Format('&#%d;', [ch])); + end; + inc(P, n); + end; + SetLength(Result, CurrPos-1); +end; + +function HtmlToString(const Value: String): String; +var + ResultLen: Integer; + P, PEnd: PChar; + CurrPos: Integer; + + procedure Append(s: String); + var + n: Integer; + begin + n := Length(s); + Move(s[1], Result[CurrPos], n); + inc(CurrPos, n); + end; + +var + html: String; + found: Boolean; + J: Integer; +begin + if Value = '' then begin + Result := ''; + exit; + end; + + ResultLen := Length(Value); + SetLength(Result, ResultLen); + + P := @Value[1]; + PEnd := @Value[ResultLen]; + CurrPos := 1; + + while P <= PEnd do begin + if P^ = '&' then begin + html := '&'; + while P < PEnd do begin + inc(P); + html := html + P^; + if P^ = ';' then break; + end; + found := false; + for J := Low(Conversions) to High(Conversions) do + if html = Conversions[J].Html then begin + Append(UnicodeToUTF8(Conversions[j].Ch)); + found := true; + break; + end; + if not found then begin + Delete(html, Length(html), 1); + Delete(html, 1, 1); + if html[1] = 'x' then html[1] := '$'; + Append(UnicodeToUTF8(StrToInt(html))); + end; + end else + Append(P^); + inc(P); + end; + SetLength(Result, CurrPos-1); +end; + +end. +