build url web for a file name with accented letter

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2220
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

build url web for a file name with accented letter

Post by jmburnod » Sat Jul 04, 2015 8:46 pm

Hi All
I look for build a valid url for a file name with accented letters
On a server there is a file called "boîte.png", I noticed the http name is "bo%C3%AEte.png" and it works with this name

I thought I could use urlencode to get the same but
urlEncode(boîte) = "bo%94te"

How can I translate "boîte.png" to "bo%C3%AEte.png" ?
Thanks again for your lights
Jean-Marc
Last edited by jmburnod on Tue Jul 03, 2018 6:26 pm, edited 3 times in total.

zaxos
Posts: 210
Joined: Thu May 23, 2013 11:15 pm
Location: Greece

Re: how build url web for a file name with accented letter ?

Post by zaxos » Sat Jul 04, 2015 10:54 pm

Replace î with %C3% or the reverse? I`m guessing this char is allways represented like that.

Code: Select all

Put "http:\\blablabla\blabla\boîte.jpg" into tUrl
Replace "î" with "%C3%" in tUrl
Just a thought
Knowledge is meant to be shared.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2220
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: how build url web for a file name with accented letter ?

Post by jmburnod » Sun Jul 05, 2015 11:11 am

Hi Zaxos
Thanks for reply
Replace î with %C3% or the reverse?
Unfortunately not
With your script I get "bo%C3%te.jpg" instead "bo%C3%AEte.jpg"
Best regards
Jean-Marc

SparkOut
Posts: 1763
Joined: Sun Sep 23, 2007 4:58 pm

Re: how build url web for a file name with accented letter ?

Post by SparkOut » Sun Jul 05, 2015 11:19 am

then just
replace "î" with "%C3%AE" in tUrl

but it might be worthwhile trying to find our why the filename has been encoded like that. It looks like a problem interpreting between UTF-8 and ISO-8859-1 or Windows-1252 code sets. If you can find out the encoding used, you might be able to make it match from LiveCode by using the matching code set, rather than hard coding a replacement. But that might get pretty complicated.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4564
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: how build url web for a file name with accented letter ?

Post by jacque » Sun Jul 05, 2015 8:02 pm

If you are using LC 7.x you can use the built-in unicode support to translate:

Code: Select all

get "boîte" -- or any other text
put urlEncode(textEncode(it,"utf8"))
In LC 7, all text exported or imported from/to LiveCode should be textEncoded or textDecoded so it is compatible with external apps and servers that have unicode support. Text encoding will not alter non-unicode characters, so it is safe to use on all text.

If you are using LC 6.x then you'll need to use the more awkward uniEncode/uniDecode functions which are now deprecated.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SparkOut
Posts: 1763
Joined: Sun Sep 23, 2007 4:58 pm

Re: how build url web for a file name with accented letter ?

Post by SparkOut » Sun Jul 05, 2015 8:25 pm

Ah great, now I can test I see that is the unicode representation in UTF-8. I was unsure if the file name had been encoded with a different (eg Windows-1252) encoding. This works nicely though. Here's your solution Jean-Marc.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2220
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: how build url web for a file name with accented letter ?

Post by jmburnod » Sun Jul 05, 2015 10:41 pm

Thanks at all,
It works fine with LC 7.
Jaque said there is a way for LC 6.7 but I'm not yet able to use it
Is there an example of "uniEncode/uniDecode" way for 6.7 ?
Jean-Marc

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2220
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: how build url web for a file name with accented letter ?

Post by jmburnod » Mon Jul 06, 2015 9:07 am

I found a quick but dirty way to translate an accented file name.
We can create a list of translated accented chars in LC 7 using unicode.
This list can be used in LC 6.7 with a search/replace

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4564
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: how build url web for a file name with accented letter ?

Post by jacque » Mon Jul 06, 2015 6:07 pm

You can use the older method this way:

Code: Select all

get "boîte"
  put urlEncode(unidecode(uniencode(it), "UTF8")) into tURL
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2220
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: how build url web for a file name with accented letter ?

Post by jmburnod » Mon Jul 06, 2015 9:42 pm

Thanks a lot Jacque
That is the way for LC 6.7

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2220
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: build url web for a file name with accented letter solved

Post by jmburnod » Tue Jul 03, 2018 6:25 pm

Hi All,
It seems something changed about this.
url file name on server for "zéro_2.png" = "ze%CC%81ro_2.png"

I tried this

Code: Select all

  get "zéro_2.png"
  put urlEncode(unidecode(uniencode(it), "UTF8")) 
return "z%C3%A9ro_2.png" instead "ze%CC%81ro_2.png"
Thanks in advance for your help
Jean-Marc

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4564
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: build url web for a file name with accented letter

Post by jacque » Wed Jul 04, 2018 6:12 pm

Maybe you have to go back to textEncode?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2220
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: build url web for a file name with accented letter

Post by jmburnod » Thu Jul 05, 2018 6:13 pm

Thanks again Jacqueline
We have tested on a ownCloud and it works with this:

Code: Select all

   get "zéro_2.png"
   put textencode(it,"UTF-8") into tTE
   put urlEncode(tTE) into tUrltTE
   replace "+" with "%20" in tUrltTE
No idea why our site does different encoding

P.S: my hight score on Klondike is 840. What is the max score ? 8)

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4564
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: build url web for a file name with accented letter

Post by jacque » Thu Jul 05, 2018 6:25 pm

my hight score on Klondike is 840. What is the max score ?
LOL. I can't remember but I think you're close. :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2669
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: build url web for a file name with accented letter

Post by richmond62 » Thu Jul 05, 2018 8:08 pm

La Boîte Diabolique:

https://youtu.be/mE0takm9TX0

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”