TIPEncoder question

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

TIPEncoder question

Post by serge_girard »

Hello,

I need to retrieve some data from a website with a URL that might contain french accents.

To build my URL I use this:

Code: Select all

cSTR        := 'Brabançonnestraat'
cBHUIS_NR   := '6'
cGEMNM      := 'LEUVEN'

oEncoder := TIPEncoder():New( "url" )
cSTR := oEncoder:Encode( cSTR)
 
url	      := 'http://loc.geopunt.be/geolocation/location?q=' + cSTR + '%20'+ cBHUIS_NR + ',' + ALLTRIM(cGEMNM)

The returned string is:
http://loc.geopunt.be/geolocation/locat ... 206,LEUVEN ==> wrong

instead of:
http://loc.geopunt.be/geolocation/locat ... 206,LEUVEN ==> good

%E7 is Windows-1252 and I need the UTF8 conversion.
How can I force the encoder to convert to UTF8?

See: https://www.w3schools.com/tags/ref_urlencode.asp
Serge
There's nothing you can do that can't be done...
radohabjan
Posts: 99
Joined: Mon Nov 30, 2009 7:17 am
Location: Slovenia
Contact:

Re: TIPEncoder question

Post by radohabjan »

Hello Serge,

I made my own conversion for Slovenian charachters:

Code: Select all

function utf8
* for check use online converter : http://www.cafewebmaster.com/online_tools/utf8_encode
parameters novtekst
novtekst=strtran(novtekst,"Č","ÄŚ")
novtekst=strtran(novtekst,"Ž","Ĺ˝")
novtekst=strtran(novtekst,"Š","Ĺ ")
novtekst=strtran(novtekst,"Ć","Ć")
novtekst=strtran(novtekst,"Đ","Đ")
novtekst=strtran(novtekst,"č","ÄŤ")
novtekst=strtran(novtekst,"ž","Ĺľ")
novtekst=strtran(novtekst,"š","š")
novtekst=strtran(novtekst,"ć","ć")
novtekst=strtran(novtekst,"đ","Ä‘")
novtekst=strtran(novtekst,"°","°")
novtekst=strtran(novtekst,"§","§")
return alltrim(novtekst)
br Rado
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: TIPEncoder question

Post by serge_girard »

Hi Rado,

About the same what I am doing now.

Code: Select all

         cSTR      := STRTRAN(cSTR, 'î' ,'%C3%AE')
         cSTR      := STRTRAN(cSTR, 'ï' ,'%C3%AF')
         cSTR      := STRTRAN(cSTR, 'ð' ,'%C3%B0')
         cSTR      := STRTRAN(cSTR, 'ñ' ,'%C3%B1')
         cSTR      := STRTRAN(cSTR, 'ò' ,'%C3%B2')
         cSTR      := STRTRAN(cSTR, 'ó' ,'%C3%B3')
This works but the TIPEncoder should do it also properly !

In Java it goed like this: request = URLEncoder.encode(uri+ queryParam + "&flags=X" + "&gflags=A", "UTF-8");

Serge
There's nothing you can do that can't be done...
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: TIPEncoder question

Post by edk »

Hi, Serge it's simple.
First you must convert string to UTF8, then encode it.
I prefer to use the tip_URLEncode() and tip_URLDecode() functions directly, rather than the tipEncoder class:

Code: Select all

#include "hmg.ch"


#include "hblang.ch"
REQUEST HB_CODEPAGE_FRWIN

Procedure main()
SET LANGUAGE TO French
set( _SET_CODEPAGE, "FRWIN" )

cSTR        := 'Brabançonnestraat'
cBHUIS_NR   := '6'
cGEMNM      := 'LEUVEN'

//oEncoder := TIPEncoder():New( "url" )
//cSTR := oEncoder:Encode( cSTR)

cUrlEnc := tip_URLEncode( hb_StrToUTF8( cStr ) )
 
url := 'http://loc.geopunt.be/geolocation/location?q=' + cUrlEnc + ' %20' + cBHUIS_NR + ',' + ALLTRIM(cGEMNM)

msgbox(url)

return
Bez tytułu.png
Bez tytułu.png (3.04 KiB) Viewed 3997 times
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: TIPEncoder question

Post by serge_girard »

Of course! Big thank you !

Serge
There's nothing you can do that can't be done...
Post Reply