url encoder/decoder

url encoder/decoder

Postby MarcoBoschi » Thu Mar 03, 2016 9:50 am

Dear friends,

I need a function to encode decode url

http%3A%2F%2F127.0.0.1 <<<< >>>>> http://127.0.0.1

Where Can I find it?

Many thanks
Marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: url encoder/decoder

Postby Carlos Mora » Thu Mar 03, 2016 10:30 am

In our best friend Harbour!

HB_URLENCODE()
HB_URLDECODE()

It happen that I am using a _very_ old version of Harbour in a legacy project, so I had to write my own funcs:

Code: Select all  Expand view

#define URL_CODE { '%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D' }
#define URL_CHAR { '!'  , '*'  , "'"  , "("  , ")"  , ";"  , ":"  , "@"  , "&"  , "="  , "+"  , "$"  , ","  , "/"  , "?"  , "%"  , "#"  , "["  , "]"   }

FUNCTION urlencode( cString )
   LOCAL cResult, i, nAt, Ch

   cResult:= ''

   FOR i:= 1 To LEN( cString )
      IF ( nAT := aScan( URL_CHAR, Ch:= SubStr( cString, i, 1 ) ) ) > 0
         cResult+= URL_CODE[ nAt ]
      ELSE
         cResult+= Ch
      ENDIF
   NEXT

RETURN cResult

FUNCTION urldecode( cString )
   LOCAL cResult, i, nAt, cH

   cResult:= ''

   FOR i:= 1 To LEN( cString )
      IF ( nAT := aScan( URL_CODE, Ch:= SubStr( cString, i, 3 ) ) ) > 0
         cResult+= URL_CHAR[ nAt ]
         i+= 2
      ELSE
         cResult+= Left( Ch, 1 )
      ENDIF
   NEXT

RETURN cResult

 

Best regards
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 989
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

Re: url encoder/decoder

Postby MarcoBoschi » Thu Mar 03, 2016 11:04 am

Many Thanks
:D
Marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: url encoder/decoder (Still Up to date ?)

Postby Marc Venken » Sat Apr 15, 2017 9:40 am

Hello,

It seems that there are encode functions like :

HB_URLENCODE()
HB_URLDECODE()

I the older post above they say that Harbour is older (to old??) and there is a alternatif function written.

I need to use these functions, but anno 04/2017 : witch one do you prefer ?

Marc
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: url encoder/decoder

Postby Carlos Mora » Sat Apr 15, 2017 7:02 pm

Hi Marc,

the native Harbour ones, without any doubt! The are updated with the rtl, written in C so the are _faster_. I posted the old ones just in case, for really old projects it may be useful.

Best regards
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 989
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

Re: url encoder/decoder

Postby Horizon » Mon Sep 30, 2024 2:56 pm

Carlos Mora wrote:Hi Marc,

the native Harbour ones, without any doubt! The are updated with the rtl, written in C so the are _faster_. I posted the old ones just in case, for really old projects it may be useful.

Best regards


Hi,

Is there any library to add my mak file.
It says,
Code: Select all  Expand view
Portal_UYAP.obj : error LNK2001: unresolved external symbol _HB_FUN_HB_URLENCODE

Thanks.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: url encoder/decoder

Postby karinha » Mon Sep 30, 2024 3:02 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: nageswaragunupudi and 83 guests