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 |
|
|
| #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 " " -> " " */ |
|
| { ' ', " " }, |
|
| #endif |
|
| { '\xE4', "ä" }, |
|
| { '\xC4', "Ä" }, |
|
| { '\xF6', "ö" }, |
|
| { '\xD6', "Ö" }, |
|
| { '\xFC', "ü" }, |
|
| { '\xDC', "Ü" }, |
|
| { '\xDF', "ß" }, |
|
| { '\xA4', "€" }, |
|
| { '\x3C', "<" }, |
|
| { '\x3E', ">" }, |
|
| { '\x26', "&" }, |
|
| { '\x22', """ } |
|
| }; |
|
| |
|
| 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); |
Platon Group <platon@platon.org> http://platon.org/
|
|