Solved

Unescape function for C/C++ CGI program.

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

##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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
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…
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…

744 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

18 Experts available now in Live!

Get 1:1 Help Now