Solved

Unescape function for C/C++ CGI program.

Posted on 2001-06-28
3
2,154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

717 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