roxen.lists.pike.general

Subject Author Date
GILD THE LILY? PeterPan <zenothing[at]hotmail[dot]com> 07-04-2009
I dump my chinese strings using sprintf("%O"), got things such as
"547566555", totally unreadable.
I see, direct dumping non-latin char maybe bother some other ones, so I
shouldn't think only about the requirement of myself.

Then I decide to write some tool to help myself. I wrote some like this:

class VARINFO(mixed v)/*{{{*/
{
        string _sprintf(int t)
        {
                if(t=='O'||t=='s'){
                        string out="";
                        string s=sprintf("%O",v);
                        for(int i=0;i<sizeof(s);i++){
                                if(i+3<sizeof(s)&&s[i]=='\'
                                                &&s[i+1]>='0'&&s[i+1]<='9'
                                                &&s[i+2]>='0'&&s[i+2]<='9'
                                                &&s[i+3]>='0'&&s[i+3]<='9'
                                  ){
                                       
out+=sprintf("%c",((s[i+1]-'0')*8+(s[i+2]-'0'))*8+(s[i+3]-'0'));
                                        i+=3;
                                }else if(i+1<sizeof(s)&&s[i]=='"'&&s[i+1]=='"'){
                                        i+=1;
                                }else{
                                        out+=sprintf("%c",s[i]);
                                }
                        }
                        return out;
                }
        }
}/*}}}*/

it works, when I use it as following:

write("%s\n",VARINFO((["大家好":1])));

it result: 

([ /* 1 element */
  "大家好": 1
])

And write("%O\n",VARINFO((["大家好":1]))); works too with Pike v7.6 release 112.

But with Pike v7.8 release 116 the result is:

([ /* 1 element */
  "\u00e5\u00a4\u00a7\u00e5\u00ae\u00b6\u00e5\u00a5\u00bd": 1
])


Why escape it ?

If one write _sprintf, he of course known what he want! If he want \u things, he
can printf it himself.