Ver código fonte

* PChar -> PAnsiChar

Michaël Van Canneyt 2 anos atrás
pai
commit
827606f114

+ 1 - 1
packages/fcl-xml/src/dom.pp

@@ -2151,7 +2151,7 @@ begin
         Exit;
       end;
     // Name validity has already been checked by IsXmlName() call above.
-    // So just check that colon isn't first or last char, and that it is follwed by NameStartChar.
+    // So just check that colon isn't first or last AnsiChar, and that it is follwed by NameStartChar.
     if ((Result = 1) or (Result = L) or not IsXmlName(@QName[Result+1], 1)) then
     begin
       Result := -NAMESPACE_ERR;

+ 3 - 3
packages/fcl-xml/src/htmldefs.pp

@@ -36,7 +36,7 @@ type
   THTMLCharsets = THTMLCData;
   THTMLContentTypes = THTMLCData;
   THTMLURI = string;
-  THTMLCharacter = char;
+  THTMLCharacter = AnsiChar;
 
   THTMLDir = (dirEmpty,dirLeftToRight,dirRightToLeft);
   THTMLalign = (alEmpty,alleft,alcenter,alright,aljustify,alchar);
@@ -364,7 +364,7 @@ const
 
   HTMLAttributeTag : array [THTMLAttributeTag] of String = (
       'abbr', 'alink', 'accept-charset', 'accept', 'accesskey', 'action', 'align', 'alt', 'archive',
-      'axis', 'background', 'bgcolor', 'border', 'cellpadding', 'cellspacing', 'char', 'charoff', 'charset',
+      'axis', 'background', 'bgcolor', 'border', 'cellpadding', 'cellspacing', 'AnsiChar', 'charoff', 'charset',
       'checked', 'cite', 'class', 'classid', 'clear', 'code', 'codebase', 'codetype', 'color', 'cols',
       'colspan', 'compact', 'content', 'coords', 'data', 'datetime', 'declare', 'defer',
       'dir', 'disabled', 'enctype', 'face', 'for', 'frame', 'frameborder', 'headers',
@@ -383,7 +383,7 @@ const
     ('Black', 'Silver', 'Gray', 'White', 'Maroon', 'Red', 'Purple', 'Fuchsia',
      'Green', 'Lime', 'Olive', 'Yellow', 'Navy', 'Blue', 'Teal', 'Aqua');
   HTMLDir : array [THTMLDir] of string = ('','LTR','RTL');
-  HTMLAlign : array [THTMLalign] of string = ('','left','center','right','justify','char');
+  HTMLAlign : array [THTMLalign] of string = ('','left','center','right','justify','AnsiChar');
   HTMLvalign : array [THTMLvalign] of string = ('','top','middle','bottom','baseline');
   HTMLframe : array [THTMLframe] of string =
       ('','void','above','below','hsides','vsides','lhs','rhs','box','border');

+ 18 - 18
packages/fcl-xml/src/htmwrite.pp

@@ -47,8 +47,8 @@ type
     FStream: TStream;
     FInsideTextNode: Boolean;
     FInsideScript: Boolean;
-    FBuffer: PChar;
-    FBufPos: PChar;
+    FBuffer: PAnsiChar;
+    FBufPos: PAnsiChar;
     FCapacity: Integer;
     FLineBreak: string;
     procedure wrtChars(Src: PWideChar; Length: Integer);
@@ -102,7 +102,7 @@ var
 begin
   if Count>0 then
   begin
-    SetString(s, PChar(@Buffer), Count);
+    SetString(s, PAnsiChar(@Buffer), Count);
     system.Write(f^, s);
   end;
   Result := Count;
@@ -136,7 +136,7 @@ end;
 
 procedure THTMLWriter.wrtChars(Src: PWideChar; Length: Integer);
 var
-  pb: PChar;
+  pb: PAnsiChar;
   wc: Cardinal;
   SrcEnd: PWideChar;
 begin
@@ -154,20 +154,20 @@ begin
 
     wc := Cardinal(Src^);  Inc(Src);
     case wc of
-      $0A: pb := StrECopy(pb, PChar(FLineBreak));
+      $0A: pb := StrECopy(pb, PAnsiChar(FLineBreak));
       $0D: begin
-        pb := StrECopy(pb, PChar(FLineBreak));
+        pb := StrECopy(pb, PAnsiChar(FLineBreak));
         if (Src < SrcEnd) and (Src^ = #$0A) then
           Inc(Src);
       end;
 
       0..$09, $0B, $0C, $0E..$7F:  begin
-        pb^ := char(wc); Inc(pb);
+        pb^ := AnsiChar(wc); Inc(pb);
       end;
 
       $80..$7FF: begin
-        pb^ := Char($C0 or (wc shr 6));
-        pb[1] := Char($80 or (wc and $3F));
+        pb^ := AnsiChar($C0 or (wc shr 6));
+        pb[1] := AnsiChar($80 or (wc and $3F));
         Inc(pb,2);
       end;
 
@@ -177,10 +177,10 @@ begin
           wc := ((LongInt(wc) - $D7C0) shl 10) + LongInt(word(Src^) xor $DC00);
           Inc(Src);
 
-          pb^ := Char($F0 or (wc shr 18));
-          pb[1] := Char($80 or ((wc shr 12) and $3F));
-          pb[2] := Char($80 or ((wc shr 6) and $3F));
-          pb[3] := Char($80 or (wc and $3F));
+          pb^ := AnsiChar($F0 or (wc shr 18));
+          pb[1] := AnsiChar($80 or ((wc shr 12) and $3F));
+          pb[2] := AnsiChar($80 or ((wc shr 6) and $3F));
+          pb[3] := AnsiChar($80 or (wc and $3F));
           Inc(pb,4);
         end
         else
@@ -190,9 +190,9 @@ begin
         raise EConvertError.Create('Low surrogate without high one');
       else   // $800 >= wc > $FFFF, excluding surrogates
       begin
-        pb^ := Char($E0 or (wc shr 12));
-        pb[1] := Char($80 or ((wc shr 6) and $3F));
-        pb[2] := Char($80 or (wc and $3F));
+        pb^ := AnsiChar($E0 or (wc shr 12));
+        pb[1] := AnsiChar($80 or ((wc shr 6) and $3F));
+        pb[2] := AnsiChar($80 or (wc and $3F));
         Inc(pb,3);
       end;
     end;
@@ -208,7 +208,7 @@ end;
 { No checks here - buffer always has 32 extra bytes }
 procedure THTMLWriter.wrtChr(c: WideChar); { inline }
 begin
-  FBufPos^ := char(ord(c));
+  FBufPos^ := AnsiChar(ord(c));
   Inc(FBufPos);
 end;
 
@@ -245,7 +245,7 @@ begin
   EndPos := 1;
   while EndPos <= Length(s) do
   begin
-    if (s[EndPos] < #255) and (Char(ord(s[EndPos])) in SpecialChars) then
+    if (s[EndPos] < #255) and (AnsiChar(ord(s[EndPos])) in SpecialChars) then
     begin
       wrtChars(@s[StartPos], EndPos - StartPos);
       SpecialCharCallback(s[EndPos]);

+ 3 - 3
packages/fcl-xml/src/sax_html.pp

@@ -56,7 +56,7 @@ type
     FRawTokenText: string;
     FScriptEndTag: string;
     FScriptEndMatchPos: Integer;
-    FCurStringValueDelimiter: Char;
+    FCurStringValueDelimiter: AnsiChar;
     FAttrNameRead: Boolean;
     FStack: array of THTMLElementTag;
     FNesting: Integer;
@@ -158,10 +158,10 @@ procedure THTMLReader.Parse(AInput: TSAXInputSource);
 const
   MaxBufferSize = 1024;
 var
-  Buffer: array[0..MaxBufferSize - 1] of Char;
+  Buffer: array[0..MaxBufferSize - 1] of AnsiChar;
   BufferSize, BufferPos: Integer;
   len: Integer;
-  ch: Char;
+  ch: AnsiChar;
 begin
   if not FStarted then
   begin

+ 2 - 2
packages/fcl-xml/src/sax_xml.pp

@@ -43,7 +43,7 @@ type
     FScannerContext: TXMLScannerContext;
     FTokenText: SAXString;
     FRawTokenText: string;
-    FCurStringValueDelimiter: Char;
+    FCurStringValueDelimiter: AnsiChar;
     FAttrNameRead: Boolean;
   protected
     procedure EnterNewScannerContext(NewContext: TXMLScannerContext);
@@ -138,7 +138,7 @@ procedure TSAXXMLReader.Parse(AInput: TSAXInputSource);
 const
   MaxBufferSize = 1024;
 var
-  Buffer: array[0..MaxBufferSize - 1] of Char;
+  Buffer: array[0..MaxBufferSize - 1] of AnsiChar;
   BufferSize, BufferPos: Integer;
 begin
   if not FStarted then

+ 8 - 8
packages/fcl-xml/src/tagsintf.inc

@@ -169,7 +169,7 @@
   public
     constructor create (AOwner: TDOMDocument); override;
     property align : THTMLalign read Getalign write Setalign;
-    property char : DOMString index atchar read GetAttribute write SetAttribute;
+    property AnsiChar : DOMString index atchar read GetAttribute write SetAttribute;
     property charoff : DOMString index atcharoff read GetAttribute write SetAttribute;
     property span : DOMString index atspan read GetAttribute write SetAttribute;
     property valign : THTMLvalign read Getvalign write Setvalign;
@@ -185,7 +185,7 @@
   public
     constructor create (AOwner: TDOMDocument); override;
     property align : THTMLalign read Getalign write Setalign;
-    property char : DOMString index atchar read GetAttribute write SetAttribute;
+    property AnsiChar : DOMString index atchar read GetAttribute write SetAttribute;
     property charoff : DOMString index atcharoff read GetAttribute write SetAttribute;
     property span : DOMString index atspan read GetAttribute write SetAttribute;
     property valign : THTMLvalign read Getvalign write Setvalign;
@@ -653,7 +653,7 @@
   public
     constructor create (AOwner: TDOMDocument); override;
     property align : THTMLalign read Getalign write Setalign;
-    property char : DOMString index atchar read GetAttribute write SetAttribute;
+    property AnsiChar : DOMString index atchar read GetAttribute write SetAttribute;
     property charoff : DOMString index atcharoff read GetAttribute write SetAttribute;
     property valign : THTMLvalign read Getvalign write Setvalign;
   end;
@@ -669,7 +669,7 @@
     property abbr : DOMString index atabbr read GetAttribute write SetAttribute;
     property align : THTMLalign read Getalign write Setalign;
     property axis : DOMString index ataxis read GetAttribute write SetAttribute;
-    property char : DOMString index atchar read GetAttribute write SetAttribute;
+    property AnsiChar : DOMString index atchar read GetAttribute write SetAttribute;
     property charoff : DOMString index atcharoff read GetAttribute write SetAttribute;
     property colspan : DOMString index atcolspan read GetAttribute write SetAttribute;
     property headers : DOMString index atheaders read GetAttribute write SetAttribute;
@@ -708,7 +708,7 @@
   public
     constructor create (AOwner: TDOMDocument); override;
     property align : THTMLalign read Getalign write Setalign;
-    property char : DOMString index atchar read GetAttribute write SetAttribute;
+    property AnsiChar : DOMString index atchar read GetAttribute write SetAttribute;
     property charoff : DOMString index atcharoff read GetAttribute write SetAttribute;
     property valign : THTMLvalign read Getvalign write Setvalign;
   end;
@@ -724,7 +724,7 @@
     property abbr : DOMString index atabbr read GetAttribute write SetAttribute;
     property align : THTMLalign read Getalign write Setalign;
     property axis : DOMString index ataxis read GetAttribute write SetAttribute;
-    property char : DOMString index atchar read GetAttribute write SetAttribute;
+    property AnsiChar : DOMString index atchar read GetAttribute write SetAttribute;
     property charoff : DOMString index atcharoff read GetAttribute write SetAttribute;
     property colspan : DOMString index atcolspan read GetAttribute write SetAttribute;
     property headers : DOMString index atheaders read GetAttribute write SetAttribute;
@@ -742,7 +742,7 @@
   public
     constructor create (AOwner: TDOMDocument); override;
     property align : THTMLalign read Getalign write Setalign;
-    property char : DOMString index atchar read GetAttribute write SetAttribute;
+    property AnsiChar : DOMString index atchar read GetAttribute write SetAttribute;
     property charoff : DOMString index atcharoff read GetAttribute write SetAttribute;
     property valign : THTMLvalign read Getvalign write Setvalign;
   end;
@@ -761,7 +761,7 @@
   public
     constructor create (AOwner: TDOMDocument); override;
     property align : THTMLalign read Getalign write Setalign;
-    property char : DOMString index atchar read GetAttribute write SetAttribute;
+    property AnsiChar : DOMString index atchar read GetAttribute write SetAttribute;
     property charoff : DOMString index atcharoff read GetAttribute write SetAttribute;
     property valign : THTMLvalign read Getvalign write Setvalign;
   end;

+ 2 - 2
packages/fcl-xml/src/xmliconv.pas

@@ -28,7 +28,7 @@ const
   utf16_encoding = 'UTF-16BE';
 {$endif  FPC_LITTLE_ENDIAN}
 
-function Iconv_Decode(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+function Iconv_Decode(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
 var
   OutChars: size_t;
   InChars: size_t;
@@ -60,7 +60,7 @@ function GetIconvDecoder(const AEncoding: string; out Decoder: TDecoder): Boolea
 var
   f: iconv_t;
 begin
-  f := iconv_open(utf16_encoding, PChar(AEncoding));
+  f := iconv_open(utf16_encoding, PAnsiChar(AEncoding));
   if f <> Pointer(-1) then
   begin
     Decoder.Context := f;

+ 4 - 4
packages/fcl-xml/src/xmliconv_windows.pas

@@ -29,13 +29,13 @@ type
 const
   iconvlib = 'iconv.dll';
 
-function iconv_open(ToCode, FromCode: PChar): iconv_t; cdecl; external iconvlib name 'libiconv_open';
-function iconv(__cd: iconv_t; __inbuf: PPChar; var __inbytesleft: size_t; __outbuf:ppchar; var __outbytesleft: size_t): size_t; cdecl; external iconvlib name 'libiconv';
+function iconv_open(ToCode, FromCode: PAnsiChar): iconv_t; cdecl; external iconvlib name 'libiconv_open';
+function iconv(__cd: iconv_t; __inbuf: PPAnsiChar; var __inbytesleft: size_t; __outbuf:PPAnsiChar; var __outbytesleft: size_t): size_t; cdecl; external iconvlib name 'libiconv';
 function iconv_close(cd: iconv_t): Integer; cdecl; external iconvlib name 'libiconv_close';
 
 function errno_location: PInteger; cdecl; external 'msvcrt.dll' name '_errno';
 
-function Iconv_Decode(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+function Iconv_Decode(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
 var
   OutChars: size_t;
   InChars : size_t;
@@ -66,7 +66,7 @@ function GetIconvDecoder(const AEncoding: string; out Decoder: TDecoder): Boolea
 var
   f: iconv_t;
 begin
-  f := iconv_open('UCS-2-INTERNAL', PChar(AEncoding));
+  f := iconv_open('UCS-2-INTERNAL', PAnsiChar(AEncoding));
   if f <> Pointer(-1) then
   begin
     Decoder.Context := f;

+ 43 - 6
packages/fcl-xml/src/xmlreader.pp

@@ -51,22 +51,34 @@ type
     rsClosed
   );
 
+  { TXMLInputSource }
+  TInputSourceType = (istStream,istAnsi,istUnicode,istSystemID);
+
   TXMLInputSource = class(TObject)
   private
+    FInputSourceType: TInputSourceType;
     FStream: TStream;
-    FStringData: string;
+    FAnsiStringData : AnsiString;
+    FUnicodeStringData : UnicodeString;
     FBaseURI: XMLString;
     FSystemID: XMLString;
     FPublicID: XMLString;
+    function GetStringData: String;
+    procedure SetSystemID(AValue: XMLString);
 //    FEncoding: string;
   public
     constructor Create(AStream: TStream); overload;
-    constructor Create(const AStringData: string); overload;
+    constructor Create(const AStringData: AnsiString); overload;
+    constructor Create(const AStringData: UnicodeString); overload;
+
     property Stream: TStream read FStream;
-    property StringData: string read FStringData;
+    property AnsiStringData: AnsiString read FAnsiStringData;
+    property UnicodeStringData: UnicodeString read FUnicodeStringData;
+//    property StringData: String read GetStringData; deprecated 'Use AnsiStringData or UnicodeStringData';
     property BaseURI: XMLString read FBaseURI write FBaseURI;
-    property SystemID: XMLString read FSystemID write FSystemID;
+    property SystemID: XMLString read FSystemID write SetSystemID;
     property PublicID: XMLString read FPublicID write FPublicID;
+    Property InputSourceType : TInputSourceType Read FInputSourceType;
 //    property Encoding: string read FEncoding write FEncoding;
   end;
 
@@ -189,16 +201,41 @@ end;
 
 { TXMLInputSource }
 
+function TXMLInputSource.GetStringData: String;
+begin
+{$IF SIZEOF(CHAR)=2}
+  Result:=UnicodeStringData
+{$ELSE}
+  Result:=AnsiStringData
+{$ENDIF}
+end;
+
+procedure TXMLInputSource.SetSystemID(AValue: XMLString);
+begin
+  if FSystemID=AValue then Exit;
+  FSystemID:=AValue;
+  FInputSourceType:=istSystemID;
+end;
+
 constructor TXMLInputSource.Create(AStream: TStream);
 begin
   inherited Create;
   FStream := AStream;
+  FInputSourceType:=istStream;
+end;
+
+constructor TXMLInputSource.Create(const AStringData: AnsiString);
+begin
+  inherited Create;
+  FAnsiStringData:=aStringData;
+  FInputSourceType:=istAnsi;
 end;
 
-constructor TXMLInputSource.Create(const AStringData: string);
+constructor TXMLInputSource.Create(const AStringData: UnicodeString);
 begin
   inherited Create;
-  FStringData := AStringData;
+  FUnicodeStringData:=aStringData;
+  FInputSourceType:=istUnicode;
 end;
 
 { TXMLReaderSettings }

+ 1 - 1
packages/fcl-xml/src/xmlstreaming.pp

@@ -55,7 +55,7 @@ type
     procedure Write(const Buffer; Count: LongInt); override;
     procedure WriteBinary(const Buffer; Count: Longint); override;
     procedure WriteBoolean(Value: Boolean); override;
-    // procedure WriteChar(Value: Char);
+    // procedure WriteChar(Value: AnsiChar);
     procedure WriteFloat(const Value: Extended); override;
     procedure WriteSingle(const Value: Single); override;
     procedure WriteCurrency(const Value: Currency); override;

+ 41 - 25
packages/fcl-xml/src/xmltextreader.pp

@@ -25,7 +25,7 @@ uses
 type
   TDecoder = record
     Context: Pointer;
-    Decode: function(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+    Decode: function(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
     Cleanup: procedure(Context: Pointer); stdcall;
   end;
 
@@ -63,6 +63,7 @@ type
     function Matches(const arg: XMLString): Boolean;
     function MatchesLong(const arg: XMLString): Boolean;
     property SourceURI: XMLString read GetSourceURI write FSourceURI;
+
   end;
 
   TElementValidator = object
@@ -319,13 +320,14 @@ uses
 type
   TXMLDecodingSource = class(TXMLCharSource)
   private
-    FCharBuf: PChar;
-    FCharBufEnd: PChar;
+    FCharBuf: PAnsiChar;
+    FCharBufEnd: PAnsiChar;
     FBufStart: PWideChar;
     FDecoder: TDecoder;
     FHasBOM: Boolean;
     FFixedUCS2: string;
     FBufSize: Integer;
+    FAssumeUTF16: Boolean;
     procedure DecodingError(const Msg: string);
   protected
     function Reload: Boolean; override;
@@ -340,17 +342,20 @@ type
     procedure Initialize; override;
   end;
 
+  { TXMLStreamInputSource }
+
   TXMLStreamInputSource = class(TXMLDecodingSource)
   private
-    FAllocated: PChar;
+    FAllocated: PAnsiChar;
     FStream: TStream;
     FCapacity: Integer;
     FOwnStream: Boolean;
     FEof: Boolean;
   public
-    constructor Create(AStream: TStream; AOwnStream: Boolean);
+    constructor Create(AStream: TStream; AOwnStream: Boolean; aAssumeUTF16 : Boolean = False);
     destructor Destroy; override;
     procedure FetchData; override;
+    Property AssumeUTF16 : Boolean Read FAssumeUTF16;
   end;
 
   TXMLFileInputSource = class(TXMLDecodingSource)
@@ -473,9 +478,9 @@ begin
   repeat
     if FBuf^ = #10 then
       NewLine;
-    if (FBuf^ < #255) and (Char(ord(FBuf^)) in Delim) then
+    if (FBuf^ < #255) and (AnsiChar(ord(FBuf^)) in Delim) then
       Break;
-    if (FBuf^ > #32) or not (Char(ord(FBuf^)) in [#32, #9, #10, #13]) then
+    if (FBuf^ > #32) or not (AnsiChar(ord(FBuf^)) in [#32, #9, #10, #13]) then
       nonws := True;
     Inc(FBuf);
   until False;
@@ -584,7 +589,7 @@ begin
 
   repeat
     inLeft := FCharBufEnd - FCharBuf;
-    if inLeft < 4 then                      // may contain an incomplete char
+    if inLeft < 4 then                      // may contain an incomplete AnsiChar
     begin
       FetchData;
       inLeft := FCharBufEnd - FCharBuf;
@@ -603,7 +608,7 @@ begin
     if r + FBufEnd <= FBufStart + FBufSize then
       FBufEnd := FBufStart + FBufSize - r
     else
-      DecodingError('Decoder error: output char count out of bounds');
+      DecodingError('Decoder error: output AnsiChar count out of bounds');
 
     if rslt = 0 then
       Break
@@ -624,7 +629,13 @@ procedure TXMLDecodingSource.Initialize;
 begin
   inherited;
   FLineNo := 1;
-  FDecoder.Decode := @Decode_UTF8;
+  if FAssumeUTF16 then
+    begin
+    FFixedUCS2 := {$IFNDEF ENDIAN_BIG} 'UTF-16BE' {$ELSE} 'UTF-16LE' {$ENDIF};
+    FDecoder.Decode := @Decode_UCS2;
+    end
+  else
+    FDecoder.Decode := @Decode_UTF8;
 
   FFixedUCS2 := '';
   if FCharBufEnd-FCharBuf > 1 then
@@ -713,7 +724,7 @@ end;
 const
   Slack = 16;
 
-constructor TXMLStreamInputSource.Create(AStream: TStream; AOwnStream: Boolean);
+constructor TXMLStreamInputSource.Create(AStream: TStream; AOwnStream: Boolean; aAssumeUTF16 : Boolean = False);
 begin
   FStream := AStream;
   FCapacity := 4096;
@@ -722,6 +733,7 @@ begin
   FCharBufEnd := FCharBuf;
   FOwnStream := AOwnStream;
   FetchData;
+  FAssumeUTF16:=aAssumeUTF16;
 end;
 
 destructor TXMLStreamInputSource.Destroy;
@@ -735,7 +747,7 @@ end;
 procedure TXMLStreamInputSource.FetchData;
 var
   Remainder, BytesRead: Integer;
-  OldBuf: PChar;
+  OldBuf: PAnsiChar;
 begin
   Assert(FCharBufEnd - FCharBuf < Slack-4);
   if FEof then
@@ -780,7 +792,7 @@ begin
     FString := FString + #10;    // bad solution...
     if Remainder > 0 then
       Insert(FTmp, FString, 1);
-    FCharBuf := PChar(FString);
+    FCharBuf := PAnsiChar(FString);
     FCharBufEnd := FCharBuf + Length(FString);
   end;
 end;
@@ -823,12 +835,16 @@ begin
   SrcOut := nil;
   if Assigned(SrcIn) then
   begin
-    if Assigned(SrcIn.Stream) then
-      SrcOut := TXMLStreamInputSource.Create(SrcIn.Stream, False)
-    else if SrcIn.StringData <> '' then
-      SrcOut := TXMLStreamInputSource.Create(TStringStream.Create(SrcIn.StringData), True)
-    else if (SrcIn.SystemID <> '') then
+    Case SrcIn.InputSourceType of
+    istStream:
+      SrcOut := TXMLStreamInputSource.Create(SrcIn.Stream, False);
+    istAnsi:
+      SrcOut := TXMLStreamInputSource.Create(TStringStream.Create(SrcIn.AnsiStringData), True, False);
+    istUnicode:
+      SrcOut := TXMLStreamInputSource.Create(TStringStream.Create(SrcIn.UnicodeStringData,TEncoding.Unicode), True, True);
+    istSystemID:
       ResolveResource(SrcIn.SystemID, SrcIn.PublicID, SrcIn.BaseURI, SrcOut);
+    end;
   end;
   if (SrcOut = nil) and (FSource = nil) then
     DoErrorPos(esFatal, 'No input source specified', NullLocation);
@@ -864,7 +880,7 @@ begin
     if fd <> THandle(-1) then
     begin
       Stream := THandleOwnerStream.Create(fd);
-      Source := TXMLStreamInputSource.Create(Stream, True);
+      Source := TXMLStreamInputSource.Create(Stream, True, False);
       Source.SourceURI := SrcURI;
     end;
   end;
@@ -1261,7 +1277,7 @@ begin
         Inc(p, 2)
       else
       begin
-  // here we come either when first char of name is bad (it may be a colon),
+  // here we come either when first AnsiChar of name is bad (it may be a colon),
   // or when a colon is not followed by a valid NameStartChar
         FSource.FBuf := p;
         Result := False;
@@ -1831,8 +1847,8 @@ begin
     SkipQuote(Delim);
     I := 0;
     while (I < 30) and (FSource.FBuf^ <> Delim) and (FSource.FBuf^ < #127) and
-      ((Char(ord(FSource.FBuf^)) in ['A'..'Z', 'a'..'z']) or
-      ((I > 0) and (Char(ord(FSource.FBuf^)) in ['0'..'9', '.', '-', '_']))) do
+      ((AnsiChar(ord(FSource.FBuf^)) in ['A'..'Z', 'a'..'z']) or
+      ((I > 0) and (AnsiChar(ord(FSource.FBuf^)) in ['0'..'9', '.', '-', '_']))) do
     begin
       buf[I] := FSource.FBuf^;
       Inc(I);
@@ -2965,7 +2981,7 @@ begin
   FCurrNode^.FValueLength := 0;
   FCurrNode^.FValueStr := '';
   StoreLocation(FCurrNode^.FLoc);
-  { point past '&' to first char of entity name }
+  { point past '&' to first AnsiChar of entity name }
   Dec(FCurrNode^.FLoc.LinePos, FName.Length+1);
 end;
 
@@ -3040,7 +3056,7 @@ begin
         (wc <> #9)) or (wc > #$FFFD) or
         (FXML11Rules and (wc >= #$7F) and (wc <= #$9F)) then
              FReader.FatalError('Invalid character');
-      if (wc < #255) and (Char(ord(wc)) in Delim) then
+      if (wc < #255) and (AnsiChar(ord(wc)) in Delim) then
         Break;
 // the checks above filter away everything below #32 that isn't a whitespace
       if wc > #32 then
@@ -3719,7 +3735,7 @@ begin
     for I := 1 to Length(PubID) do
     begin
       wc := PubID[I];
-      if (wc > #255) or not (Char(ord(wc)) in PubidChars) then
+      if (wc > #255) or not (AnsiChar(ord(wc)) in PubidChars) then
         FatalError('Illegal Public ID literal', -1);
     end;
   end

+ 12 - 12
packages/fcl-xml/src/xmlutils.pp

@@ -24,7 +24,7 @@ uses
 
 type
   TXMLVersion = (xmlVersionUnknown, xmlVersion10, xmlVersion11);
-  TSetOfChar = set of Char;
+  TSetOfChar = set of AnsiChar;
   XMLString = UnicodeString;
   PXMLString = ^XMLString;
   PXMLChar = PWideChar;
@@ -249,10 +249,10 @@ procedure BufNormalize(var Buf: TWideCharBuf; out Modified: Boolean);
 
 { Built-in decoder functions for UTF-8, UTF-16 and ISO-8859-1 }
 
-function Decode_UCS2(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
-function Decode_UCS2_Swapped(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
-function Decode_UTF8(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
-function Decode_8859_1(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+function Decode_UCS2(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+function Decode_UCS2_Swapped(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+function Decode_UTF8(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+function Decode_8859_1(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
 
 {$i names.inc}
 
@@ -376,10 +376,10 @@ var
   I: Integer;
 begin
   Result := False;
-  if (Value = '') or (Value[1] > #255) or not (char(ord(Value[1])) in ['A'..'Z', 'a'..'z']) then
+  if (Value = '') or (Value[1] > #255) or not (AnsiChar(ord(Value[1])) in ['A'..'Z', 'a'..'z']) then
     Exit;
   for I := 2 to Length(Value) do
-    if (Value[I] > #255) or not (char(ord(Value[I])) in ['A'..'Z', 'a'..'z', '0'..'9', '.', '_', '-']) then
+    if (Value[I] > #255) or not (AnsiChar(ord(Value[I])) in ['A'..'Z', 'a'..'z', '0'..'9', '.', '_', '-']) then
       Exit;
   Result := True;
 end;
@@ -1012,7 +1012,7 @@ end;
 
 { standard decoders }
 
-function Decode_UCS2(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+function Decode_UCS2(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
 var
   cnt: Cardinal;
 begin
@@ -1025,11 +1025,11 @@ begin
   Result := cnt;
 end;
 
-function Decode_UCS2_Swapped(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+function Decode_UCS2_Swapped(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
 var
   I: Integer;
   cnt: Cardinal;
-  InPtr: PChar;
+  InPtr: PAnsiChar;
 begin
   cnt := OutCnt;         // num of widechars
   if cnt > InCnt div sizeof(WideChar) then
@@ -1045,7 +1045,7 @@ begin
   Result := cnt;
 end;
 
-function Decode_8859_1(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+function Decode_8859_1(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
 var
   I: Integer;
   cnt: Cardinal;
@@ -1060,7 +1060,7 @@ begin
   Result := cnt;
 end;
 
-function Decode_UTF8(Context: Pointer; InBuf: PChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
+function Decode_UTF8(Context: Pointer; InBuf: PAnsiChar; var InCnt: Cardinal; OutBuf: PWideChar; var OutCnt: Cardinal): Integer; stdcall;
 const
   MaxCode: array[1..4] of Cardinal = ($7F, $7FF, $FFFF, $1FFFFF);
 var

+ 17 - 17
packages/fcl-xml/src/xmlwrite.pp

@@ -44,8 +44,8 @@ Type
     FCanonical: Boolean;
     FIndent: XMLString;
     FNesting: Integer;
-    FBuffer: PChar;
-    FBufPos: PChar;
+    FBuffer: PAnsiChar;
+    FBufPos: PAnsiChar;
     FCapacity: Integer;
     FLineBreak: XMLString;
     FNSHelper: TNSSupport;
@@ -158,7 +158,7 @@ var
 begin
   if Count>0 then
   begin
-    SetString(s, PChar(@Buffer), Count);
+    SetString(s, PAnsiChar(@Buffer), Count);
     system.Write(f^, s);
   end;
   Result := Count;
@@ -177,7 +177,7 @@ const
   AmpStr = '&amp;';
   ltStr = '&lt;';
   gtStr = '&gt;';
-  IndentChars : Array[Boolean] of char = (' ',#9);
+  IndentChars : Array[Boolean] of AnsiChar = (' ',#9);
 
 procedure AttrSpecialCharCallback(Sender: TXMLWriter; const s: DOMString;
   var idx: Integer);
@@ -338,7 +338,7 @@ end;
 
 procedure TXMLWriter.wrtChars(Src: PWideChar; Length: Integer);
 var
-  pb: PChar;
+  pb: PAnsiChar;
   wc: Cardinal;
   SrcEnd: PWideChar;
 begin
@@ -357,12 +357,12 @@ begin
     wc := Cardinal(Src^);  Inc(Src);
     case wc of
       0..$7F:  begin
-        pb^ := char(wc); Inc(pb);
+        pb^ := AnsiChar(wc); Inc(pb);
       end;
 
       $80..$7FF: begin
-        pb^ := Char($C0 or (wc shr 6));
-        pb[1] := Char($80 or (wc and $3F));
+        pb^ := AnsiChar($C0 or (wc shr 6));
+        pb[1] := AnsiChar($80 or (wc and $3F));
         Inc(pb,2);
       end;
 
@@ -372,10 +372,10 @@ begin
           wc := ((LongInt(wc) - $D7C0) shl 10) + LongInt(word(Src^) xor $DC00);
           Inc(Src);
 
-          pb^ := Char($F0 or (wc shr 18));
-          pb[1] := Char($80 or ((wc shr 12) and $3F));
-          pb[2] := Char($80 or ((wc shr 6) and $3F));
-          pb[3] := Char($80 or (wc and $3F));
+          pb^ := AnsiChar($F0 or (wc shr 18));
+          pb[1] := AnsiChar($80 or ((wc shr 12) and $3F));
+          pb[2] := AnsiChar($80 or ((wc shr 6) and $3F));
+          pb[3] := AnsiChar($80 or (wc and $3F));
           Inc(pb,4);
         end
         else
@@ -385,9 +385,9 @@ begin
         raise EConvertError.Create('Low surrogate without high one');
       else   // $800 >= wc > $FFFF, excluding surrogates
       begin
-        pb^ := Char($E0 or (wc shr 12));
-        pb[1] := Char($80 or ((wc shr 6) and $3F));
-        pb[2] := Char($80 or (wc and $3F));
+        pb^ := AnsiChar($E0 or (wc shr 12));
+        pb[1] := AnsiChar($80 or ((wc shr 6) and $3F));
+        pb[2] := AnsiChar($80 or (wc and $3F));
         Inc(pb,3);
       end;
     end;
@@ -403,7 +403,7 @@ end;
 { No checks here - buffer always has 32 extra bytes }
 procedure TXMLWriter.wrtChr(c: WideChar); { inline }
 begin
-  FBufPos^ := char(ord(c));
+  FBufPos^ := AnsiChar(ord(c));
   Inc(FBufPos);
 end;
 
@@ -449,7 +449,7 @@ begin
   EndPos := 1;
   while EndPos <= Length(s) do
   begin
-    if (s[EndPos] < #128) and (Char(ord(s[EndPos])) in SpecialChars) then
+    if (s[EndPos] < #128) and (AnsiChar(ord(s[EndPos])) in SpecialChars) then
     begin
       wrtChars(@s[StartPos], EndPos - StartPos);
       SpecialCharCallback(Self, s, EndPos);

+ 3 - 3
packages/fcl-xml/src/xpath.pp

@@ -593,7 +593,7 @@ begin
     end;
     SetLength(S, P-Start);
   end
-  else  // no char removal possible
+  else  // no AnsiChar removal possible
     for I := 1 to Length(S) do
     begin
       J := Pos(S[I], SrcPat);
@@ -1625,7 +1625,7 @@ begin
       Inc(p)
     else
     begin
-      // either the first char of name is bad (it may be a colon),
+      // either the first AnsiChar of name is bad (it may be a colon),
       // or a colon is not followed by a valid NameStartChar
       Result := False;
       Break;
@@ -1664,7 +1664,7 @@ var
   Delim: WideChar;
 begin
   // Skip whitespace
-  while (FCurData[0] < #255) and (char(ord(FCurData[0])) in [#9, #10, #13, ' ']) do
+  while (FCurData[0] < #255) and (AnsiChar(ord(FCurData[0])) in [#9, #10, #13, ' ']) do
     Inc(FCurData);
 
   FTokenStart := FCurData;

+ 2 - 2
packages/fcl-xml/tests/domunit.pp

@@ -57,7 +57,7 @@ type
     procedure assertSize(const id: string; size: Integer; obj: TDOMNamedNodeMap);
     procedure assertInstanceOf(const id: string; obj: TObject; const typename: string);
     procedure assertURIEquals(const id: string;
-      scheme, path, host, file_, name, query, fragment: PChar;
+      scheme, path, host, file_, name, query, fragment: PAnsiChar;
       IsAbsolute: Boolean; const Actual: DOMString);
     function bad_condition(const TagName: XMLString): Boolean;
     property implementationAttribute[const name: string]: Boolean read getImplAttr write setImplAttr;
@@ -267,7 +267,7 @@ end;
 
 { expected args already UTF-8 encoded }
 procedure TDOMTestBase.assertURIEquals(const id: string; scheme, path,
-  host, file_, name, query, fragment: PChar; IsAbsolute: Boolean;
+  host, file_, name, query, fragment: PAnsiChar; IsAbsolute: Boolean;
   const Actual: DOMString);
 var
   URI: TURI;