1 //===-- StringConvert.cpp ---------------------------------------*- 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 //===----------------------------------------------------------------------===//
14 // Other libraries and framework includes
16 #include "lldb/Host/StringConvert.h"
18 namespace lldb_private
20 namespace StringConvert
24 ToSInt32 (const char *s, int32_t fail_value, int base, bool *success_ptr)
29 const long sval = ::strtol (s, &end, base);
33 *success_ptr = ((sval <= INT32_MAX) && (sval >= INT32_MIN));
34 return (int32_t)sval; // All characters were used, return the result
43 ToUInt32 (const char *s, uint32_t fail_value, int base, bool *success_ptr)
48 const unsigned long uval = ::strtoul (s, &end, base);
52 *success_ptr = (uval <= UINT32_MAX);
53 return (uint32_t)uval; // All characters were used, return the result
62 ToSInt64 (const char *s, int64_t fail_value, int base, bool *success_ptr)
67 int64_t uval = ::strtoll (s, &end, base);
72 return uval; // All characters were used, return the result
81 ToUInt64 (const char *s, uint64_t fail_value, int base, bool *success_ptr)
86 uint64_t uval = ::strtoull (s, &end, base);
91 return uval; // All characters were used, return the result
94 if (success_ptr) *success_ptr = false;
99 ToDouble (const char *s, double fail_value, bool *success_ptr)
104 double val = strtod (s, &end);
109 return val; // All characters were used, return the result
113 *success_ptr = false;