Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for libplaton/platon/str/strcgi.c between version 1.1 and 1.2

version 1.1, 2003/04/21 00:48:36 version 1.2, 2003/04/21 23:51:36
Line 1 
Line 1 
 #include <stdio.h>  
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <ctype.h>  #include <ctype.h>
   
 #include <platon/str/strcgi.h>  #include <platon/str/strcgi.h>
   
 static struct iso8859_15 {  
         char code;  
         char *html;  
 } he[] = {  
 #ifdef NBSP  /* define it, if you want " " -> "&nbsp;" */  
         { ' ', "&nbsp;" },  
 #endif  
         { '\xE4', "&auml;" },  
         { '\xC4', "&Auml;" },  
         { '\xF6', "&ouml;" },  
         { '\xD6', "&Ouml;" },  
         { '\xFC', "&uuml;" },  
         { '\xDC', "&Uuml;" },  
         { '\xDF', "&szlig;" },  
         { '\xA4', "&euro;" },  
         { '\x3C', "&lt;" },  
         { '\x3E', "&gt;" },  
         { '\x26', "&amp;" },  
         { '\x22', "&quot;" }  
 };  
   
 static const int NCODES = sizeof(he) / sizeof(struct iso8859_15);  
   
         char *  
 PLATON_FUNC(htmlentities)(str)  
         const char *str;  
 {  
         register int j, len = 1;  
         int tmp_len = 0;  
   
         char *html = malloc(1);  
         if (html == NULL)  
                 return NULL;  
         *html = '\0';  
   
         /* This one needs the struct and NCODES above.  
            NCODES is the number of elements in the struct. */  
         while (*str) {  
                 for (j = 0; j < NCODES; j++) {  
                         if (*str != he[j].code)  
                                 continue;  
   
                         tmp_len = strlen(he[j].html);  
                         len    += tmp_len;  
                         html    = realloc(html, len);  
   
                         if (html == NULL)  
                                 return NULL;  
   
                         strncat(html, he[j].html, tmp_len);  
                         break;  
                 }  
   
                 if (j == NCODES) {  
                         if ((html = realloc(html, len + 1)) == NULL)  
                                 return NULL;  
   
                         html[len - 1] = *str;  
                         html[len]     = '\0';  
                         len++;  
                 }  
                 str++;  
         }  
   
         return html;  
 }  
   
         char *          char *
 PLATON_FUNC(urlencode)(str)  PLATON_FUNC(urlencode)(str)
         const char *str;          const char *str;
Line 231  PLATON_FUNC(stripnslashes)(s, n)
Line 163  PLATON_FUNC(stripnslashes)(s, n)
   
 #include <stdio.h>  #include <stdio.h>
   
 #define TEST_htmlentities       "[<--//-->]"  
 #define TEST_urlencode          "&bar'foo'&baz[ ]"  #define TEST_urlencode          "&bar'foo'&baz[ ]"
 #define TEST_urldecode          (s1)  #define TEST_urldecode          (s1)
 #define TEST_addslashes         "The \"string\" wo/backslash (\\)."  #define TEST_addslashes         "The \"string\" wo/backslash (\\)."
Line 244  main(argc, argv)
Line 175  main(argc, argv)
 {  {
         register char *s1, *s2;          register char *s1, *s2;
   
         s1 = htmlentities(TEST_htmlentities);  
         printf("htmlentities(\"%s\") = \"%s\"\n", TEST_htmlentities, s1);  
         free(s1);  
   
         s1 = urlencode(TEST_urlencode);          s1 = urlencode(TEST_urlencode);
         printf("urlencode(\"%s\") = \"%s\"\n", TEST_urlencode, s1);          printf("urlencode(\"%s\") = \"%s\"\n", TEST_urlencode, s1);
         s2 = urldecode(TEST_urlencode);          s2 = urldecode(TEST_urlencode);

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top