Skip to content

Commit 7168d5c

Browse files
committed
Interface change - replaced WideString references with String
1 parent 49e4ebb commit 7168d5c

File tree

1 file changed

+68
-74
lines changed

1 file changed

+68
-74
lines changed

HtmlParserEx.pas

+68-74
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
unit HtmlParserEx;
2-
{ '$DEFINE UseXPath }
2+
{$DEFINE UseXPath }
33
{$IF RTLVersion < 24.0}
44
{$MESSAGE ERROR 'Only XE3 and later versions are supported'}
55
{$ENDIF}
@@ -24,12 +24,6 @@ interface
2424
LowStrIndex = low(string); // Mobile platform=0, PC platform=1
2525

2626
type
27-
{$IFNDEF MSWINDOWS}
28-
{ The interface uses WideString so that it can be used by languages such as C++, VB, etc.
29-
But if you leave the Windows platform, other platforms do not have the COM data type of WideString.
30-
}
31-
WideString = string;
32-
{$ENDIF}
3327
IHtmlElement = interface;
3428
IHtmlElementList = interface;
3529
TElementEachEvent = reference to procedure(AIndex:Integer; AEl:IHtmlElement);
@@ -38,19 +32,19 @@ interface
3832
IHtmlElement = interface
3933
['{8C75239C-8CFA-499F-B115-7CEBEDFB421B}']
4034
function GetParent:IHtmlElement; stdcall;
41-
function GetTagName:WideString; stdcall;
42-
procedure SetTagName(Value:WideString); stdcall;
43-
function GetContent:WideString; stdcall;
44-
function GetOrignal:WideString; stdcall;
35+
function GetTagName:String; stdcall;
36+
procedure SetTagName(Value:String); stdcall;
37+
function GetContent:String; stdcall;
38+
function GetOrignal:String; stdcall;
4539
function GetChildrenCount:Integer; stdcall;
4640
function GetChildren(Index:Integer):IHtmlElement; stdcall;
4741
function GetCloseTag:IHtmlElement; stdcall;
48-
function GetInnerHtml():WideString; stdcall;
49-
function GetOuterHtml():WideString; stdcall;
50-
function GetInnerText():WideString; stdcall;
51-
procedure SetInnerText(Value:WideString); stdcall;
52-
function GetAttributes(Key:WideString):WideString; stdcall;
53-
procedure SetAttributes(Key:WideString; Value:WideString); stdcall;
42+
function GetInnerHtml():String; stdcall;
43+
function GetOuterHtml():String; stdcall;
44+
function GetInnerText():String; stdcall;
45+
procedure SetInnerText(Value:String); stdcall;
46+
function GetAttributes(Key:String):String; stdcall;
47+
procedure SetAttributes(Key:String; Value:String); stdcall;
5448
procedure RemoveAttr(AAttrName:string); stdcall;
5549
function GetSourceLineNum():Integer; stdcall;
5650
function GetSourceColNum():Integer; stdcall;
@@ -59,35 +53,35 @@ interface
5953
procedure Remove; stdcall;
6054
function AppedChild(const ATag:string):IHtmlElement; stdcall;
6155
// Does the property exist
62-
function HasAttribute(AttributeName:WideString):Boolean; stdcall;
56+
function HasAttribute(AttributeName:String):Boolean; stdcall;
6357
{ Find Element using CSS selector syntax, "pseudo-class" is not supported
6458
http://www.w3.org/TR/CSS2/selector.html
6559
}
66-
function SimpleCSSSelector(const selector:WideString):IHtmlElementList; stdcall;
67-
function Find(const selector:WideString):IHtmlElementList; stdcall;
60+
function SimpleCSSSelector(const selector:String):IHtmlElementList; stdcall;
61+
function Find(const selector:String):IHtmlElementList; stdcall;
6862
{$IFDEF UseXPath}
69-
function FindX(const AXPath:WideString):IHtmlElementList; stdcall;
63+
function FindX(const AXPath:String):IHtmlElementList; stdcall;
7064
{$ENDIF}
7165
// enum property
72-
function EnumAttributeNames(Index:Integer):WideString; stdcall;
73-
property TagName:WideString read GetTagName write SetTagName;
66+
function EnumAttributeNames(Index:Integer):String; stdcall;
67+
property TagName:String read GetTagName write SetTagName;
7468
property ChildrenCount:Integer read GetChildrenCount;
7569
property Children[index:Integer]:IHtmlElement read GetChildren; default;
7670
property CloseTag:IHtmlElement read GetCloseTag;
77-
property Content:WideString read GetContent;
78-
property Orignal:WideString read GetOrignal;
71+
property Content:String read GetContent;
72+
property Orignal:String read GetOrignal;
7973
property Parent:IHtmlElement read GetParent;
8074
// Get the position of an element in the source code
8175
property SourceLineNum:Integer read GetSourceLineNum;
8276
property SourceColNum:Integer read GetSourceColNum;
8377
//
84-
property InnerHtml:WideString read GetInnerHtml;
85-
property OuterHtml:WideString read GetOuterHtml;
86-
property InnerText:WideString read GetInnerText write SetInnerText;
87-
property Text:WideString read GetInnerText write SetInnerText;
88-
property Attributes[Key:WideString]:WideString read GetAttributes write SetAttributes;
78+
property InnerHtml:String read GetInnerHtml;
79+
property OuterHtml:String read GetOuterHtml;
80+
property InnerText:String read GetInnerText write SetInnerText;
81+
property Text:String read GetInnerText write SetInnerText;
82+
property Attributes[Key:String]:String read GetAttributes write SetAttributes;
8983
// ying32 does not change the original, just simplifies the use
90-
property Attrs[Key:WideString]:WideString read GetAttributes write SetAttributes;
84+
property Attrs[Key:String]:String read GetAttributes write SetAttributes;
9185
end;
9286

9387

@@ -110,15 +104,15 @@ THtmlListEnumerator = class
110104
procedure RemoveAll; stdcall;
111105
procedure Remove(ANode:IHtmlElement); stdcall;
112106
procedure Each(f:TElementEachEvent); stdcall;
113-
function GetText:WideString; stdcall;
107+
function GetText:String; stdcall;
114108
function GetEnumerator:THtmlListEnumerator;
115-
property Text:WideString read GetText;
109+
property Text:String read GetText;
116110
property Count:Integer read GetCount;
117111
property Items[index:Integer]:IHtmlElement read GetItems; default;
118112
end;
119113

120114

121-
function ParserHTML(const Source:WideString):IHtmlElement; stdcall;
115+
function ParserHTML(const Source:String):IHtmlElement; stdcall;
122116
function DecodeHtmlEntities(S:string):string; forward;
123117

124118
implementation
@@ -217,19 +211,19 @@ THtmlElement = class(TInterfacedObject, IHtmlElement)
217211
protected
218212
// ying32
219213
function GetParent:IHtmlElement; stdcall;
220-
function GetTagName:WideString; stdcall;
221-
procedure SetTagName(Value:WideString); stdcall;
222-
function GetContent:WideString; stdcall;
223-
function GetOrignal:WideString; stdcall;
214+
function GetTagName:String; stdcall;
215+
procedure SetTagName(Value:String); stdcall;
216+
function GetContent:String; stdcall;
217+
function GetOrignal:String; stdcall;
224218
function GetChildrenCount:Integer; stdcall;
225219
function GetChildren(Index:Integer):IHtmlElement; stdcall;
226220
function GetCloseTag:IHtmlElement; stdcall;
227-
function GetInnerHtml():WideString; stdcall;
228-
function GetOuterHtml():WideString; stdcall;
229-
function GetInnerText():WideString; stdcall;
230-
procedure SetInnerText(Value:WideString); stdcall;
231-
function GetAttributes(Key:WideString):WideString; stdcall;
232-
procedure SetAttributes(Key:WideString; Value:WideString); stdcall;
221+
function GetInnerHtml():String; stdcall;
222+
function GetOuterHtml():String; stdcall;
223+
function GetInnerText():String; stdcall;
224+
procedure SetInnerText(Value:String); stdcall;
225+
function GetAttributes(Key:String):String; stdcall;
226+
procedure SetAttributes(Key:String; Value:String); stdcall;
233227
procedure RemoveAttr(AAttrName:string); stdcall;
234228
function GetSourceLineNum():Integer; stdcall;
235229
function GetSourceColNum():Integer; stdcall;
@@ -239,32 +233,32 @@ THtmlElement = class(TInterfacedObject, IHtmlElement)
239233
function AppedChild(const ATag:string):IHtmlElement; stdcall;
240234

241235
// Does the property exist
242-
function HasAttribute(AttributeName:WideString):Boolean; stdcall;
236+
function HasAttribute(AttributeName:String):Boolean; stdcall;
243237
{ Find Element with CSS selector syntax, does not support "pseudo-class"
244238
http://www.w3.org/TR/CSS2/selector.html
245239
}
246-
function SimpleCSSSelector(const selector:WideString):IHtmlElementList; stdcall;
247-
function Find(const selector:WideString):IHtmlElementList; stdcall;
240+
function SimpleCSSSelector(const selector:String):IHtmlElementList; stdcall;
241+
function Find(const selector:String):IHtmlElementList; stdcall;
248242
{$IFDEF UseXPath}
249-
function FindX(const AXPath:WideString):IHtmlElementList; stdcall;
243+
function FindX(const AXPath:String):IHtmlElementList; stdcall;
250244
{$ENDIF}
251245
// enum property
252-
function EnumAttributeNames(Index:Integer):WideString; stdcall;
253-
property TagName:WideString read GetTagName write SetTagName;
246+
function EnumAttributeNames(Index:Integer):String; stdcall;
247+
property TagName:String read GetTagName write SetTagName;
254248
property ChildrenCount:Integer read GetChildrenCount;
255249
property Children[index:Integer]:IHtmlElement read GetChildren; default;
256250
property CloseTag:IHtmlElement read GetCloseTag;
257-
property Content:WideString read GetContent;
258-
property Orignal:WideString read GetOrignal;
251+
property Content:String read GetContent;
252+
property Orignal:String read GetOrignal;
259253
property Parent:IHtmlElement read GetParent;
260254
// Get the position of an element in the source code
261255
property SourceLineNum:Integer read GetSourceLineNum;
262256
property SourceColNum:Integer read GetSourceColNum;
263257
//
264-
property InnerHtml:WideString read GetInnerHtml;
265-
property OuterHtml:WideString read GetOuterHtml;
266-
property InnerText:WideString read GetInnerText;
267-
property Attributes[Key:WideString]:WideString read GetAttributes write SetAttributes;
258+
property InnerHtml:String read GetInnerHtml;
259+
property OuterHtml:String read GetOuterHtml;
260+
property InnerText:String read GetInnerText;
261+
property Attributes[Key:String]:String read GetAttributes write SetAttributes;
268262
property Childrens:IHtmlElementList read GetChildrens;
269263
private
270264
FClosed:Boolean;
@@ -305,7 +299,7 @@ TIHtmlElementList = class(TInterfacedObject, IHtmlElementList)
305299
procedure RemoveAll; stdcall;
306300
procedure Remove(ANode:IHtmlElement); stdcall;
307301
procedure Each(f:TElementEachEvent); stdcall;
308-
function GetText:WideString; stdcall;
302+
function GetText:String; stdcall;
309303
public
310304
constructor Create;
311305
destructor Destroy; override;
@@ -1040,7 +1034,7 @@ function BuildTree(ElementList:THtmlElementList):THtmlElement;
10401034
end;
10411035

10421036

1043-
function ParserHTML(const Source:WideString):IHtmlElement; stdcall;
1037+
function ParserHTML(const Source:String):IHtmlElement; stdcall;
10441038
var
10451039
ElementList:THtmlElementList;
10461040
begin
@@ -1592,7 +1586,7 @@ function TIHtmlElementList.GetItems(Index:Integer):IHtmlElement;
15921586
end;
15931587

15941588

1595-
function TIHtmlElementList.GetText:WideString;
1589+
function TIHtmlElementList.GetText:String;
15961590
var
15971591
LEL:IHtmlElement;
15981592
begin
@@ -1673,7 +1667,7 @@ function THtmlElement.AppedChild(const ATag:string):IHtmlElement;
16731667
end;
16741668

16751669

1676-
function THtmlElement.EnumAttributeNames(Index:Integer):WideString;
1670+
function THtmlElement.EnumAttributeNames(Index:Integer):String;
16771671
var
16781672
Attrs:TStringDynArray;
16791673
begin
@@ -1684,7 +1678,7 @@ function THtmlElement.EnumAttributeNames(Index:Integer):WideString;
16841678
end;
16851679

16861680

1687-
function THtmlElement.GetAttributes(Key:WideString):WideString;
1681+
function THtmlElement.GetAttributes(Key:String):String;
16881682
begin
16891683
Result := '';
16901684
Key := LowerCase(Key);
@@ -1717,7 +1711,7 @@ function THtmlElement.GetCloseTag:IHtmlElement;
17171711
end;
17181712

17191713

1720-
function THtmlElement.GetContent:WideString;
1714+
function THtmlElement.GetContent:String;
17211715
begin
17221716
Result := FContent;
17231717
end;
@@ -1878,7 +1872,7 @@ procedure THtmlElement._SimpleCSSSelector(const ItemGroup:TCSSSelectorItemGroup;
18781872
end;
18791873

18801874

1881-
function THtmlElement.GetInnerHtml:WideString;
1875+
function THtmlElement.GetInnerHtml:String;
18821876
var
18831877
Sb:TStringBuilder;
18841878
begin
@@ -1889,7 +1883,7 @@ function THtmlElement.GetInnerHtml:WideString;
18891883
end;
18901884

18911885

1892-
function THtmlElement.GetInnerText:WideString;
1886+
function THtmlElement.GetInnerText:String;
18931887
var
18941888
Sb:TStringBuilder;
18951889
begin
@@ -1900,13 +1894,13 @@ function THtmlElement.GetInnerText:WideString;
19001894
end;
19011895

19021896

1903-
function THtmlElement.GetOrignal:WideString;
1897+
function THtmlElement.GetOrignal:String;
19041898
begin
19051899
Result := FOrignal;
19061900
end;
19071901

19081902

1909-
function THtmlElement.GetOuterHtml:WideString;
1903+
function THtmlElement.GetOuterHtml:String;
19101904
var
19111905
Sb:TStringBuilder;
19121906
begin
@@ -1935,13 +1929,13 @@ function THtmlElement.GetSourceLineNum:Integer;
19351929
end;
19361930

19371931

1938-
function THtmlElement.GetTagName:WideString;
1932+
function THtmlElement.GetTagName:String;
19391933
begin
19401934
Result := FTagName;
19411935
end;
19421936

19431937

1944-
function THtmlElement.HasAttribute(AttributeName:WideString):Boolean;
1938+
function THtmlElement.HasAttribute(AttributeName:String):Boolean;
19451939
begin
19461940
Result := FAttributes.ContainsKey(LowerCase(AttributeName));
19471941
end;
@@ -1973,27 +1967,27 @@ procedure THtmlElement.RemoveAttr(AAttrName:string);
19731967
end;
19741968

19751969

1976-
procedure THtmlElement.SetAttributes(Key:WideString; Value:WideString);
1970+
procedure THtmlElement.SetAttributes(Key:String; Value:String);
19771971
begin
19781972
FAttributes.AddOrSetValue(LowerCase(Key), Value);
19791973
end;
19801974

19811975

1982-
procedure THtmlElement.SetInnerText(Value:WideString);
1976+
procedure THtmlElement.SetInnerText(Value:String);
19831977
begin
19841978
FContent := Value;
19851979
end;
19861980

19871981

1988-
procedure THtmlElement.SetTagName(Value:WideString);
1982+
procedure THtmlElement.SetTagName(Value:String);
19891983
begin
19901984
FTagName := UpperCase(Value);
19911985
if FCloseTag <> nil then
19921986
FCloseTag.TagName := Self.FTagName;
19931987
end;
19941988

19951989

1996-
function THtmlElement.SimpleCSSSelector(const selector:WideString):IHtmlElementList;
1990+
function THtmlElement.SimpleCSSSelector(const selector:String):IHtmlElementList;
19971991
var
19981992
r:TIHtmlElementList;
19991993
begin
@@ -2003,7 +1997,7 @@ function THtmlElement.SimpleCSSSelector(const selector:WideString):IHtmlElementL
20031997
end;
20041998

20051999

2006-
function THtmlElement.Find(const selector:WideString):IHtmlElementList;
2000+
function THtmlElement.Find(const selector:String):IHtmlElementList;
20072001
begin
20082002
Result := SimpleCSSSelector(selector);
20092003
end;
@@ -2012,7 +2006,7 @@ function THtmlElement.Find(const selector:WideString):IHtmlElementList;
20122006
function XPathToCSSSelector(const AXPath:string):string; forward;
20132007

20142008

2015-
function THtmlElement.FindX(const AXPath:WideString):IHtmlElementList;
2009+
function THtmlElement.FindX(const AXPath:String):IHtmlElementList;
20162010
begin
20172011
Result := SimpleCSSSelector(XPathToCSSSelector(AXPath));
20182012
end;

0 commit comments

Comments
 (0)