Line data Source code
1 : //
2 : // Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
3 : //
4 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 : //
7 : // Official repository: https://github.com/cppalliance/http
8 : //
9 :
10 : #include <boost/http/server/escape_html.hpp>
11 :
12 : namespace boost {
13 : namespace http {
14 :
15 : std::string
16 0 : escape_html( core::string_view s )
17 : {
18 0 : std::string result;
19 0 : result.reserve( s.size() );
20 :
21 0 : for( char c : s )
22 : {
23 0 : switch( c )
24 : {
25 0 : case '&':
26 0 : result.append( "&" );
27 0 : break;
28 0 : case '<':
29 0 : result.append( "<" );
30 0 : break;
31 0 : case '>':
32 0 : result.append( ">" );
33 0 : break;
34 0 : case '"':
35 0 : result.append( """ );
36 0 : break;
37 0 : case '\'':
38 0 : result.append( "'" );
39 0 : break;
40 0 : default:
41 0 : result.push_back( c );
42 0 : break;
43 : }
44 : }
45 :
46 0 : return result;
47 0 : }
48 :
49 : } // http
50 : } // boost
|