src/core/model/test.cc
changeset 9876 c84d748a959f
parent 9784 740a983ed25b
child 9877 7511dc1f8ae8
equal deleted inserted replaced
9875:7d31acb96ea3 9876:c84d748a959f
   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[] = {"&lt;", "&gt;", "&amp;", "&#39;", "&quot;"};
   488   specials_map specials;
       
   489   specials['<'] = "&lt;";
       
   490   specials['>'] = "&gt;";
       
   491   specials['&'] = "&amp;";
       
   492   specials['"'] = "&#39;";
       
   493   specials['\''] = "&quot;";
       
   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