]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/escape.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / escape.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #ifndef CEPH_RGW_ESCAPE_H
16 #define CEPH_RGW_ESCAPE_H
17
18 #include <ostream>
19 #include <boost/utility/string_view.hpp>
20
21 /* Returns the length of a buffer that would be needed to escape 'buf'
22 * as an XML attribute
23 */
24 size_t escape_xml_attr_len(const char *buf);
25
26 /* Escapes 'buf' as an XML attribute. Assumes that 'out' is at least long
27 * enough to fit the output. You can find out the required length by calling
28 * escape_xml_attr_len first.
29 */
30 void escape_xml_attr(const char *buf, char *out);
31
32 /* Returns the length of a buffer that would be needed to escape 'buf'
33 * as an JSON attribute
34 */
35 size_t escape_json_attr_len(const char *buf, size_t src_len);
36
37 /* Escapes 'buf' as an JSON attribute. Assumes that 'out' is at least long
38 * enough to fit the output. You can find out the required length by calling
39 * escape_json_attr_len first.
40 */
41 void escape_json_attr(const char *buf, size_t src_len, char *out);
42
43 /* Note: we escape control characters. Although the XML spec doesn't actually
44 * require this, Amazon does it in their XML responses.
45 */
46
47 // stream output operators that write escaped text without making a copy
48 // usage:
49 // std::string xml_input = ...;
50 // std::cout << xml_stream_escaper(xml_input) << std::endl;
51
52 struct xml_stream_escaper {
53 boost::string_view str;
54 xml_stream_escaper(std::string_view str) : str(str.data(), str.size()) {}
55 };
56 std::ostream& operator<<(std::ostream& out, const xml_stream_escaper& e);
57
58 struct json_stream_escaper {
59 boost::string_view str;
60 json_stream_escaper(std::string_view str) : str(str.data(), str.size()) {}
61 };
62 std::ostream& operator<<(std::ostream& out, const json_stream_escaper& e);
63
64 #endif