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 
11 using namespace lldb;
12 using namespace lldb_private;
13 
14 StreamString::StreamString() : Stream(0, 4, eByteOrderBig) {}
15 
17  ByteOrder byte_order)
18  : Stream(flags, addr_size, byte_order), m_packet() {}
19 
20 StreamString::~StreamString() = default;
21 
23  // Nothing to do when flushing a buffer based stream...
24 }
25 
26 size_t StreamString::WriteImpl(const void *s, size_t length) {
27  m_packet.append(static_cast<const char *>(s), length);
28  return length;
29 }
30 
32  m_packet.clear();
33  m_bytes_written = 0;
34 }
35 
36 bool StreamString::Empty() const { return GetSize() == 0; }
37 
38 size_t StreamString::GetSize() const { return m_packet.size(); }
39 
41  const size_t length = m_packet.size();
42  size_t last_line_begin_pos = m_packet.find_last_of("\r\n");
43  if (last_line_begin_pos == std::string::npos) {
44  return length;
45  } else {
46  ++last_line_begin_pos;
47  return length - last_line_begin_pos;
48  }
49 }
50 
51 llvm::StringRef StreamString::GetString() const { return m_packet; }
52 
53 void StreamString::FillLastLineToColumn(uint32_t column, char fill_char) {
54  const size_t length = m_packet.size();
55  size_t last_line_begin_pos = m_packet.find_last_of("\r\n");
56  if (last_line_begin_pos == std::string::npos) {
57  last_line_begin_pos = 0;
58  } else {
59  ++last_line_begin_pos;
60  }
61 
62  const size_t line_columns = length - last_line_begin_pos;
63  if (column > line_columns) {
64  m_packet.append(column - line_columns, fill_char);
65  }
66 }
lldb_private::StreamString::FillLastLineToColumn
void FillLastLineToColumn(uint32_t column, char fill_char)
Definition: StreamString.cpp:53
lldb_private::Stream
Definition: Stream.h:28
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
lldb_private::Stream::m_bytes_written
std::size_t m_bytes_written
Number of bytes written so far.
Definition: Stream.h:368
lldb_private::StreamString::GetSize
size_t GetSize() const
Definition: StreamString.cpp:38
lldb_private::StreamString::StreamString
StreamString()
Definition: StreamString.cpp:14
lldb_private::StreamString::Clear
void Clear()
Definition: StreamString.cpp:31
StreamString.h
lldb_private::StreamString::Empty
bool Empty() const
Definition: StreamString.cpp:36
lldb_private::StreamString::WriteImpl
size_t WriteImpl(const void *s, size_t length) override
Output character bytes to the stream.
Definition: StreamString.cpp:26
uint32_t
lldb_private::StreamString::m_packet
std::string m_packet
Definition: StreamString.h:48
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::eByteOrderBig
@ eByteOrderBig
Definition: lldb-enumerations.h:140
lldb_private::StreamString::Flush
void Flush() override
Flush the stream.
Definition: StreamString.cpp:22
lldb_private::StreamString::~StreamString
~StreamString() override
lldb_private::StreamString::GetSizeOfLastLine
size_t GetSizeOfLastLine() const
Definition: StreamString.cpp:40
lldb
Definition: SBAddress.h:15
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138