• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- StreamString.cpp ----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Core/StreamString.h"
11 #include <stdio.h>
12 
13 using namespace lldb;
14 using namespace lldb_private;
15 
StreamString()16 StreamString::StreamString () :
17     Stream (0, 4, eByteOrderBig)
18 {
19 }
20 
StreamString(uint32_t flags,uint32_t addr_size,ByteOrder byte_order)21 StreamString::StreamString(uint32_t flags, uint32_t addr_size, ByteOrder byte_order) :
22     Stream (flags, addr_size, byte_order),
23     m_packet ()
24 {
25 }
26 
~StreamString()27 StreamString::~StreamString()
28 {
29 }
30 
31 void
Flush()32 StreamString::Flush ()
33 {
34     // Nothing to do when flushing a buffer based stream...
35 }
36 
37 size_t
Write(const void * s,size_t length)38 StreamString::Write (const void *s, size_t length)
39 {
40     m_packet.append ((char *)s, length);
41     return length;
42 }
43 
44 void
Clear()45 StreamString::Clear()
46 {
47     m_packet.clear();
48 }
49 
50 bool
Empty() const51 StreamString::Empty() const
52 {
53     return GetSize() == 0;
54 }
55 
56 const char *
GetData() const57 StreamString::GetData () const
58 {
59     return m_packet.c_str();
60 }
61 
62 size_t
GetSize() const63 StreamString::GetSize () const
64 {
65     return m_packet.size();
66 }
67 
68 std::string &
GetString()69 StreamString::GetString()
70 {
71     return m_packet;
72 }
73 
74 const std::string &
GetString() const75 StreamString::GetString() const
76 {
77     return m_packet;
78 }
79 
80 void
FillLastLineToColumn(uint32_t column,char fill_char)81 StreamString::FillLastLineToColumn (uint32_t column, char fill_char)
82 {
83     const size_t length = m_packet.size();
84     size_t last_line_begin_pos = m_packet.find_last_of("\r\n");
85     if (last_line_begin_pos == std::string::npos)
86     {
87         last_line_begin_pos = 0;
88     }
89     else
90     {
91         ++last_line_begin_pos;
92     }
93 
94     const size_t line_columns = length - last_line_begin_pos;
95     if (column > line_columns)
96     {
97         m_packet.append(column - line_columns, fill_char);
98     }
99 }
100 
101