]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/StringPrinter.h
Merge sync of head
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / StringPrinter.h
1 //===-- StringPrinter.h -----------------------------------------*- 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 #ifndef liblldb_StringPrinter_h_
11 #define liblldb_StringPrinter_h_
12
13 #include "lldb/lldb-forward.h"
14
15 #include "lldb/Core/DataExtractor.h"
16
17 namespace lldb_private {
18     namespace formatters
19     {
20         
21         enum class StringElementType {
22             ASCII,
23             UTF8,
24             UTF16,
25             UTF32
26         };
27         
28         class ReadStringAndDumpToStreamOptions
29         {
30         public:
31             
32             ReadStringAndDumpToStreamOptions () :
33             m_location(0),
34             m_process_sp(),
35             m_stream(NULL),
36             m_prefix_token(0),
37             m_quote('"'),
38             m_source_size(0),
39             m_needs_zero_termination(true),
40             m_escape_non_printables(true),
41             m_ignore_max_length(false)
42             {
43             }
44             
45             ReadStringAndDumpToStreamOptions (ValueObject& valobj);
46             
47             ReadStringAndDumpToStreamOptions&
48             SetLocation (uint64_t l)
49             {
50                 m_location = l;
51                 return *this;
52             }
53             
54             uint64_t
55             GetLocation () const
56             {
57                 return m_location;
58             }
59             
60             ReadStringAndDumpToStreamOptions&
61             SetProcessSP (lldb::ProcessSP p)
62             {
63                 m_process_sp = p;
64                 return *this;
65             }
66             
67             lldb::ProcessSP
68             GetProcessSP () const
69             {
70                 return m_process_sp;
71             }
72             
73             ReadStringAndDumpToStreamOptions&
74             SetStream (Stream* s)
75             {
76                 m_stream = s;
77                 return *this;
78             }
79             
80             Stream*
81             GetStream () const
82             {
83                 return m_stream;
84             }
85             
86             ReadStringAndDumpToStreamOptions&
87             SetPrefixToken (char p)
88             {
89                 m_prefix_token = p;
90                 return *this;
91             }
92             
93             char
94             GetPrefixToken () const
95             {
96                 return m_prefix_token;
97             }
98             
99             ReadStringAndDumpToStreamOptions&
100             SetQuote (char q)
101             {
102                 m_quote = q;
103                 return *this;
104             }
105             
106             char
107             GetQuote () const
108             {
109                 return m_quote;
110             }
111             
112             ReadStringAndDumpToStreamOptions&
113             SetSourceSize (uint32_t s)
114             {
115                 m_source_size = s;
116                 return *this;
117             }
118             
119             uint32_t
120             GetSourceSize () const
121             {
122                 return m_source_size;
123             }
124             
125             ReadStringAndDumpToStreamOptions&
126             SetNeedsZeroTermination (bool z)
127             {
128                 m_needs_zero_termination = z;
129                 return *this;
130             }
131             
132             bool
133             GetNeedsZeroTermination () const
134             {
135                 return m_needs_zero_termination;
136             }
137             
138             ReadStringAndDumpToStreamOptions&
139             SetEscapeNonPrintables (bool e)
140             {
141                 m_escape_non_printables = e;
142                 return *this;
143             }
144             
145             bool
146             GetEscapeNonPrintables () const
147             {
148                 return m_escape_non_printables;
149             }
150             
151             ReadStringAndDumpToStreamOptions&
152             SetIgnoreMaxLength (bool e)
153             {
154                 m_ignore_max_length = e;
155                 return *this;
156             }
157             
158             bool
159             GetIgnoreMaxLength () const
160             {
161                 return m_ignore_max_length;
162             }
163             
164         private:
165             uint64_t m_location;
166             lldb::ProcessSP m_process_sp;
167             Stream* m_stream;
168             char m_prefix_token;
169             char m_quote;
170             uint32_t m_source_size;
171             bool m_needs_zero_termination;
172             bool m_escape_non_printables;
173             bool m_ignore_max_length;
174         };
175         
176         class ReadBufferAndDumpToStreamOptions
177         {
178         public:
179             
180             ReadBufferAndDumpToStreamOptions () :
181             m_data(),
182             m_stream(NULL),
183             m_prefix_token(0),
184             m_quote('"'),
185             m_source_size(0),
186             m_escape_non_printables(true)
187             {
188             }
189             
190             ReadBufferAndDumpToStreamOptions (ValueObject& valobj);
191             
192             ReadBufferAndDumpToStreamOptions&
193             SetData (DataExtractor d)
194             {
195                 m_data = d;
196                 return *this;
197             }
198             
199             lldb_private::DataExtractor
200             GetData () const
201             {
202                 return m_data;
203             }
204             
205             ReadBufferAndDumpToStreamOptions&
206             SetStream (Stream* s)
207             {
208                 m_stream = s;
209                 return *this;
210             }
211             
212             Stream*
213             GetStream () const
214             {
215                 return m_stream;
216             }
217             
218             ReadBufferAndDumpToStreamOptions&
219             SetPrefixToken (char p)
220             {
221                 m_prefix_token = p;
222                 return *this;
223             }
224             
225             char
226             GetPrefixToken () const
227             {
228                 return m_prefix_token;
229             }
230             
231             ReadBufferAndDumpToStreamOptions&
232             SetQuote (char q)
233             {
234                 m_quote = q;
235                 return *this;
236             }
237             
238             char
239             GetQuote () const
240             {
241                 return m_quote;
242             }
243             
244             ReadBufferAndDumpToStreamOptions&
245             SetSourceSize (uint32_t s)
246             {
247                 m_source_size = s;
248                 return *this;
249             }
250             
251             uint32_t
252             GetSourceSize () const
253             {
254                 return m_source_size;
255             }
256             
257             ReadBufferAndDumpToStreamOptions&
258             SetEscapeNonPrintables (bool e)
259             {
260                 m_escape_non_printables = e;
261                 return *this;
262             }
263             
264             bool
265             GetEscapeNonPrintables () const
266             {
267                 return m_escape_non_printables;
268             }
269             
270         private:
271             DataExtractor m_data;
272             Stream* m_stream;
273             char m_prefix_token;
274             char m_quote;
275             uint32_t m_source_size;
276             bool m_escape_non_printables;
277         };
278         
279         template <StringElementType element_type>
280         bool
281         ReadStringAndDumpToStream (ReadStringAndDumpToStreamOptions options);
282         
283         template <StringElementType element_type>
284         bool
285         ReadBufferAndDumpToStream (ReadBufferAndDumpToStreamOptions options);
286         
287     } // namespace formatters
288 } // namespace lldb_private
289
290 #endif // liblldb_StringPrinter_h_