LLDB mainline
StreamString.cpp
Go to the documentation of this file.
1//===-- StreamString.cpp --------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11using namespace lldb;
12using namespace lldb_private;
13
14StreamString::StreamString(bool colors) : Stream(0, eByteOrderBig, colors) {}
15
16StreamString::StreamString(uint32_t flags, ByteOrder byte_order)
17 : Stream(flags, byte_order) {}
18
20
22 // Nothing to do when flushing a buffer based stream...
23}
24
25size_t StreamString::WriteImpl(const void *s, size_t length) {
26 m_packet.append(static_cast<const char *>(s), length);
27 return length;
28}
29
31 m_packet.clear();
33}
34
35bool StreamString::Empty() const { return GetSize() == 0; }
36
37size_t StreamString::GetSize() const { return m_packet.size(); }
38
40 const size_t length = m_packet.size();
41 size_t last_line_begin_pos = m_packet.find_last_of("\r\n");
42 if (last_line_begin_pos == std::string::npos) {
43 return length;
44 } else {
45 ++last_line_begin_pos;
46 return length - last_line_begin_pos;
47 }
48}
49
50llvm::StringRef StreamString::GetString() const { return m_packet; }
51
52void StreamString::FillLastLineToColumn(uint32_t column, char fill_char) {
53 const size_t length = m_packet.size();
54 size_t last_line_begin_pos = m_packet.find_last_of("\r\n");
55 if (last_line_begin_pos == std::string::npos) {
56 last_line_begin_pos = 0;
57 } else {
58 ++last_line_begin_pos;
59 }
60
61 const size_t line_columns = length - last_line_begin_pos;
62 if (column > line_columns) {
63 m_packet.append(column - line_columns, fill_char);
64 }
65}
size_t WriteImpl(const void *s, size_t length) override
Output character bytes to the stream.
size_t GetSizeOfLastLine() const
void Flush() override
Flush the stream.
llvm::StringRef GetString() const
void FillLastLineToColumn(uint32_t column, char fill_char)
StreamString(bool colors=false)
std::size_t m_bytes_written
Number of bytes written so far.
Definition Stream.h:412
Stream(uint32_t flags, lldb::ByteOrder byte_order, bool colors=false)
Construct with flags and address size and byte order.
Definition Stream.cpp:27
A class that represents a running process on the host machine.
ByteOrder
Byte ordering definitions.