blob: 1f813b1070eeb9e2fadc851c6c39680fbb368198 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#pragma once
#include <string>
#include <IO/WriteBufferFromVector.h>
#include <base/StringRef.h>
namespace DB
{
/** Writes the data to a string.
* Note: before using the resulting string, destroy this object.
*/
using WriteBufferFromString = WriteBufferFromVector<std::string>;
namespace detail
{
/// For correct order of initialization.
class StringHolder
{
protected:
std::string value;
};
}
/// Creates the string by itself and allows to get it.
class WriteBufferFromOwnString : public detail::StringHolder, public WriteBufferFromString
{
public:
WriteBufferFromOwnString() : WriteBufferFromString(value) {}
std::string_view stringView() const { return isFinished() ? std::string_view(value) : std::string_view(value.data(), pos - value.data()); }
std::string & str()
{
finalize();
return value;
}
};
}
|