1 //===-- StringExtractor.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef utility_StringExtractor_h_
11 #define utility_StringExtractor_h_
18 // Other libraries and framework includes
29 //------------------------------------------------------------------
30 // Constructors and Destructors
31 //------------------------------------------------------------------
33 StringExtractor(const char *packet_cstr);
34 StringExtractor(const StringExtractor& rhs);
35 virtual ~StringExtractor();
37 //------------------------------------------------------------------
39 //------------------------------------------------------------------
40 const StringExtractor&
41 operator=(const StringExtractor& rhs);
43 // Returns true if the file position is still valid for the data
44 // contained in this string extractor object.
48 return m_index != UINT64_MAX;
58 SetFilePos (uint32_t idx)
88 return m_packet.empty();
94 if (m_index < m_packet.size())
95 return m_packet.size() - m_index;
100 GetChar (char fail_value = '\0');
103 PeekChar (char fail_value = '\0')
105 const char *cstr = Peek();
115 GetHexU8 (uint8_t fail_value = 0, bool set_eof_on_fail = true);
118 GetHexU8Ex (uint8_t& ch, bool set_eof_on_fail = true);
121 GetNameColonValue (std::string &name, std::string &value);
124 GetS32 (int32_t fail_value, int base = 0);
127 GetU32 (uint32_t fail_value, int base = 0);
130 GetS64 (int64_t fail_value, int base = 0);
133 GetU64 (uint64_t fail_value, int base = 0);
136 GetHexMaxU32 (bool little_endian, uint32_t fail_value);
139 GetHexMaxU64 (bool little_endian, uint64_t fail_value);
142 GetHexBytes (void *dst, size_t dst_len, uint8_t fail_fill_value);
145 GetHexBytesAvail (void *dst, size_t dst_len);
148 GetHexWithFixedSize (uint32_t byte_size, bool little_endian, uint64_t fail_value);
151 GetHexByteString (std::string &str);
154 GetHexByteStringFixedLength (std::string &str, uint32_t nibble_length);
157 GetHexByteStringTerminatedBy (std::string &str,
163 if (m_index < m_packet.size())
164 return m_packet.c_str() + m_index;
169 //------------------------------------------------------------------
170 // For StringExtractor only
171 //------------------------------------------------------------------
172 std::string m_packet; // The string in which to extract data.
173 uint64_t m_index; // When extracting data from a packet, this index
174 // will march along as things get extracted. If set
175 // to UINT64_MAX the end of the packet data was
176 // reached when decoding information
179 #endif // utility_StringExtractor_h_