1 //===-- StreamString.cpp --------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/StreamString.h"
12 using namespace lldb_private
;
14 StreamString::StreamString(bool colors
) : Stream(0, 4, eByteOrderBig
, colors
) {}
16 StreamString::StreamString(uint32_t flags
, uint32_t addr_size
,
18 : Stream(flags
, addr_size
, byte_order
), m_packet() {}
20 StreamString::~StreamString() = default;
22 void StreamString::Flush() {
23 // Nothing to do when flushing a buffer based stream...
26 size_t StreamString::WriteImpl(const void *s
, size_t length
) {
27 m_packet
.append(static_cast<const char *>(s
), length
);
31 void StreamString::Clear() {
36 bool StreamString::Empty() const { return GetSize() == 0; }
38 size_t StreamString::GetSize() const { return m_packet
.size(); }
40 size_t StreamString::GetSizeOfLastLine() const {
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
) {
46 ++last_line_begin_pos
;
47 return length
- last_line_begin_pos
;
51 llvm::StringRef
StreamString::GetString() const { return m_packet
; }
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;
59 ++last_line_begin_pos
;
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
);