roxen.lists.pike.general

Subject Author Date
Re: GILD THE LILY? PeterPan <zenothing[at]hotmail[dot]com> 08-04-2009
It not, see this, I add a werror before VARINFO return:

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]);
                                }
                        }
                        werror("%s\n",out);
                        return out;
                }
        }
}/*}}}*/
void main()
{
        write("%O\n",VARINFO((["大家好":1])));
}

the output is:

[<peterpan[at]brain> ~]$ pike varinfo.pike
([ /* 1 element */
  "大家好": 1
])
([ /* 1 element */
  "\u00e5\u00a4\u00a7\u00e5\u00ae\u00b6\u00e5\u00a5\u00bd": 1
])

it is escaped after VARINFO return.


--------------------------------------------------
From: "Martin Stjernholm" <<mast[at]lysator.liu.se>>
Sent: Wednesday, April 08, 2009 2:22 AM
To: "PeterPan" <<zenothing[at]hotmail.com>>
Cc: <<pike[at]roxen.com>>
Subject: Re: GILD THE LILY?

> "PeterPan" <<zenothing[at]hotmail.com>> wrote:
>
>> 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 ?
>
> Pike has only switched escape method from \oooooo to \uxxxx. If you
> update your VARINFO class to handle \u escapes then it should work
> again.
>
> That aside, the stdout and stderr handling could be better when they
> are connected to a terminal. In that case pike should look at the
> locale settings and encode charsets appropriately, so that the output
> streams can accept unicode strings. I don't quite know how the
> terminal stuff works, but it obviously doesn't handle this entirely
> well.
>