summaryrefslogtreecommitdiffstats
path: root/source/Utility/StringExtractor.cpp
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2013-11-06 16:48:53 +0000
committeremaste <emaste@FreeBSD.org>2013-11-06 16:48:53 +0000
commitc727fe695d28799acb499e9961f11ec07d4f9fe2 (patch)
tree56d79f94966870db1cecd65a7264510a25fd1cba /source/Utility/StringExtractor.cpp
parent2e8c9206a971efee1b77ad2ae852265d6f4ecaa0 (diff)
downloadFreeBSD-src-c727fe695d28799acb499e9961f11ec07d4f9fe2.zip
FreeBSD-src-c727fe695d28799acb499e9961f11ec07d4f9fe2.tar.gz
Import lldb as of SVN r194122
Sponsored by: DARPA, AFRL
Diffstat (limited to 'source/Utility/StringExtractor.cpp')
-rw-r--r--source/Utility/StringExtractor.cpp78
1 files changed, 75 insertions, 3 deletions
diff --git a/source/Utility/StringExtractor.cpp b/source/Utility/StringExtractor.cpp
index 2f4bcec..d4ce470 100644
--- a/source/Utility/StringExtractor.cpp
+++ b/source/Utility/StringExtractor.cpp
@@ -168,10 +168,68 @@ StringExtractor::GetU32 (uint32_t fail_value, int base)
{
char *end = NULL;
const char *start = m_packet.c_str();
- const char *uint_cstr = start + m_index;
- uint32_t result = ::strtoul (uint_cstr, &end, base);
+ const char *cstr = start + m_index;
+ uint32_t result = ::strtoul (cstr, &end, base);
- if (end && end != uint_cstr)
+ if (end && end != cstr)
+ {
+ m_index = end - start;
+ return result;
+ }
+ }
+ return fail_value;
+}
+
+int32_t
+StringExtractor::GetS32 (int32_t fail_value, int base)
+{
+ if (m_index < m_packet.size())
+ {
+ char *end = NULL;
+ const char *start = m_packet.c_str();
+ const char *cstr = start + m_index;
+ int32_t result = ::strtol (cstr, &end, base);
+
+ if (end && end != cstr)
+ {
+ m_index = end - start;
+ return result;
+ }
+ }
+ return fail_value;
+}
+
+
+uint64_t
+StringExtractor::GetU64 (uint64_t fail_value, int base)
+{
+ if (m_index < m_packet.size())
+ {
+ char *end = NULL;
+ const char *start = m_packet.c_str();
+ const char *cstr = start + m_index;
+ uint64_t result = ::strtoull (cstr, &end, base);
+
+ if (end && end != cstr)
+ {
+ m_index = end - start;
+ return result;
+ }
+ }
+ return fail_value;
+}
+
+int64_t
+StringExtractor::GetS64 (int64_t fail_value, int base)
+{
+ if (m_index < m_packet.size())
+ {
+ char *end = NULL;
+ const char *start = m_packet.c_str();
+ const char *cstr = start + m_index;
+ int64_t result = ::strtoll (cstr, &end, base);
+
+ if (end && end != cstr)
{
m_index = end - start;
return result;
@@ -371,6 +429,20 @@ StringExtractor::GetHexByteString (std::string &str)
return str.size();
}
+size_t
+StringExtractor::GetHexByteStringTerminatedBy (std::string &str,
+ char terminator)
+{
+ str.clear();
+ char ch;
+ while ((ch = GetHexU8(0,false)) != '\0')
+ str.append(1, ch);
+ if (Peek() && *Peek() == terminator)
+ return str.size();
+ str.clear();
+ return str.size();
+}
+
bool
StringExtractor::GetNameColonValue (std::string &name, std::string &value)
{
OpenPOWER on IntegriCloud