unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* base64-encode-string confusion
@ 2008-08-26 11:17 İsmail Dönmez
  2008-08-26 13:16 ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: İsmail Dönmez @ 2008-08-26 11:17 UTC (permalink / raw
  To: emacs- devel

Hello Emacsers,

http://www.gnu.org/software/emacs/elisp/html_node/Base-64.html
specifically mentions :

<quote>
— Function: base64-encode-string string &optional no-line-break

    This function converts the string string into base 64 code. It
returns a string containing the encoded text. As for
base64-encode-region, *an error is signaled if a character in the
string is multibyte*.
</quote>

Emphasis mine. So essentially it says base64-encode-string will fail
with non-ascii input. But looking at the source code in src/fns.c
function base64_encode_1 has the following signature:

static int
base64_encode_1 (from, to, length, line_break, multibyte)

The last parameter is set to be 1 if the input is multibyte so this
function is supposed to accept multibyte characters it seems. Still at
src/fns.c line 3345 it says :

  encoded_length = base64_encode_1 (SDATA (string),
                                    encoded, length, NILP (no_line_break),
                                    STRING_MULTIBYTE (string));

Looks like STRING_MULTIBYTE macro tries to detect if string is
multibyte or not. So far so good. But trying to base64 encode a
non-ascii character fails :

(base64-encode-string "€") gives

Debugger entered--Lisp error: (error "Multibyte character in data for
base64 encoding")

which is in line with the documentation but doesn't agree with the
code. Am I missing something here?

Regards,
ismail

-- 
Programmer Excuse #26: I suspect it's a bus collision.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: base64-encode-string confusion
  2008-08-26 11:17 base64-encode-string confusion İsmail Dönmez
@ 2008-08-26 13:16 ` Andreas Schwab
  2008-08-26 13:28   ` İsmail Dönmez
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2008-08-26 13:16 UTC (permalink / raw
  To: İsmail Dönmez; +Cc: emacs- devel

"İsmail Dönmez" <ismail@namtrac.org> writes:

> Looks like STRING_MULTIBYTE macro tries to detect if string is
> multibyte or not.

Just because a string is multibyte does not mean that any characters in
it are multibyte.  You can have a multibyte string consiting only of
8-bit characters, which is perfectly valid for base64-encode-string.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: base64-encode-string confusion
  2008-08-26 13:16 ` Andreas Schwab
@ 2008-08-26 13:28   ` İsmail Dönmez
  2008-08-26 13:49     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: İsmail Dönmez @ 2008-08-26 13:28 UTC (permalink / raw
  To: Andreas Schwab; +Cc: emacs- devel

Hi,

On Tue, Aug 26, 2008 at 16:16, Andreas Schwab <schwab@suse.de> wrote:
> "İsmail Dönmez" <ismail@namtrac.org> writes:
>
>> Looks like STRING_MULTIBYTE macro tries to detect if string is
>> multibyte or not.
>
> Just because a string is multibyte does not mean that any characters in
> it are multibyte.  You can have a multibyte string consiting only of
> 8-bit characters, which is perfectly valid for base64-encode-string.

So here I guess multibyte != non-ascii ? The actual problem I am
facing is base64-encode-string doesn't support non-ascii characters,
but I guess the code will have to be modified for that.

Regards,
ismail

-- 
Programmer Excuse #26: I suspect it's a bus collision.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: base64-encode-string confusion
  2008-08-26 13:28   ` İsmail Dönmez
@ 2008-08-26 13:49     ` Stefan Monnier
  2008-08-26 15:57       ` İsmail Dönmez
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2008-08-26 13:49 UTC (permalink / raw
  To: İsmail Dönmez; +Cc: Andreas Schwab, emacs- devel

> So here I guess multibyte != non-ascii ? The actual problem I am
> facing is base64-encode-string doesn't support non-ascii characters,

base64 is a way to encode a *byte sequence* in a way that is "email
safe".  I.e. it does not accept any characters: only bytes.
If you want to encode a char sequence using base64, you first need to
convert your char sequence into a byte sequence, using
encode-coding-string.


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: base64-encode-string confusion
  2008-08-26 13:49     ` Stefan Monnier
@ 2008-08-26 15:57       ` İsmail Dönmez
  0 siblings, 0 replies; 5+ messages in thread
From: İsmail Dönmez @ 2008-08-26 15:57 UTC (permalink / raw
  To: Stefan Monnier; +Cc: Andreas Schwab, emacs- devel

Hi,

On Tue, Aug 26, 2008 at 16:49, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> So here I guess multibyte != non-ascii ? The actual problem I am
>> facing is base64-encode-string doesn't support non-ascii characters,
>
> base64 is a way to encode a *byte sequence* in a way that is "email
> safe".  I.e. it does not accept any characters: only bytes.
> If you want to encode a char sequence using base64, you first need to
> convert your char sequence into a byte sequence, using
> encode-coding-string.

Ah that makes sense indeed, thanks for the pointer.

Regards,
ismail

-- 
Programmer Excuse #26: I suspect it's a bus collision.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-08-26 15:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-26 11:17 base64-encode-string confusion İsmail Dönmez
2008-08-26 13:16 ` Andreas Schwab
2008-08-26 13:28   ` İsmail Dönmez
2008-08-26 13:49     ` Stefan Monnier
2008-08-26 15:57       ` İsmail Dönmez

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).