Get hex or octal value from escaped string

I am working on an application that needs to take posted data from a form and process it. One of the steps in this process is to unescape the data that is included. One of the problems I am facing is that the data I am retrieving from the form is binary in nature, so it includes escape sequences that I need to return to characters. It's pretty trivial with characters like tab and newline, but I can't figure out how to do it with hex and octal values.

Here's an example of some input:

"blahblah\nblahblah\x20blahblah\037blahblah"

      

When published, it will look something like this:

"blahblah%5Cnblahblah%5Cx20blahblah%5C037blahblah"

      

For the most part I am currently just looping through the string and looping through the "%". Then I use sscanf to get the value of the escaped character. Then if it's 92, I look at the next character. If it's something like "n", I just replace the "\ n" characters and continue.

My question is basically how can I scan a string for hex and octal values? In the above example, how can I get% 5C037 and replace that whole sequence with the corresponding character '\ 037'?

As a side note, I have to do all of this because the data received in the form is usually passed between calls to the server and I am trying to put together a test application so that the user can see what is happening with the data.

+2


source to share


2 answers


strtol

should do what you need.



+2


source


Google for decrypting the U code and you will find many answers, one of them is:



http://www.icosaedro.it/apache/urldecode.c

+4


source







All Articles