msDecodeHTMLEntities() ** ** Modify the string to replace encoded characters by their true value ** ** The replacements performed are: ** "&" -> '&', """ -> '"', "<" -> '<' and ">" -> '>' **/
| 1222 | ** "&" -> '&', """ -> '"', "<" -> '<' and ">" -> '>' |
| 1223 | **/ |
| 1224 | void msDecodeHTMLEntities(const char *string) |
| 1225 | { |
| 1226 | char *pszAmp=NULL, *pszSemiColon=NULL, *pszReplace=NULL, *pszEnd=NULL; |
| 1227 | char *pszBuffer=NULL; |
| 1228 | size_t bufferSize = 0; |
| 1229 | |
| 1230 | if(string == NULL) |
| 1231 | return; |
| 1232 | else |
| 1233 | pszBuffer = (char*)string; |
| 1234 | |
| 1235 | bufferSize = strlen(pszBuffer); |
| 1236 | pszReplace = (char*) msSmallMalloc(bufferSize); |
| 1237 | pszEnd = (char*) msSmallMalloc(bufferSize); |
| 1238 | |
| 1239 | while((pszAmp = strchr(pszBuffer, '&')) != NULL) |
| 1240 | { |
| 1241 | /* Get the &...; */ |
| 1242 | strlcpy(pszReplace, pszAmp, bufferSize); |
| 1243 | pszSemiColon = strchr(pszReplace, ';'); |
| 1244 | if(pszSemiColon == NULL) |
| 1245 | break; |
| 1246 | else |
| 1247 | pszSemiColon++; |
| 1248 | |
| 1249 | /* Get everything after the &...; */ |
| 1250 | strlcpy(pszEnd, pszSemiColon, bufferSize); |
| 1251 | |
| 1252 | pszReplace[pszSemiColon-pszReplace] = '\0'; |
| 1253 | |
| 1254 | /* Replace the &...; */ |
| 1255 | if(strcasecmp(pszReplace, "&") == 0) |
| 1256 | { |
| 1257 | pszBuffer[pszAmp - pszBuffer] = '&'; |
| 1258 | pszBuffer[pszAmp - pszBuffer + 1] = '\0'; |
| 1259 | strcat(pszBuffer, pszEnd); |
| 1260 | } |
| 1261 | else if(strcasecmp(pszReplace, "<") == 0) |
| 1262 | { |
| 1263 | pszBuffer[pszAmp - pszBuffer] = '<'; |
| 1264 | pszBuffer[pszAmp - pszBuffer + 1] = '\0'; |
| 1265 | strcat(pszBuffer, pszEnd); |
| 1266 | } |
| 1267 | else if(strcasecmp(pszReplace, ">") == 0) |
| 1268 | { |
| 1269 | pszBuffer[pszAmp - pszBuffer] = '>'; |
| 1270 | pszBuffer[pszAmp - pszBuffer + 1] = '\0'; |
| 1271 | strcat(pszBuffer, pszEnd); |
| 1272 | } |
| 1273 | else if(strcasecmp(pszReplace, """) == 0) |
| 1274 | { |
| 1275 | pszBuffer[pszAmp - pszBuffer] = '"'; |
| 1276 | pszBuffer[pszAmp - pszBuffer + 1] = '\0'; |
| 1277 | strcat(pszBuffer, pszEnd); |
| 1278 | } |
| 1279 | else if(strcasecmp(pszReplace, "'") == 0) |
| 1280 | { |
| 1281 | pszBuffer[pszAmp - pszBuffer] = '\''; |
no test coverage detected