[fpc-devel] XML Components

Andrew Brunner atbrunner at aurawin.com
Sat Nov 3 22:42:41 CET 2012


I just added this Prepare method to my database API.

class function XML.IsInvalid(var Value:Byte):boolean;
begin
   Result:=(Value<9) or (Value=11) or (Value=12) or ( (Value>13) and 
(Value<32));
end;

class function  XML.Prepare(var sInput:string; Refactor:TStream):string;
var
   bChar:byte;
   iLcv:Int64;
   iLen:Int64;
   sReplace:string;
begin
   Refactor.Size:=0;
   for iLcv:=1 to System.Length(sInput) do begin
     bChar:=Byte(sInput[iLcv]);
     if IsInvalid(bChar) then begin
       sReplace:=Concat('&#',IntToStr(bChar),';');
       iLen:=System.Length(sReplace);
       Refactor.Write(sReplace[1],iLen);
     end else
       Refactor.Write(bChar,1);
   end;
   System.SetLength(Result,Refactor.Size);
   if Refactor.Size>0 then
     Refactor.Read(Result[1],Refactor.Size);
   Refactor.Size:=0;
end;

The question is, what is going to happen when the encoding is UTF8 or 
UTF16?  Will this code allow bytes to go by without messing them all up?


-- 
Andrew Brunner

Aurawin LLC
512.574.6298
http://aurawin.com/

Aurawin is a great new way to store, share, and enjoy your
photos, videos, music and more.




More information about the fpc-devel mailing list