* Encoding multibyte strings
@ 2016-04-08 7:09 Eric Abrahamsen
2016-04-08 7:28 ` Eli Zaretskii
[not found] ` <mailman.31.1460100539.7477.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 6+ messages in thread
From: Eric Abrahamsen @ 2016-04-08 7:09 UTC (permalink / raw)
To: help-gnu-emacs
Hi there.
I'm trying to get from this:
陈冬梅
to this:
CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E9=99=88=E5=86=AC=E6=A2=85
Assuming that the original characters were in utf-8, of course. So that
陈 is =E9=99=88, and so on.
I got this string by looking at a Vcard export from the Contacts app on
my Android phone. I'm trying to take an Emacs buffer and turn it into a
*.vcf card file to import into the same app -- basically I'm trying to
reverse-engineer the VCard encoding format so I can create a file to
feed to my phone.
I'm 99.9% sure that Emacs already comes with functions that will produce
my escaped coded string, but after many adventures with C-h f (during
which I learned quite a few unrelated tricks) I haven't found it. Can
someone enlighten me as to what the simplest way to do this is?
Thanks!
E
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding multibyte strings
2016-04-08 7:09 Encoding multibyte strings Eric Abrahamsen
@ 2016-04-08 7:28 ` Eli Zaretskii
2016-04-08 7:40 ` Eric Abrahamsen
[not found] ` <mailman.31.1460100539.7477.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2016-04-08 7:28 UTC (permalink / raw)
To: help-gnu-emacs
> From: Eric Abrahamsen <eric@ericabrahamsen.net>
> Date: Fri, 08 Apr 2016 15:09:55 +0800
>
> I'm trying to get from this:
>
> 陈冬梅
>
> to this:
>
> CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E9=99=88=E5=86=AC=E6=A2=85
>
> Assuming that the original characters were in utf-8, of course. So that
> 陈 is =E9=99=88, and so on.
>
> I got this string by looking at a Vcard export from the Contacts app on
> my Android phone. I'm trying to take an Emacs buffer and turn it into a
> *.vcf card file to import into the same app -- basically I'm trying to
> reverse-engineer the VCard encoding format so I can create a file to
> feed to my phone.
>
> I'm 99.9% sure that Emacs already comes with functions that will produce
> my escaped coded string, but after many adventures with C-h f (during
> which I learned quite a few unrelated tricks) I haven't found it. Can
> someone enlighten me as to what the simplest way to do this is?
Not sure what exactly are you looking for. A wild guess is that
(encode-coding-string 'utf-8 STRING)
and
(quoted-printable-encode-string STRING)
will do the job, IIUC.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding multibyte strings
2016-04-08 7:28 ` Eli Zaretskii
@ 2016-04-08 7:40 ` Eric Abrahamsen
2016-04-08 7:48 ` Eli Zaretskii
0 siblings, 1 reply; 6+ messages in thread
From: Eric Abrahamsen @ 2016-04-08 7:40 UTC (permalink / raw)
To: help-gnu-emacs
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Eric Abrahamsen <eric@ericabrahamsen.net>
>> Date: Fri, 08 Apr 2016 15:09:55 +0800
>>
>> I'm trying to get from this:
>>
>> 陈冬梅
>>
>> to this:
>>
>> CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E9=99=88=E5=86=AC=E6=A2=85
>>
>> Assuming that the original characters were in utf-8, of course. So that
>> 陈 is =E9=99=88, and so on.
>>
>> I got this string by looking at a Vcard export from the Contacts app on
>> my Android phone. I'm trying to take an Emacs buffer and turn it into a
>> *.vcf card file to import into the same app -- basically I'm trying to
>> reverse-engineer the VCard encoding format so I can create a file to
>> feed to my phone.
>>
>> I'm 99.9% sure that Emacs already comes with functions that will produce
>> my escaped coded string, but after many adventures with C-h f (during
>> which I learned quite a few unrelated tricks) I haven't found it. Can
>> someone enlighten me as to what the simplest way to do this is?
Hi Eli,
> Not sure what exactly are you looking for. A wild guess is that
What I'm looking for, I guess, is this:
(mystery-function "陈”) --> "=E9=99=88"
> (encode-coding-string 'utf-8 STRING)
(encode-coding-string "陈" 'utf-8) --> "\351\231\210"
So maybe what I need is a way to get from "\351\231\210" to "=E9=99=88"?
> and
>
> (quoted-printable-encode-string STRING)
(quoted-printable-encode-string "陈")
Evalling the above gives me the message "Multibyte character in QP
encoding region"
Thanks,
Eric
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding multibyte strings
2016-04-08 7:40 ` Eric Abrahamsen
@ 2016-04-08 7:48 ` Eli Zaretskii
2016-04-08 8:02 ` Eric Abrahamsen
0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2016-04-08 7:48 UTC (permalink / raw)
To: help-gnu-emacs
> From: Eric Abrahamsen <eric@ericabrahamsen.net>
> Date: Fri, 08 Apr 2016 15:40:31 +0800
>
> > Not sure what exactly are you looking for. A wild guess is that
>
> What I'm looking for, I guess, is this:
>
> (mystery-function "陈”) --> "=E9=99=88"
>
> > (encode-coding-string 'utf-8 STRING)
>
> (encode-coding-string "陈" 'utf-8) --> "\351\231\210"
>
> So maybe what I need is a way to get from "\351\231\210" to "=E9=99=88"?
>
> > and
> >
> > (quoted-printable-encode-string STRING)
>
> (quoted-printable-encode-string "陈")
>
> Evalling the above gives me the message "Multibyte character in QP
> encoding region"
I said "and", didn't I?
(quoted-printable-encode-string (encode-coding-string "陈" 'utf-8))
--> "=E9=99=88"
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding multibyte strings
2016-04-08 7:48 ` Eli Zaretskii
@ 2016-04-08 8:02 ` Eric Abrahamsen
0 siblings, 0 replies; 6+ messages in thread
From: Eric Abrahamsen @ 2016-04-08 8:02 UTC (permalink / raw)
To: help-gnu-emacs
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Eric Abrahamsen <eric@ericabrahamsen.net>
>> Date: Fri, 08 Apr 2016 15:40:31 +0800
>>
>> > Not sure what exactly are you looking for. A wild guess is that
>>
>> What I'm looking for, I guess, is this:
>>
>> (mystery-function "陈”) --> "=E9=99=88"
>>
>> > (encode-coding-string 'utf-8 STRING)
>>
>> (encode-coding-string "陈" 'utf-8) --> "\351\231\210"
>>
>> So maybe what I need is a way to get from "\351\231\210" to "=E9=99=88"?
>>
>> > and
>> >
>> > (quoted-printable-encode-string STRING)
>>
>> (quoted-printable-encode-string "陈")
>>
>> Evalling the above gives me the message "Multibyte character in QP
>> encoding region"
>
> I said "and", didn't I?
>
> (quoted-printable-encode-string (encode-coding-string "陈" 'utf-8))
> --> "=E9=99=88"
You did! And, as always, technically correct is the best kind of correct
:)
Thanks for this. Eventually I will soak up the appropriate knowledge
regarding string encoding, but it's taking a while.
Thanks again,
Eric
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding multibyte strings
[not found] ` <mailman.31.1460100539.7477.help-gnu-emacs@gnu.org>
@ 2016-04-08 18:53 ` B. T. Raven
0 siblings, 0 replies; 6+ messages in thread
From: B. T. Raven @ 2016-04-08 18:53 UTC (permalink / raw)
To: help-gnu-emacs
On 4/8/2016 02:28, Eli Zaretskii wrote:
>> From: Eric Abrahamsen <eric@ericabrahamsen.net>
>> Date: Fri, 08 Apr 2016 15:09:55 +0800
>>
>> I'm trying to get from this:
>>
>> 陈冬梅
>>
>> to this:
>>
>> CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E9=99=88=E5=86=AC=E6=A2=85
>>
>> Assuming that the original characters were in utf-8, of course. So that
>> 陈 is =E9=99=88, and so on.
>>
>> I got this string by looking at a Vcard export from the Contacts app on
>> my Android phone. I'm trying to take an Emacs buffer and turn it into a
>> *.vcf card file to import into the same app -- basically I'm trying to
>> reverse-engineer the VCard encoding format so I can create a file to
>> feed to my phone.
>>
>> I'm 99.9% sure that Emacs already comes with functions that will produce
>> my escaped coded string, but after many adventures with C-h f (during
>> which I learned quite a few unrelated tricks) I haven't found it. Can
>> someone enlighten me as to what the simplest way to do this is?
>
> Not sure what exactly are you looking for. A wild guess is that
>
> (encode-coding-string 'utf-8 STRING)
>
> and
>
> (quoted-printable-encode-string STRING)
>
> will do the job, IIUC.
>
(haxe-string-to-x-string "陈冬梅")
evaluated to this:
"\\xe9\\x99\\x88\\xe5\\x86\\xac\\xe6\\xa2\\x85"
that function and a discussion of the problem are here:
http://stackoverflow.com/questions/11085222/translate-unicode-utf-8-codepoint-to-bytes
hth,
Ed
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-04-08 18:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-08 7:09 Encoding multibyte strings Eric Abrahamsen
2016-04-08 7:28 ` Eli Zaretskii
2016-04-08 7:40 ` Eric Abrahamsen
2016-04-08 7:48 ` Eli Zaretskii
2016-04-08 8:02 ` Eric Abrahamsen
[not found] ` <mailman.31.1460100539.7477.help-gnu-emacs@gnu.org>
2016-04-08 18:53 ` B. T. Raven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).