Browse Source

* ppudump: Proper output of Unicode string constants.

git-svn-id: trunk@24410 -
yury 12 years ago
parent
commit
eb26ccfbe7
2 changed files with 24 additions and 10 deletions
  1. 11 3
      compiler/utils/ppuutils/ppudump.pp
  2. 13 7
      compiler/utils/ppuutils/ppuxml.pp

+ 11 - 3
compiler/utils/ppuutils/ppudump.pp

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

+ 13 - 7
compiler/utils/ppuutils/ppuxml.pp

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