Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Looking for freee and fast URLDecode function
Message
From
22/04/2002 15:46:04
 
 
To
18/04/2002 11:34:14
General information
Forum:
Visual FoxPro
Category:
Internet applications
Miscellaneous
Thread ID:
00646395
Message ID:
00647816
Views:
19
Assuming fewer than 65000 '%'s :
#define STRING_LEN	500	&& * 1024
#define LOOP_COUNT	11

lcURL = ""
for i = 1 to STRING_LEN
	lcURL = lcURL + "%" + right(transform(i % 256, "@0"), 2) + replicate("X", 1022)
endfor

clear

ss1 = seconds()
for i = 1 to LOOP_COUNT
	lcResult1 = URLDecode1(lcURL)
endfor
? seconds() - ss1

ss1 = seconds()
for i = 1 to LOOP_COUNT
	lcResult2 = URLDecode2(lcURL)
endfor
? seconds() - ss1

? lcResult1 == lcResult2
? len(lcResult1), len(lcResult2)

function URLDecode1
	*** URLDecodes a text string:
	* Replaces %hh tokens with ascii characters

	*** Input: tcInput - Text string to decode
	*** Return: Decoded string
	* Author: Nick

	lparameter tcInput

	local lnPcntPos, lcOutput
	lcOutput=""
	tcInput=strtran(tcInput, "+", " ")

	do while !empty(tcInput)
		lnPcntPos=at("%",tcInput)
		if betw( lnPcntPos, 1, len(tcInput)-2 )
			lcOutput= m.lcOutput+ left(tcInput, ;
				lnPcntPos-1)+chr(eval('0x'+substr(tcInput,lnPcntPos+1,2)))
			tcInput=substr(tcInput,lnPcntPos+3)
		else
			lcOutput=m.lcOutput+ m.tcInput
			exit
		endif
	enddo
	return lcOutput

function URLDecode2
	*** URLDecodes a text string:
	* Replaces %hh tokens with ascii characters

	*** Input: tcInput - Text string to decode
	*** Return: Decoded string
	* Author: Albert

	lparameter tcInput

	local lnPcntPos, lcOutput, lnPcntCount, i
	tcInput = strtran(tcInput, "+", " ")

	local array laPercents[1]
	lnPcntCount = alines(laPercents, strtran(tcInput, "%", chr(13)))

	lcOutput = laPercents[1]
	
	for i = 2 to lnPcntCount
		lcOutput = m.lcOutput + chr(evaluate('0x' + left(laPercents[i], 2))) + ;
			substr(laPercents[i], 3)
	endfor
	return lcOutput
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform