473,721 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URL decoding function in C++/C?

Hi,

Can you please tell me if there is a library function in C++/C to do
URL decoding?
i.e. change from:
http%3A%2F%2F
to:
http://

Thank you.

Jun 10 '07 #1
8 6857
what is C++ language are you using. because standard C++ does not
define this URL Decode function.

I suggest you that look into the java source and build the class for
URL Decoding yourself.

the Visual C++ has provide A function to decoding URL, please
reference here: http://www.codeproject.com/internet/CppHttpWebForm.asp

Jun 10 '07 #2
On 2007-06-10 16:50, He************@ gmail.com wrote:
Hi,

Can you please tell me if there is a library function in C++/C to do
URL decoding?
i.e. change from:
http%3A%2F%2F
to:
http://
There's non in standard C++, if you are using some framework/library
there might be one in that. Else I think you can do something similar
yourself quite easy (this is based on my limited understanding of how
this URL encoding works).

All you have to do is copy the URL until you encounter '%', then you
read in the next two characters, convert them to an int, create a char
variable, assign the number to it, add the char to the copy. Then
proceed like this until you reach the end of the URL.

This however requires that your platform uses ASCII as native chars (or
whatever it is called).

--
Erik Wikström
Jun 10 '07 #3
He************@ gmail.com wrote:
Hi,

Can you please tell me if there is a library function in C++/C to do
URL decoding?
i.e. change from:
http%3A%2F%2F
to:
http://
Nothing standard. Google around, there are tons of snippets for that
sort of thing.

Brian
Jun 10 '07 #4

<He************ @gmail.comwrote in message...
Hi,
Can you please tell me if there is a library function in C++/C to do
URL decoding?
i.e. change from:
http%3A%2F%2F
to:
http://

Thank you.
Not hard to write your own.

{
std::cout<<"-------"<<std::end l;
std::string Test( "http%3A%2F %2F" );
std::cout<<Test <<std::endl;
std::string Find1( "%3A" );
std::string Rep1( ":" );
std::string Find2( "%2F" );
std::string Rep2( "/" );
Test.replace( Test.find( Find1 ), Find1.size(), Rep1);
std::size_t Pos;
while( ( Pos = Test.find( Find2 ) ) != Test.npos ){
Test.replace( Pos, Find2.size(), Rep2 );
}
std::cout<<Test <<std::endl;
std::cout<<"-------"<<std::end l;
}
Maybe put the from/to pairs in a std::map, and use that in a loop.

--
Bob R
POVrookie
Jun 10 '07 #5
BobR wrote:
>
<He************ @gmail.comwrote in message...
Hi,
Can you please tell me if there is a library function in C++/C to do
URL decoding?
i.e. change from:
http%3A%2F%2F
to:
http://

Thank you.

Not hard to write your own.

{
std::cout<<"-------"<<std::end l;
std::string Test( "http%3A%2F %2F" );
std::cout<<Test <<std::endl;
std::string Find1( "%3A" );
std::string Rep1( ":" );
std::string Find2( "%2F" );
std::string Rep2( "/" );
Yeah, but there are lot of characters to decode. You're better off not
reinventing the wheel unless there's a particular reason to do so, like
it's a instructional program.

Many decode programs are out there, in most any language you like.


Brian
Jun 10 '07 #6
He************@ gmail.com wrote:
Hi,

Can you please tell me if there is a library function in C++/C to do
URL decoding?
i.e. change from:
http%3A%2F%2F
to:
http://
Nothing standard comes to mind. There is a url parser in austria c++ -
it contains a decoder as well.

http://austria.sourceforge.net/dox/h...8h-source.html
Jun 11 '07 #7

Herman Schultz wrote:
Hi,
Hello!
Can you please tell me if there is a library function
in C++/C to do URL decoding?
i.e. change from:
http%3A%2F%2F
to:
http://
There is no *standard* library facility to do that.

There's almost certainly libraries out there that have
that facility, though. Google for "C++ URL library" or
similar searches.

However, it may be simpler to just to write your own.

Here's a big hint: Unix file names may only contain certain
characters, not others; so Unix tends to turn unacceptable
characters into 3-character triglyphs consisting of "%"
followed by the two-digit ASCII value of the character,
in hexidecimal. (Or, if the numbers are greater than %7E,
they're probably ISO-8859-1 instead of ASCII.)

Examples:

* = %2A (as in "grep 'dog' *") // ASCII
/ = %2F (as in "user/bin") // ASCII
§ = %A7 (as in "see §38.7.13") // assuming ISO-8859-1
ñ = %F1 (as in "España") // assuming ISO-8859-1

(Google "ASCII" and "ISO-8859-1" for more on these encodings.)

So just replace each %HH with the character who's encoding
is "HH". Eg: "%64%6F%67" becomes "dog".

Grab each "%XY" using std::string.fin d() and std::string.sub str().
Feed each "%XY" substring into a function that returns the
character with that encoding. Then replace the "%XY" in the string
with the character Z which you just generated, by using
std::string.rep lace().

Here's a program I just wrote, for the fun of it, which solves
your problem (tested, working code). (CAVEAT: This assumes that
any '%' character will be followed by a valid two-digit hexidecimal
number. If not, it will blow up. You'll have to add your own
error-checking.)

// dehex.cpp

#include <iostream>
#include <string>
#include <sstream>

char CharFromHex (std::string a)
{
std::istringstr eam Blat (a);
int Z;
Blat >std::hex >Z;

/*
int X = int (a[1]); // 16^1 place value
if (X >= 97) {X -= 97;} // capital letter?
else if (X >= 65) {X -= 65;} // small letter?
else {X -= 48;} // numeral?
int Y = int (a[2]); // 16^0 place value
if (Y >= 97) {Y -= 97;} // capital letter?
else if (Y >= 65) {Y -= 65;} // small letter?
else {Y -= 48;} // numeral?
int Z = 16 * X + Y; // generate numerical value of character
*/

return char (Z); // cast to char and return
}

int main (int Beren, char * Luthien[])
{
std::string Text (Luthien[1]);
std::string::si ze_type Pos;
std::string Hex;
while (std::string::n pos != (Pos = Text.find('%')) )
{
Hex = Text.substr(Pos + 1, 2);
Text.replace(Po s, 3, 1, CharFromHex(Hex ));
}
std::cout << Text << std::endl;
return 0;
}
Thank you.
You're welcome.

--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
triple-dubya dott tustinfreezone dott org
Jun 11 '07 #8
On Jun 11, 8:21 am, "Robbie Hatley" <bogus.addr...@ no.spamwrote:
Herman Schultz wrote:
Can you please tell me if there is a library function
in C++/C to do URL decoding?
i.e. change from:
http%3A%2F%2F
to:
http://
There is no *standard* library facility to do that.
There's almost certainly libraries out there that have
that facility, though. Google for "C++ URL library" or
similar searches.
However, it may be simpler to just to write your own.
You're kidding, of course.
Here's a big hint: Unix file names may only contain certain
characters, not others;
It has nothing to do with Unix; the only characters which cannot
occur in a Unix filename are '/' and '\0'.

[...]
Grab each "%XY" using std::string.fin d() and std::string.sub str().
Feed each "%XY" substring into a function that returns the
character with that encoding. Then replace the "%XY" in the string
with the character Z which you just generated, by using
std::string.rep lace().
And this is simpler than just calling a single function in a
third party library.
Here's a program I just wrote, for the fun of it, which solves
your problem (tested, working code). (CAVEAT: This assumes that
any '%' character will be followed by a valid two-digit hexidecimal
number. If not, it will blow up. You'll have to add your own
error-checking.)
Which will likely increase the size of the code by two or three.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 11 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3970
by: steve | last post by:
Hi, I am opening a stream that is UTF encoded. I use fgetc to read the stream- which is binary safe. I add every character read to a string. But when I look at the stream, I see some characters with a bunch of "?" question markets, and then utf8_decode has no effect on it either. How do you go about decoding utf. Does adding the characters to the
1
8335
by: Anuj | last post by:
How can I decode HTML entities? I have an HTML tag as below? <p> Will you help me ? </p> I need to pick this tag in a variable in ASP, and decode the ? into it actual value. There can be a lot of codes like this, so I need a decoding function.
11
2711
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
0
2762
by: Johann Blake | last post by:
In my need to decode a JPEG 2000 file, I discovered like many that there was no functionality for this in the .NET Framework. Instead of forking out a pile of cash to do this, I came up with the idea that costs nothing and it is inheritently built into the Framework. So here is the solution... When you use the WebRequest and WebResponse classes to obtain graphics from a web site, these classes have built-in decoding for JPEG 2000 files....
0
1600
by: Thomas Podlesak | last post by:
Does anybody know any "standard" class?
10
6197
by: mistral | last post by:
I need help implement based64 decoding in javascript: a function to return a script that has been base64 encoded into a string (decoding in client side). For encode, online base64 encoder tool was used. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>JavaScript Base64 Decoder</title> <script type="text/javascript">
25
3407
by: marcin.rzeznicki | last post by:
Hello everyone I've got a little problem with choosing the best decoding strategy for some nasty problem. I have to deal with very large files wich contain text encoded with various encodings. Their length makes loading contents of file into memory in single run inappropriate. I solved this problem by implementing memory mapping using P/Invoke and I load contents of file in chunks. Since files' contents are in different encodings what I...
2
7932
by: pmz | last post by:
Dear Group, I've got a problem with decoding e-mail message subject, which has been read within usage of Pear_Mail_Mime library. There are some elements unwelcome in my subject string, such as: =?ISO-8859-2?Q?My subject. Especially when subject contains polish characters, i.e.:
42
8953
by: Santander | last post by:
how to decode HTML pages encoded like this: http://www.long2consulting.com/seeinaction2008/Simplicity_Beach_table/index.htm Is there script that will do this automatically and generate normal fully readable HTML? Santander
0
8834
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8727
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9212
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9127
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8002
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5973
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4483
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4748
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3186
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.