* ppudump: Proper output of Unicode string constants.

git-svn-id: trunk@24410 -
This commit is contained in:
yury 2013-05-03 15:04:50 +00:00
parent 906cd9d365
commit eb26ccfbe7
2 changed files with 24 additions and 10 deletions

View File

@ -2104,6 +2104,7 @@ var
startnewline : boolean;
i,j,len : longint;
prettyname, ss : ansistring;
ws: widestring;
guid : tguid;
realvalue : ppureal;
doublevalue : double;
@ -2209,6 +2210,7 @@ begin
writeln([space,' Value : "',pc,'"']);
constdef.ConstType:=ctStr;
SetString(constdef.VStr, pc, len);
constdef.VStr:=UTF8Encode(constdef.VStr);
freemem(pc,len+1);
end;
constreal :
@ -2284,6 +2286,9 @@ begin
begin
for i:=0 to pw^.len-1 do
pw^.data[i]:=ppufile.getword;
SetString(ws, PWideChar(pw^.data), pw^.len);
constdef.VStr:=UTF8Encode(ws);
constdef.ConstType:=ctStr;
end
else if widecharsize=4 then
begin
@ -2294,12 +2299,13 @@ begin
begin
WriteError('Unsupported tcompilerwidechar size');
end;
Writeln([space,'Wide string type']);
Write([space,'Wide string type']);
startnewline:=true;
for i:=0 to pw^.len-1 do
begin
if startnewline then
begin
writeln;
write(space);
startnewline:=false;
end;
@ -2308,12 +2314,14 @@ begin
write(hexstr(ch,4))
else
write(hexstr(ch,8));
if (i mod 8)= 0 then
if ((i + 1) mod 8)= 0 then
startnewline:=true
else
write(', ');
if i <> pw^.len-1 then
write(', ');
end;
donewidestring(pw);
Writeln;
end;
constguid:
begin

View File

@ -51,7 +51,9 @@ implementation
function TPpuXmlOutput.XmlStr(const s: string): string;
var
ps, pd: PAnsiChar;
ws: widestring;
ps: PWideChar;
pd: PAnsiChar;
slen, dlen, dpos: integer;
procedure _AddChar(c: ansichar);
@ -79,10 +81,11 @@ var
end;
var
c: ansichar;
c: widechar;
begin
ps:=PAnsiChar(s);
slen:=Length(s);
ws:=UTF8Decode(s);
ps:=PWideChar(ws);
slen:=Length(ws);
dlen:=slen + 2;
SetLength(Result, dlen);
pd:=PAnsiChar(Result);
@ -97,10 +100,13 @@ begin
'"': _AddStr('&quot;');
'\': _AddStr('\\');
else
if c < #32 then
_AddStr('\x' + hexStr(byte(c), 2))
if (c > #127) or (byte(c) in [9, 10, 13]) then
_AddStr('&#x' + hexStr(word(c), 4) + ';')
else
_AddChar(c);
if c < #32 then
_AddStr('\x' + hexStr(byte(c), 2))
else
_AddChar(c);
end;
Inc(ps);
Dec(slen);