1
// Copyright 2005-6 Ben Hutchings <ben@decadent.org.uk>.
2
// See the file "COPYING" for licence details.
7
#include "xml_utils.hpp"
9
std::string xml_escape(const std::string & str)
12
std::size_t begin = 0;
16
std::size_t end = str.find_first_of("\"&'<>", begin);
17
result.append(str, begin, end - begin);
18
if (end == std::string::npos)
21
const char * entity = NULL;
24
case '"': entity = """; break;
25
case '&': entity = "&"; break;
26
case '\'': entity = "'"; break;
27
case '<': entity = "<"; break;
28
case '>': entity = ">"; break;
31
result.append(entity);