1 | //===-- StdStringExtractor.h ------------------------------------*- C++ -*-===// |
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 | |
9 | #ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_STDSTRINGEXTRACTOR_H |
10 | #define |
11 | |
12 | #include <cstdint> |
13 | #include <string> |
14 | |
15 | |
16 | // Based on StringExtractor, with the added limitation that this file should not |
17 | // take a dependency on LLVM, as it is used from debugserver. |
18 | class { |
19 | public: |
20 | enum { = 0, = 1 }; |
21 | // Constructors and Destructors |
22 | (); |
23 | (const char *packet_cstr); |
24 | virtual (); |
25 | |
26 | // Returns true if the file position is still valid for the data |
27 | // contained in this string extractor object. |
28 | bool () const { return m_index != UINT64_MAX; } |
29 | |
30 | uint64_t () const { return m_index; } |
31 | |
32 | void (uint32_t idx) { m_index = idx; } |
33 | |
34 | void () { |
35 | m_packet.clear(); |
36 | m_index = 0; |
37 | } |
38 | |
39 | void (); |
40 | |
41 | const std::string &() const { return m_packet; } |
42 | |
43 | bool () { return m_packet.empty(); } |
44 | |
45 | size_t () { |
46 | if (m_index < m_packet.size()) |
47 | return m_packet.size() - m_index; |
48 | return 0; |
49 | } |
50 | |
51 | char (char fail_value = '\0'); |
52 | |
53 | char (char fail_value = '\0') { |
54 | const char *cstr = Peek(); |
55 | if (cstr) |
56 | return cstr[0]; |
57 | return fail_value; |
58 | } |
59 | |
60 | int (); |
61 | |
62 | uint8_t (uint8_t fail_value = 0, bool set_eof_on_fail = true); |
63 | |
64 | bool (uint8_t &ch, bool set_eof_on_fail = true); |
65 | |
66 | bool (std::string &name, std::string &value); |
67 | |
68 | int32_t (int32_t fail_value, int base = 0); |
69 | |
70 | uint32_t (uint32_t fail_value, int base = 0); |
71 | |
72 | int64_t (int64_t fail_value, int base = 0); |
73 | |
74 | uint64_t (uint64_t fail_value, int base = 0); |
75 | |
76 | uint32_t (bool little_endian, uint32_t fail_value); |
77 | |
78 | uint64_t (bool little_endian, uint64_t fail_value); |
79 | |
80 | size_t (void *dst, size_t dst_len, uint8_t fail_fill_value); |
81 | |
82 | size_t (void *dst, size_t dst_len); |
83 | |
84 | size_t (std::string &str); |
85 | |
86 | size_t (std::string &str, uint32_t nibble_length); |
87 | |
88 | size_t (std::string &str, char terminator); |
89 | |
90 | const char *() { |
91 | if (m_index < m_packet.size()) |
92 | return m_packet.c_str() + m_index; |
93 | return nullptr; |
94 | } |
95 | |
96 | protected: |
97 | // For StdStringExtractor only |
98 | std::string ; // The string in which to extract data. |
99 | uint64_t ; // When extracting data from a packet, this index |
100 | // will march along as things get extracted. If set |
101 | // to UINT64_MAX the end of the packet data was |
102 | // reached when decoding information |
103 | }; |
104 | |
105 | #endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_STDSTRINGEXTRACTOR_H |
106 | |