482 // |
482 // |
483 std::string |
483 std::string |
484 TestRunnerImpl::ReplaceXmlSpecialCharacters (std::string xml) const |
484 TestRunnerImpl::ReplaceXmlSpecialCharacters (std::string xml) const |
485 { |
485 { |
486 NS_LOG_FUNCTION (this << xml); |
486 NS_LOG_FUNCTION (this << xml); |
487 std::string specials = "<>&\"'"; |
487 typedef std::map <char, std::string> specials_map; |
488 std::string replacements[] = {"<", ">", "&", "'", """}; |
488 specials_map specials; |
|
489 specials['<'] = "<"; |
|
490 specials['>'] = ">"; |
|
491 specials['&'] = "&"; |
|
492 specials['"'] = "'"; |
|
493 specials['\''] = """; |
|
494 |
489 std::string result; |
495 std::string result; |
490 std::size_t index, length = xml.length (); |
496 std::size_t length = xml.length (); |
491 |
497 |
492 for (size_t i = 0; i < length; ++i) |
498 for (size_t i = 0; i < length; ++i) |
493 { |
499 { |
494 char character = xml[i]; |
500 char character = xml[i]; |
495 |
501 |
496 if ((index = specials.find (character)) == std::string::npos) |
502 specials_map::const_iterator it = specials.find (character); |
|
503 |
|
504 if (it == specials.end ()) |
497 { |
505 { |
498 result.push_back (character); |
506 result.push_back (character); |
499 } |
507 } |
500 else |
508 else |
501 { |
509 { |
502 result += replacements[index]; |
510 result += it->second; |
503 } |
511 } |
504 } |
512 } |
505 return result; |
513 return result; |
506 } |
514 } |
507 |
515 |