Re: GDBus/GVariant plans for next GLib release



On Mon, 09 Nov 2009 at 08:52:08 -0500, David Zeuthen wrote:
> Yeah, we can choose another encoding that hex. The problem is that D-Bus
> is very strict about what characters it accepts for names - in
> particular, '-' is not accepted. So we'd need some kind of way to escape
> things.

You're very welcome to copy telepathy-glib's tp_escape_as_identifier()
(HTTP-style escaping using _ instead of %, fitting within all the restricted
character sets of D-Bus, and also the character set of C identifiers) to any
project that needs it. I think so far I've implemented it at least three times
in two languages...

It's a reversible encoding in order to guarantee that it preserves uniqueness,
but so far I've never needed to write a function to decode it (we usually use
it to encode account names, etc. into our object paths, either for uniqueness,
ease of debugging or both).

It's pretty good for strings that are "nearly identifiers", and pessimal for
arbitrary natural-language text (every escaped byte produces three bytes of
output, so it'd triple the size of any non-ASCII text).

    Simon


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]