Solved

Unescape function for C/C++ CGI program.

Posted on 2001-06-28
3
2,136 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

738 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