Paolo Mantovani wrote:
Hello Stephan,

Alle 09:34, venerdì 22 luglio 2005, Stephan Bergmann ha scritto:
[...]

I  must admit that I don't understand this part of your explanation
I'm sure that I'm missing something, may you detail a bit more this part?

The syntax for vnd.sun.star.expand URLs is

  "vnd.sun.star.expand:" + <escaped macrofied URL>

So if the macrofied URL is

  "$ORIGIN/foo%20bar"

its escaped representation is

  "$ORIGIN/foo%2520bar"

(because "%" is a character that must be escaped as "%25" when inserted
into a URL).  If you do not de-escape this before de-macrofication, the
result will be some URL like

  "file:///the/origin/foo%2520bar"

which would correspond to a filepath

  "/the/origin/foo%20bar"

instead of the intended

  "/the/origin/foo bar"


Thank you very much for the clearful explanation!


IIRC, there currently is no functionality available from OOo Basic to do
the de-escaping.  There is C++ functionality for that in rtl/uri.hxx,
and on CWS sb36 (targeted for OOo 3.0) I just added the UNO
com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand that includes
functionality to do the complete de-escape--and--de-macrofy step.


Speaking of OOBasic, it's true, there is no a direct way to de-escape URLs, but In this specific context (macrofied url's) this workaround seems working quite well:

sEscapedTwiceUrl = "$ORIGIN/foo%2520bar"
sEscapedSimpleUrl = convertFromUrl(sEscapedTwiceUrl)
print sEscapedSimpleUrl

What do you think about?

According to Andreas Bregas, convertFromUrl is intended to convert from (file) URLs to platform-specific filepaths. One step it does is to de-escape the URL, so it might work ok here by chance---but it could also do harm to the URL.

As a further possibility, I'm looking in the sources of cUrl library.
http://curl.haxx.se/

The file lib/escape.c contains two functions that encodes/decodes Url's.
It shouldn't be very complicated to "translate" them in OOBasic, therefore, if the first workaround wouldn't be accettable for any reasons, I could try this second way

I did not look at the cUrl stuff. In theory, what you have to do here is to de-escape sequences of "%xx"-sequences into byte sequences (each "xx" is a hex digit pair that represents a byte), treat those byte sequences as UTF-8 strings, and convert those UTF-8 strings into UTF-16 strings. In practice, the original input (the macrofied URL "$ORIGIN/foo%20bar") should have been a valid macrofied URL, which implies that it should only contain ASCII characters, which in turn implies that the escaped macrofied URL should only contain escape sequences %00--%7F. That simplifies matters: You can individually de-escape such an escape sequence in the range %00--%7F into a single Basic (UTF-16) character by building a Basic integer value from the two hex digits and using $chr (or whatever that function is called in OOo Basic) to turn it into a Basic character value.

-Stephan

ciao
Paolo

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to