24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
** Make the given string safe for HTML by converting every "<" into "<",
** every ">" into ">" and every "&" into "&". Return a pointer
** to a new string obtained from malloc().
**
** We also encode " as " and ' as ' so they can appear as an argument
** to markup.
*/
char *htmlize(const char *zIn, int n){
int c;
int i = 0;
int count = 0;
char *zOut;
if( n<0 ) n = strlen(zIn);
while( i<n && (c = zIn[i])!=0 ){
switch( c ){
case '<': count += 4; break;
case '>': count += 4; break;
case '&': count += 5; break;
case '"': count += 6; break;
case '\'': count += 5; break;
default: count++; break;
}
i++;
}
i = 0;
zOut = fossil_malloc( count+1 );
while( n-->0 && (c = *zIn)!=0 ){
switch( c ){
case '<':
zOut[i++] = '&';
zOut[i++] = 'l';
zOut[i++] = 't';
zOut[i++] = ';';
break;
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
|
>
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
** Make the given string safe for HTML by converting every "<" into "<",
** every ">" into ">" and every "&" into "&". Return a pointer
** to a new string obtained from malloc().
**
** We also encode " as " and ' as ' so they can appear as an argument
** to markup.
*/
char *htmlize(const char *z, int n){
unsigned char c;
int i = 0;
int count = 0;
unsigned char *zOut;
const unsigned char *zIn = (const unsigned char*)z;
if( n<0 ) n = strlen(z);
while( i<n ){
switch( zIn[i] ){
case '<': count += 3; break;
case '>': count += 3; break;
case '&': count += 4; break;
case '"': count += 5; break;
case '\'': count += 4; break;
case 0: n = i; break;
}
i++;
}
i = 0;
zOut = fossil_malloc( count+n+1 );
if( count==0 ){
memcpy(zOut, zIn, n);
zOut[n] = 0;
return (char*)zOut;
}
while( n-->0 ){
c = *(zIn++);
switch( c ){
case '<':
zOut[i++] = '&';
zOut[i++] = 'l';
zOut[i++] = 't';
zOut[i++] = ';';
break;
|
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
zOut[i++] = '9';
zOut[i++] = ';';
break;
default:
zOut[i++] = c;
break;
}
zIn++;
}
zOut[i] = 0;
return zOut;
}
/*
** Append HTML-escaped text to a Blob.
*/
void htmlize_to_blob(Blob *p, const char *zIn, int n){
int c, i, j;
|
<
|
|
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
zOut[i++] = '9';
zOut[i++] = ';';
break;
default:
zOut[i++] = c;
break;
}
}
zOut[i] = 0;
return (char*)zOut;
}
/*
** Append HTML-escaped text to a Blob.
*/
void htmlize_to_blob(Blob *p, const char *zIn, int n){
int c, i, j;
|