]>
git.proxmox.com Git - ceph.git/blob - 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
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
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.
15 #ifndef CEPH_RGW_ESCAPE_H
16 #define CEPH_RGW_ESCAPE_H
19 #include <string_view>
21 /* Returns the length of a buffer that would be needed to escape 'buf'
24 size_t escape_xml_attr_len(const char *buf
);
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.
30 void escape_xml_attr(const char *buf
, char *out
);
32 /* Returns the length of a buffer that would be needed to escape 'buf'
33 * as an JSON attribute
35 size_t escape_json_attr_len(const char *buf
, size_t src_len
);
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.
41 void escape_json_attr(const char *buf
, size_t src_len
, char *out
);
43 /* Note: we escape control characters. Although the XML spec doesn't actually
44 * require this, Amazon does it in their XML responses.
47 // stream output operators that write escaped text without making a copy
49 // std::string xml_input = ...;
50 // std::cout << xml_stream_escaper(xml_input) << std::endl;
52 struct xml_stream_escaper
{
54 xml_stream_escaper(std::string_view str
) : str(str
.data(), str
.size()) {}
56 std::ostream
& operator<<(std::ostream
& out
, const xml_stream_escaper
& e
);
58 struct json_stream_escaper
{
60 json_stream_escaper(std::string_view str
) : str(str
.data(), str
.size()) {}
62 std::ostream
& operator<<(std::ostream
& out
, const json_stream_escaper
& e
);