diff options
| author | ivost <ivost@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2010-03-03 18:54:46 +0000 |
|---|---|---|
| committer | ivost <ivost@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2010-03-03 18:54:46 +0000 |
| commit | 0b980d9eaf5e8636a8b0f4bc7a797f2a58e11494 (patch) | |
| tree | e58aa7b1dd003f35eeba547329d3e983ec0fc5b1 | |
| parent | ce9ef74af67cd88e00a4f7ad6cf66e30aa4eb614 (diff) | |
| download | fpc-0b980d9eaf5e8636a8b0f4bc7a797f2a58e11494.tar.gz | |
* fxied xsdTryParseStringLower (SetLength allocated a string but then append char was used -> resulted in leading zeros)
* optimized xsdTryParseStringLower
* optimized xsdTryParseString
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@14968 3ad0048d-3df7-0310-abae-a5850022a9f2
| -rw-r--r-- | packages/libxml/src/xmlxsd.pas | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/packages/libxml/src/xmlxsd.pas b/packages/libxml/src/xmlxsd.pas index 9d5f3c80d3..a135f0e586 100644 --- a/packages/libxml/src/xmlxsd.pas +++ b/packages/libxml/src/xmlxsd.pas @@ -860,9 +860,51 @@ begin end; function xsdTryParseString(Chars: xmlCharPtr; Len: Integer; out Value: Utf8String): Boolean; +const + AllocChars = 256; +var + P,L,D: PByte; begin if Assigned(Chars) then begin + P := PByte(Chars); + if Len >= 0 then + begin + L := P + Len; + SetLength(Value, Len); + D := @Value[1]; + while P < L do + begin + D^ := P^; + Inc(D); + Inc(P); + end; + end else begin + SetLength(Value, AllocChars); + D := @Value[1]; + L := D + AllocChars; + while P^ <> 0 do + begin + if D = L then + begin + Len := Length(Value); + SetLength(Value, Len+AllocChars); + D := @Value[Len+1]; + L := D + AllocChars; + end; + D^ := P^; + Inc(D); + Inc(P); + end; + SetLength(Value, P-PByte(Chars)); + end; + Result := True; + end else + Result := False; +end; +{begin + if Assigned(Chars) then + begin if Len >= 0 then begin SetLength(Value, Len); @@ -872,9 +914,11 @@ begin Result := True; end else Result := False; -end; +end;} function xsdTryParseStringLower(Chars: xmlCharPtr; Len: Integer; out Value: Utf8String): Boolean; +const + AllocChars = 256; var P,L,D: PByte; C: Byte; @@ -896,15 +940,25 @@ begin Inc(P); end; end else begin - SetLength(Value, 255); - //D := @Value[1]; + SetLength(Value, AllocChars); + D := @Value[1]; + L := D + AllocChars; while P^ <> 0 do begin C := P^; if (C>=65) and (C<=90) then Inc(C, 32); - Value := Value + Chr(C); {$warning assign char by char maybe quite slow!} + if D = L then + begin + Len := Length(Value); + SetLength(Value, Len+AllocChars); + D := @Value[Len+1]; + L := D + AllocChars; + end; + D^ := C; + Inc(D); Inc(P); end; + SetLength(Value, P-PByte(Chars)); end; Result := True; end else |
