MCPcopy Index your code
hub / github.com/MapServer/MapServer / msEncodeHTMLEntities

Function msEncodeHTMLEntities

mapstring.c:1157–1214  ·  view source on GitHub ↗

msEncodeHTMLEntities() ** ** Return a copy of string after replacing some problematic chars with their ** HTML entity equivalents. ** ** The replacements performed are: ** '&' -> "&amp;", '"' -> "&quot;", '<' -> "&lt;" and '>' -> "&gt;" **/

Source from the content-addressed store, hash-verified

1155** '&' -> "&amp;", '"' -> "&quot;", '<' -> "&lt;" and '>' -> "&gt;"
1156**/
1157char *msEncodeHTMLEntities(const char *string)
1158{
1159 int buflen, i;
1160 char *newstring;
1161 const char *c;
1162
1163 if(string == NULL)
1164 return NULL;
1165
1166 /* Start with 100 extra chars for replacements... */
1167 /* should be good enough for most cases */
1168 buflen = strlen(string) + 100;
1169 newstring = (char*)malloc(buflen+1);
1170 MS_CHECK_ALLOC(newstring, buflen+1, NULL);
1171
1172 for(i=0, c=string; *c != '\0'; c++)
1173 {
1174 /* Need to realloc buffer? */
1175 if (i+6 > buflen)
1176 {
1177 /* If we had to realloc then this string must contain several */
1178 /* entities... so let's go with twice the previous buffer size */
1179 buflen *= 2;
1180 newstring = (char*)realloc(newstring, buflen+1);
1181 MS_CHECK_ALLOC(newstring, buflen+1, NULL);
1182 }
1183
1184 switch(*c)
1185 {
1186 case '&':
1187 strcpy(newstring+i, "&amp;");
1188 i += 5;
1189 break;
1190 case '<':
1191 strcpy(newstring+i, "&lt;");
1192 i += 4;
1193 break;
1194 case '>':
1195 strcpy(newstring+i, "&gt;");
1196 i += 4;
1197 break;
1198 case '"':
1199 strcpy(newstring+i, "&quot;");
1200 i += 6;
1201 break;
1202 case '\'':
1203 strcpy(newstring+i, "&#39;"); /* changed from &apos; and i += 6 (bug 1040) */
1204 i += 5;
1205 break;
1206 default:
1207 newstring[i++] = *c;
1208 }
1209 }
1210
1211 newstring[i++] = '\0';
1212
1213 return newstring;
1214}

Callers 15

msSLDGenerateSLDFunction · 0.85
msSLDGenerateSLDLayerFunction · 0.85
msOWSPrintEncodeMetadataFunction · 0.85
msOWSGetEncodeMetadataFunction · 0.85
msOWSPrintGroupMetadataFunction · 0.85
msOWSPrintURLTypeFunction · 0.85
msOWSPrintEncodeParamFunction · 0.85
msOWSPrintBoundingBoxFunction · 0.85
msWCSExceptionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected