summaryrefslogtreecommitdiff
path: root/packages/fcl-xml/src/xmlutils.pp
diff options
context:
space:
mode:
authormichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-02-13 10:31:09 +0000
committermichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-02-13 10:31:09 +0000
commitcd12e355a60b116cd582e3d5700dd8932d2ae4da (patch)
tree5ce3b2dc9823bd337b69a68d1ca4a2c863b02c62 /packages/fcl-xml/src/xmlutils.pp
parentd0eea255fd04048b8d5f12b250485bf85e53258a (diff)
downloadfpc-cd12e355a60b116cd582e3d5700dd8932d2ae4da.tar.gz
* Patch from Sergei Gorelkin:
fcl-xml/src/dom.pp: resolved a number of Level 1 conformance issues: * Node.Normalize always deletes empty text nodes * Node.Normalize is recursive into Attributes * Node.InsertBefore corrected exception code in case when RefChild is not one of node's children + Node.InsertBefore added missing check for possible cycle in tree + Node.AppendChild and Node.InsertBefore added checking type of NewChild + CloneNode enabled for Fragment and Entity - CloneNode deleted for DocumentType (w3 specs directly prohibit cloning it between documents, and cloning within one document is claimed 'implementation specific' - but makes no sense). + Node.ImportNode is now working * Uncommented Level 2 node properties (NamespaceURI, localName and Prefix), this caused a name clash and a lot of function argument renames. fcl-xml/src/xmlutils.pp: + overloaded IsXmlName() that accepts PWideChars fcl-xml/src/xmlconf.pp * Applied a fix similar to xmlcfg.pp for Mantis #10554 fcl-xml/src/xmlread.pp: * Major: Got errors reported at correct locations for all 1600+ negative tests. Easy to say, but it required modifying almost every second line of code. * TContentParticle references an existing element definition instead of storing its own name (this allows content model matching without string comparisons). * Resorted to old-style 'object' for TElementValidator and to plain procedures for decoders (allows to drop almost all related memory management). * Moved parameter entity detection from char to token level, this simplifies things a bit. + Added second level of buffering to input source (a step towards supporting arbitrary encodings). * The main parsing loop contains no implicit exception frames now. fcl-xml/src/xmlwrite.pp * Replaced the stupid indenting algorithm with a simple rule: "Do not write indents adjacent to text nodes". Now it does not make a mess out of the documents which were parsed with PreserveWhitespace=True. * Use specialized node properties instead of generic ones, this eliminates WideString copies and results in almost 2x performance boost in Windows. * Even more performance: * Write line endings together with indents -> twice less calls. * Increase slack in buffer and write strings with known length (i.e. most of markup) without overflow checking. fcl-xml/tests/xmlts.pp: * Use parser options instead of dedicated procedure to 'canonicalize' documents, the parser has become mature enough to do that. * Fatal error in non-valid category is a test failure, as well as validation error alone in not-wellformed category. fcl-xml/src/README * Brought a bit up to date fcl-xml/tests/README + Added testsuite errata/issues git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@10314 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fcl-xml/src/xmlutils.pp')
-rw-r--r--packages/fcl-xml/src/xmlutils.pp27
1 files changed, 22 insertions, 5 deletions
diff --git a/packages/fcl-xml/src/xmlutils.pp b/packages/fcl-xml/src/xmlutils.pp
index 4bb8a75b23..11c0f3e0cc 100644
--- a/packages/fcl-xml/src/xmlutils.pp
+++ b/packages/fcl-xml/src/xmlutils.pp
@@ -22,7 +22,8 @@ interface
uses
SysUtils;
-function IsXmlName(const Value: WideString; Xml11: Boolean = False): Boolean;
+function IsXmlName(const Value: WideString; 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 IsXmlNmToken(const Value: WideString; Xml11: Boolean = False): Boolean;
function IsXmlNmTokens(const Value: WideString; Xml11: Boolean = False): Boolean;
@@ -64,7 +65,18 @@ begin
Result := Xml11Pg;
end;
-function IsXml11Char(const Value: WideString; var Index: Integer): Boolean;
+function IsXml11Char(Value: PWideChar; var Index: Integer): Boolean; overload;
+begin
+ if (Value[Index] >= #$D800) and (Value[Index] <= #$DB7F) then
+ begin
+ Inc(Index);
+ Result := (Value[Index] >= #$DC00) and (Value[Index] <= #$DFFF);
+ end
+ else
+ Result := False;
+end;
+
+function IsXml11Char(const Value: WideString; var Index: Integer): Boolean; overload;
begin
if (Value[Index] >= #$D800) and (Value[Index] <= #$DB7F) then
begin
@@ -76,6 +88,11 @@ begin
end;
function IsXmlName(const Value: WideString; Xml11: Boolean): Boolean;
+begin
+ Result := IsXmlName(PWideChar(Value), Length(Value), Xml11);
+end;
+
+function IsXmlName(Value: PWideChar; Len: Integer; Xml11: Boolean = False): Boolean; overload;
var
Pages: PByteArray;
I: Integer;
@@ -86,12 +103,12 @@ begin
else
Pages := @NamePages;
- I := 1;
- if (Value = '') or not ((Byte(Value[I]) in NamingBitmap[Pages^[hi(Word(Value[I]))]]) or
+ I := 0;
+ if (Len = 0) or not ((Byte(Value[I]) in NamingBitmap[Pages^[hi(Word(Value[I]))]]) or
(Xml11 and IsXml11Char(Value, I))) then
Exit;
Inc(I);
- while I <= Length(Value) do
+ while I < Len do
begin
if not ((Byte(Value[I]) in NamingBitmap[Pages^[$100+hi(Word(Value[I]))]]) or
(Xml11 and IsXml11Char(Value, I))) then