* Declared the XMLString type to serve as a base string type for entire package, and aliased DOMString and SAXString to it (the type remains WideString; once all other units are adjusted it may be changed to UnicodeString).

* Replaced WideString by XMLString in xmlutils.pp.

git-svn-id: trunk@20394 -
This commit is contained in:
sergei 2012-02-21 20:23:35 +00:00
parent e7a8bc567d
commit 8df23e7bd0
3 changed files with 44 additions and 40 deletions

View File

@ -111,9 +111,9 @@ type
// DOMString // DOMString
// ------------------------------------------------------- // -------------------------------------------------------
TSetOfChar = set of Char; TSetOfChar = xmlutils.TSetOfChar; { to be removed: not used in DOM unit }
DOMString = WideString; DOMString = XMLString;
DOMPChar = PWideChar; DOMPChar = PXMLChar;
PDOMString = ^DOMString; PDOMString = ^DOMString;
EDOMError = class(Exception) EDOMError = class(Exception)
@ -2076,9 +2076,9 @@ begin
// QName contains prefix, but no namespace // QName contains prefix, but no namespace
if ((nsIdx = 0) and (Result > 0)) or if ((nsIdx = 0) and (Result > 0)) or
// Bad usage of 'http://www.w3.org/2000/xmlns/' // Bad usage of 'http://www.w3.org/2000/xmlns/'
((((L = 5) or (Result = 6)) and (Pos(WideString('xmlns'), QName) = 1)) <> (nsIdx = 2)) or ((((L = 5) or (Result = 6)) and (Pos(DOMString('xmlns'), QName) = 1)) <> (nsIdx = 2)) or
// Bad usage of 'http://www.w3.org/XML/1998/namespace' // Bad usage of 'http://www.w3.org/XML/1998/namespace'
((Result = 4) and (Pos(WideString('xml'), QName) = 1) and (nsIdx <> 1)) then ((Result = 4) and (Pos(DOMString('xml'), QName) = 1) and (nsIdx <> 1)) then
Result := -NAMESPACE_ERR; Result := -NAMESPACE_ERR;
end; end;

View File

@ -23,7 +23,7 @@ unit SAX;
interface interface
uses SysUtils, Classes; uses SysUtils, Classes, xmlutils;
resourcestring resourcestring
SSAXAttributeIndexError = 'Invalid attribute index %d'; SSAXAttributeIndexError = 'Invalid attribute index %d';
@ -35,9 +35,9 @@ const
type type
SAXString = WideString; SAXString = XMLString;
SAXChar = WideChar; SAXChar = WideChar;
PSAXChar = ^SAXChar; PSAXChar = PXMLChar;
{ Exceptions } { Exceptions }

View File

@ -22,25 +22,29 @@ interface
uses uses
SysUtils, Classes; SysUtils, Classes;
function IsXmlName(const Value: WideString; Xml11: Boolean = False): Boolean; overload; type
TXMLVersion = (xmlVersionUnknown, xmlVersion10, xmlVersion11);
TSetOfChar = set of Char;
XMLString = WideString;
PXMLChar = PWideChar;
function IsXmlName(const Value: XMLString; Xml11: Boolean = False): Boolean; overload;
function IsXmlName(Value: PWideChar; Len: Integer; Xml11: Boolean = False): Boolean; overload; function IsXmlName(Value: PWideChar; Len: Integer; Xml11: Boolean = False): Boolean; overload;
function IsXmlNames(const Value: WideString; Xml11: Boolean = False): Boolean; function IsXmlNames(const Value: XMLString; Xml11: Boolean = False): Boolean;
function IsXmlNmToken(const Value: WideString; Xml11: Boolean = False): Boolean; function IsXmlNmToken(const Value: XMLString; Xml11: Boolean = False): Boolean;
function IsXmlNmTokens(const Value: WideString; Xml11: Boolean = False): Boolean; function IsXmlNmTokens(const Value: XMLString; Xml11: Boolean = False): Boolean;
function IsValidXmlEncoding(const Value: WideString): Boolean; function IsValidXmlEncoding(const Value: XMLString): Boolean;
function Xml11NamePages: PByteArray; function Xml11NamePages: PByteArray;
procedure NormalizeSpaces(var Value: WideString); procedure NormalizeSpaces(var Value: XMLString);
function IsXmlWhiteSpace(c: WideChar): Boolean; function IsXmlWhiteSpace(c: WideChar): Boolean;
function Hash(InitValue: LongWord; Key: PWideChar; KeyLen: Integer): LongWord; function Hash(InitValue: LongWord; Key: PWideChar; KeyLen: Integer): LongWord;
{ beware, works in ASCII range only } { beware, works in ASCII range only }
function WStrLIComp(S1, S2: PWideChar; Len: Integer): Integer; function WStrLIComp(S1, S2: PWideChar; Len: Integer): Integer;
procedure WStrLower(var S: WideString); procedure WStrLower(var S: XMLString);
type
TXMLVersion = (xmlVersionUnknown, xmlVersion10, xmlVersion11);
const const
xmlVersionStr: array[TXMLVersion] of WideString = ('', '1.0', '1.1'); xmlVersionStr: array[TXMLVersion] of XMLString = ('', '1.0', '1.1');
type type
TXMLNodeType = (ntNone, ntElement, ntAttribute, ntText, TXMLNodeType = (ntNone, ntElement, ntAttribute, ntText,
@ -77,7 +81,7 @@ type
PPHashItem = ^PHashItem; PPHashItem = ^PHashItem;
PHashItem = ^THashItem; PHashItem = ^THashItem;
THashItem = record THashItem = record
Key: WideString; Key: XMLString;
HashValue: LongWord; HashValue: LongWord;
Next: PHashItem; Next: PHashItem;
Data: TObject; Data: TObject;
@ -102,7 +106,7 @@ type
function Find(Key: PWideChar; KeyLen: Integer): PHashItem; function Find(Key: PWideChar; KeyLen: Integer): PHashItem;
function FindOrAdd(Key: PWideChar; KeyLen: Integer; var Found: Boolean): PHashItem; overload; function FindOrAdd(Key: PWideChar; KeyLen: Integer; var Found: Boolean): PHashItem; overload;
function FindOrAdd(Key: PWideChar; KeyLen: Integer): PHashItem; overload; function FindOrAdd(Key: PWideChar; KeyLen: Integer): PHashItem; overload;
function FindOrAdd(const Key: WideString): PHashItem; overload; function FindOrAdd(const Key: XMLString): PHashItem; overload;
function Get(Key: PWideChar; KeyLen: Integer): TObject; function Get(Key: PWideChar; KeyLen: Integer): TObject;
function Remove(Entry: PHashItem): Boolean; function Remove(Entry: PHashItem): Boolean;
function RemoveData(aData: TObject): Boolean; function RemoveData(aData: TObject): Boolean;
@ -154,7 +158,7 @@ type
FIDEntry: PHashItem; // ID attributes: entry in ID map FIDEntry: PHashItem; // ID attributes: entry in ID map
FNodeType: TXMLNodeType; FNodeType: TXMLNodeType;
FValueStr: WideString; FValueStr: XMLString;
FValueStart: PWideChar; FValueStart: PWideChar;
FValueLength: Integer; FValueLength: Integer;
FIsDefault: Boolean; FIsDefault: Boolean;
@ -165,7 +169,7 @@ type
TBinding = class TBinding = class
public public
uri: WideString; uri: XMLString;
next: TBinding; next: TBinding;
prevPrefixBinding: TObject; prevPrefixBinding: TObject;
Prefix: PHashItem; Prefix: PHashItem;
@ -189,12 +193,12 @@ type
public public
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
procedure DefineBinding(const Prefix, nsURI: WideString; out Binding: TBinding); procedure DefineBinding(const Prefix, nsURI: XMLString; out Binding: TBinding);
function CheckAttribute(const Prefix, nsURI: WideString; function CheckAttribute(const Prefix, nsURI: XMLString;
out Binding: TBinding): TAttributeAction; out Binding: TBinding): TAttributeAction;
function IsPrefixBound(P: PWideChar; Len: Integer; out Prefix: PHashItem): Boolean; function IsPrefixBound(P: PWideChar; Len: Integer; out Prefix: PHashItem): Boolean;
function GetPrefix(P: PWideChar; Len: Integer): PHashItem; function GetPrefix(P: PWideChar; Len: Integer): PHashItem;
function BindPrefix(const nsURI: WideString; aPrefix: PHashItem): TBinding; function BindPrefix(const nsURI: XMLString; aPrefix: PHashItem): TBinding;
function DefaultNSBinding: TBinding; function DefaultNSBinding: TBinding;
procedure StartElement; procedure StartElement;
procedure EndElement; procedure EndElement;
@ -212,7 +216,7 @@ type
procedure BufAllocate(var ABuffer: TWideCharBuf; ALength: Integer); procedure BufAllocate(var ABuffer: TWideCharBuf; ALength: Integer);
procedure BufAppend(var ABuffer: TWideCharBuf; wc: WideChar); procedure BufAppend(var ABuffer: TWideCharBuf; wc: WideChar);
procedure BufAppendChunk(var ABuf: TWideCharBuf; pstart, pend: PWideChar); procedure BufAppendChunk(var ABuf: TWideCharBuf; pstart, pend: PWideChar);
function BufEquals(const ABuf: TWideCharBuf; const Arg: WideString): Boolean; function BufEquals(const ABuf: TWideCharBuf; const Arg: XMLString): Boolean;
procedure BufNormalize(var Buf: TWideCharBuf; out Modified: Boolean); procedure BufNormalize(var Buf: TWideCharBuf; out Modified: Boolean);
{ Built-in decoder functions for UTF-8, UTF-16 and ISO-8859-1 } { Built-in decoder functions for UTF-8, UTF-16 and ISO-8859-1 }
@ -268,7 +272,7 @@ begin
Result := False; Result := False;
end; end;
function IsXml11Char(const Value: WideString; var Index: Integer): Boolean; overload; function IsXml11Char(const Value: XMLString; var Index: Integer): Boolean; overload;
begin begin
if (Value[Index] >= #$D800) and (Value[Index] <= #$DB7F) then if (Value[Index] >= #$D800) and (Value[Index] <= #$DB7F) then
begin begin
@ -279,7 +283,7 @@ begin
Result := False; Result := False;
end; end;
function IsXmlName(const Value: WideString; Xml11: Boolean): Boolean; function IsXmlName(const Value: XMLString; Xml11: Boolean): Boolean;
begin begin
Result := IsXmlName(PWideChar(Value), Length(Value), Xml11); Result := IsXmlName(PWideChar(Value), Length(Value), Xml11);
end; end;
@ -312,7 +316,7 @@ begin
Result := True; Result := True;
end; end;
function IsXmlNames(const Value: WideString; Xml11: Boolean): Boolean; function IsXmlNames(const Value: XMLString; Xml11: Boolean): Boolean;
var var
Pages: PByteArray; Pages: PByteArray;
I: Integer; I: Integer;
@ -345,7 +349,7 @@ begin
Result := True; Result := True;
end; end;
function IsXmlNmToken(const Value: WideString; Xml11: Boolean): Boolean; function IsXmlNmToken(const Value: XMLString; Xml11: Boolean): Boolean;
var var
I: Integer; I: Integer;
Pages: PByteArray; Pages: PByteArray;
@ -369,7 +373,7 @@ begin
Result := True; Result := True;
end; end;
function IsXmlNmTokens(const Value: WideString; Xml11: Boolean): Boolean; function IsXmlNmTokens(const Value: XMLString; Xml11: Boolean): Boolean;
var var
I: Integer; I: Integer;
Pages: PByteArray; Pages: PByteArray;
@ -396,7 +400,7 @@ begin
Result := True; Result := True;
end; end;
function IsValidXmlEncoding(const Value: WideString): Boolean; function IsValidXmlEncoding(const Value: XMLString): Boolean;
var var
I: Integer; I: Integer;
begin begin
@ -409,7 +413,7 @@ begin
Result := True; Result := True;
end; end;
procedure NormalizeSpaces(var Value: WideString); procedure NormalizeSpaces(var Value: XMLString);
var var
I, J: Integer; I, J: Integer;
begin begin
@ -462,7 +466,7 @@ begin
result := c1 - c2; result := c1 - c2;
end; end;
procedure WStrLower(var S: WideString); procedure WStrLower(var S: XMLString);
var var
i: Integer; i: Integer;
begin begin
@ -484,7 +488,7 @@ begin
end; end;
end; end;
function KeyCompare(const Key1: WideString; Key2: Pointer; Key2Len: Integer): Boolean; function KeyCompare(const Key1: XMLString; Key2: Pointer; Key2Len: Integer): Boolean;
begin begin
{$IFDEF FPC} {$IFDEF FPC}
Result := (Length(Key1)=Key2Len) and (CompareWord(Pointer(Key1)^, Key2^, Key2Len) = 0); Result := (Length(Key1)=Key2Len) and (CompareWord(Pointer(Key1)^, Key2^, Key2Len) = 0);
@ -554,7 +558,7 @@ begin
Result := Lookup(Key, KeyLen, Dummy, True); Result := Lookup(Key, KeyLen, Dummy, True);
end; end;
function THashTable.FindOrAdd(const Key: WideString): PHashItem; function THashTable.FindOrAdd(const Key: XMLString): PHashItem;
var var
Dummy: Boolean; Dummy: Boolean;
begin begin
@ -791,7 +795,7 @@ begin
inherited Destroy; inherited Destroy;
end; end;
function TNSSupport.BindPrefix(const nsURI: WideString; aPrefix: PHashItem): TBinding; function TNSSupport.BindPrefix(const nsURI: XMLString; aPrefix: PHashItem): TBinding;
begin begin
{ try to reuse an existing binding } { try to reuse an existing binding }
result := FFreeBindings; result := FFreeBindings;
@ -819,7 +823,7 @@ begin
result := TBinding(FDefaultPrefix.Data); result := TBinding(FDefaultPrefix.Data);
end; end;
procedure TNSSupport.DefineBinding(const Prefix, nsURI: WideString; procedure TNSSupport.DefineBinding(const Prefix, nsURI: XMLString;
out Binding: TBinding); out Binding: TBinding);
var var
Pfx: PHashItem; Pfx: PHashItem;
@ -833,7 +837,7 @@ begin
Binding := nil; Binding := nil;
end; end;
function TNSSupport.CheckAttribute(const Prefix, nsURI: WideString; function TNSSupport.CheckAttribute(const Prefix, nsURI: XMLString;
out Binding: TBinding): TAttributeAction; out Binding: TBinding): TAttributeAction;
var var
Pfx: PHashItem; Pfx: PHashItem;
@ -968,7 +972,7 @@ begin
Inc(ABuf.Length, Len); Inc(ABuf.Length, Len);
end; end;
function BufEquals(const ABuf: TWideCharBuf; const Arg: WideString): Boolean; function BufEquals(const ABuf: TWideCharBuf; const Arg: XMLString): Boolean;
begin begin
Result := (ABuf.Length = Length(Arg)) and Result := (ABuf.Length = Length(Arg)) and
CompareMem(ABuf.Buffer, Pointer(Arg), ABuf.Length*sizeof(WideChar)); CompareMem(ABuf.Buffer, Pointer(Arg), ABuf.Length*sizeof(WideChar));