Solved

Unescape function for C/C++ CGI program.

Posted on 2001-06-28
3
2,066 Views
Last Modified: 2013-12-25
Does anyone know of a site where I can get the source code to convert the escaped non-alphanumeric characters back to its original form, just like the unescape() function in JavaScript?
0
Comment
Question by:szetoa
3 Comments
 
LVL 8

Expert Comment

by:bebonham
ID: 6236222

##sample script
use URI::Escape;
$string="what's up";
$string=uri_escape($string);
print "$string\n";
print uri_unescape($url_encode_string);
##end
that would be the most comparable...

but you can also use a regexp or pack and unpack to do this the 'long' way.

0
 
LVL 5

Accepted Solution

by:
marecs earned 50 total points
ID: 6237935
This is my own version. It uses the utility function ostrcpy which is like strcpy but is defined for strings with overlapping memory, provided the second string's pointer is > than the first string's pointer. This routine does in place unescaping.

/* Strings with overlapping memory copy */
void ostrcpy (char *str1, char *str2) {
   char *p1, *p2;
   for (p1=str1,p2=str2;;p1++,p2++) {
      *p1=*p2;
      if (*p1 == '\0') break;
   }
}

char * unescape (char *string) {
    char hex[2];
    char *dummy, *p;
   /* Do actual character translation in place */
    for (p=string;*p != '\0';p++)
        if (*p == '%') {
            hex[0] = *(p+1);
            hex[1] = *(p+2);
            *p = (char) strtol(hex, &dummy, 16);
            ostrcpy(p+1,p+3);
         }
    return string;
}


0
 
LVL 1

Author Comment

by:szetoa
ID: 6238450
bebonham

Thanks for your help.  But my CGI is a C/C++ program.  So I was looking for C/C++ approach.

marces

Thank you for your help.  It works.

Thanks again experts.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
help with the script. not working for remote computers 3 63
Ready Made PHP Scripts 5 62
Automating a script for user accounts LINUX 14 65
User profile Size Report 3 63
In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now